22
33namespace MongoDB ;
44
5+ use MongoDB \Driver \Manager ;
6+ use MongoDB \Driver \ReadPreference ;
57use MongoDB \Driver \Server ;
8+ use MongoDB \Driver \WriteConcern ;
69use MongoDB \Exception \InvalidArgumentTypeException ;
10+ use ReflectionClass ;
711
812/**
913 * Return whether the first key in the document starts with a "$" character.
@@ -30,6 +34,69 @@ function is_first_key_operator($document)
3034 return (isset ($ firstKey [0 ]) && $ firstKey [0 ] == '$ ' );
3135}
3236
37+ /**
38+ * Returns a ReadPreference corresponding to the Manager's read preference.
39+ *
40+ * @internal
41+ * @todo this function can be removed once PHPC-417 is implemented
42+ * @param Manager $manager
43+ * @return ReadPreference
44+ */
45+ function get_manager_read_preference (Manager $ manager )
46+ {
47+ $ rp = $ manager ->getReadPreference ();
48+
49+ if ($ rp instanceof ReadPreference) {
50+ return $ rp ;
51+ }
52+
53+ $ args = array (
54+ $ rp ['mode ' ],
55+ );
56+
57+ if (isset ($ rp ['tags ' ])) {
58+ $ args [] = $ rp ['tags ' ];
59+ }
60+
61+ $ rc = new ReflectionClass ('MongoDB\Driver\ReadPreference ' );
62+
63+ return $ rc ->newInstanceArgs ($ args );
64+ }
65+
66+ /**
67+ * Returns a WriteConcern corresponding to the Manager's write concern.
68+ *
69+ * @internal
70+ * @todo this function can be removed once PHPC-417 is implemented
71+ * @param Manager $manager
72+ * @return WriteConcern
73+ */
74+ function get_manager_write_concern (Manager $ manager )
75+ {
76+ $ wc = $ manager ->getWriteConcern ();
77+
78+ if ($ wc instanceof WriteConcern) {
79+ return $ wc ;
80+ }
81+
82+ $ args = array (
83+ isset ($ wc ['w ' ]) ? $ wc ['w ' ] : -2 ,
84+ $ wc ['wtimeout ' ],
85+ );
86+
87+ if (isset ($ wc ['journal ' ])) {
88+ $ args [] = $ wc ['journal ' ];
89+
90+ if (isset ($ wc ['fsync ' ])) {
91+ $ args [] = $ wc ['fsync ' ];
92+ }
93+ }
94+
95+ $ rc = new ReflectionClass ('MongoDB\Driver\WriteConcern ' );
96+
97+ return $ rc ->newInstanceArgs ($ args );
98+ }
99+
33100/**
34101 * Generate an index name from a key specification.
35102 *
0 commit comments