1 | <?php |
||
21 | trait WriteConcern |
||
22 | { |
||
23 | /** |
||
24 | * @var \MongoDB\Driver\WriteConcern |
||
25 | */ |
||
26 | protected $writeConcern; |
||
27 | |||
28 | /** |
||
29 | * @param $wstring |
||
30 | * @param int $wtimeout |
||
31 | * @return bool |
||
32 | */ |
||
33 | abstract public function setWriteConcern($wstring, $wtimeout = 0); |
||
34 | |||
35 | /** |
||
36 | * @return array |
||
37 | */ |
||
38 | 112 | public function getWriteConcern() |
|
50 | |||
51 | /** |
||
52 | * @param string|int $wstring |
||
53 | * @param int $wtimeout |
||
54 | * @return \MongoDB\Driver\WriteConcern |
||
55 | */ |
||
56 | 112 | protected function createWriteConcernFromParameters($wstring, $wtimeout) |
|
57 | { |
||
58 | 112 | if (! is_string($wstring) && ! is_int($wstring)) { |
|
59 | trigger_error("w for WriteConcern must be a string or integer", E_WARNING); |
||
60 | return false; |
||
61 | } |
||
62 | |||
63 | // Ensure wtimeout is not < 0 |
||
64 | 112 | return new \MongoDB\Driver\WriteConcern($wstring, max($wtimeout, 0)); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param string|int $wstring |
||
69 | * @param int $wtimeout |
||
70 | * @return bool |
||
71 | */ |
||
72 | 112 | protected function setWriteConcernFromParameters($wstring, $wtimeout = 0) |
|
73 | { |
||
74 | 112 | $this->writeConcern = $this->createWriteConcernFromParameters($wstring, $wtimeout); |
|
75 | |||
76 | 112 | return true; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param array $writeConcernArray |
||
81 | * @return bool |
||
82 | */ |
||
83 | 111 | protected function setWriteConcernFromArray($writeConcernArray) |
|
90 | } |
||
91 |