|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\Utility; |
|
21
|
|
|
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Utility class used to unify checks on how collection strategies should behave. |
|
25
|
|
|
* |
|
26
|
|
|
* @since 1.0 |
|
27
|
|
|
* @internal |
|
28
|
|
|
*/ |
|
29
|
|
|
class CollectionHelper |
|
30
|
|
|
{ |
|
31
|
|
|
const DEFAULT_STRATEGY = ClassMetadataInfo::STORAGE_STRATEGY_PUSH_ALL; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Returns whether update query must be included in query updating owning document. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $strategy |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
206 |
|
public static function isAtomic($strategy) |
|
40
|
|
|
{ |
|
41
|
206 |
|
return $strategy === ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET || $strategy === ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET_ARRAY; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Returns whether Collection hold associative array. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $strategy |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
190 |
|
public static function isHash($strategy) |
|
51
|
|
|
{ |
|
52
|
190 |
|
return $strategy === ClassMetadataInfo::STORAGE_STRATEGY_SET || $strategy === ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns whether Collection hold array indexed by consecutive numbers. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $strategy |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
399 |
|
public static function isList($strategy) |
|
62
|
|
|
{ |
|
63
|
399 |
|
return $strategy !== ClassMetadataInfo::STORAGE_STRATEGY_SET && $strategy !== ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns whether strategy uses $set to update its data. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $strategy |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
427 |
|
public static function usesSet($strategy) |
|
73
|
|
|
{ |
|
74
|
427 |
|
return in_array( |
|
75
|
427 |
|
$strategy, |
|
76
|
|
|
[ |
|
77
|
427 |
|
ClassMetadataInfo::STORAGE_STRATEGY_SET, |
|
78
|
427 |
|
ClassMetadataInfo::STORAGE_STRATEGY_SET_ARRAY, |
|
79
|
427 |
|
ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET, |
|
80
|
427 |
|
ClassMetadataInfo::STORAGE_STRATEGY_ATOMIC_SET_ARRAY |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|