1 | <?php |
||
27 | class MongoDBException extends \Exception |
||
28 | { |
||
29 | /** |
||
30 | * @param string $documentName |
||
31 | * @param string $fieldName |
||
32 | * @param string $method |
||
33 | * @return MongoDBException |
||
34 | */ |
||
35 | public static function invalidFindByCall($documentName, $fieldName, $method) |
||
36 | { |
||
37 | return new self(sprintf('Invalid find by call %s::$fieldName (%s)', $documentName, $fieldName, $method)); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return MongoDBException |
||
42 | */ |
||
43 | public static function detachedDocumentCannotBeRemoved() |
||
44 | { |
||
45 | return new self('Detached document cannot be removed'); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param string $state |
||
50 | * @return MongoDBException |
||
51 | */ |
||
52 | public static function invalidDocumentState($state) |
||
53 | { |
||
54 | return new self(sprintf('Invalid document state "%s"', $state)); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $className |
||
59 | * @return MongoDBException |
||
60 | */ |
||
61 | public static function documentNotMappedToCollection($className) |
||
62 | { |
||
63 | return new self(sprintf('The "%s" document is not mapped to a MongoDB database collection.', $className)); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return MongoDBException |
||
68 | */ |
||
69 | 5 | public static function documentManagerClosed() |
|
70 | { |
||
71 | 5 | return new self('The DocumentManager is closed.'); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param string $methodName |
||
76 | * @return MongoDBException |
||
77 | */ |
||
78 | public static function findByRequiresParameter($methodName) |
||
79 | { |
||
80 | return new self("You need to pass a parameter to '".$methodName."'"); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param string $documentNamespaceAlias |
||
85 | * @return MongoDBException |
||
86 | */ |
||
87 | public static function unknownDocumentNamespace($documentNamespaceAlias) |
||
88 | { |
||
89 | return new self("Unknown Document namespace alias '$documentNamespaceAlias'."); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @param string $className |
||
94 | * @return MongoDBException |
||
95 | */ |
||
96 | 1 | public static function cannotPersistMappedSuperclass($className) |
|
97 | { |
||
98 | 1 | return new self('Cannot persist an embedded document or mapped superclass ' . $className); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param string $className |
||
103 | * @param string $unindexedFields |
||
104 | * @return MongoDBException |
||
105 | */ |
||
106 | 5 | public static function queryNotIndexed($className, $unindexedFields) |
|
107 | { |
||
108 | 5 | return new self(sprintf('Cannot execute unindexed queries on %s. Unindexed fields: %s', |
|
109 | $className, |
||
110 | 5 | implode(', ', $unindexedFields) |
|
111 | )); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @param string $className |
||
116 | * @return MongoDBException |
||
117 | */ |
||
118 | public static function invalidDocumentRepository($className) |
||
119 | { |
||
120 | return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository."); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @param string $type |
||
125 | * @param string|array $expected |
||
126 | * @param mixed $got |
||
127 | * @return MongoDBException |
||
128 | */ |
||
129 | 4 | public static function invalidValueForType($type, $expected, $got) |
|
130 | { |
||
131 | 4 | if (is_array($expected)) { |
|
132 | 4 | $expected = sprintf('%s or %s', |
|
133 | 4 | join(', ', array_slice($expected, 0, -1)), |
|
134 | end($expected) |
||
135 | ); |
||
136 | } |
||
137 | 4 | if (is_object($got)) { |
|
138 | 2 | $gotType = get_class($got); |
|
139 | 2 | } elseif (is_array($got)) { |
|
140 | $gotType = 'array'; |
||
141 | } else { |
||
142 | 2 | $gotType = 'scalar'; |
|
143 | } |
||
144 | 4 | return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType)); |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * @param string $field |
||
149 | * @param string $className |
||
150 | * @return MongoDBException |
||
151 | */ |
||
152 | 2 | public static function shardKeyFieldCannotBeChanged($field, $className) |
|
156 | |||
157 | /** |
||
158 | * @param string $field |
||
159 | * @param string $className |
||
160 | * @return MongoDBException |
||
161 | */ |
||
162 | public static function shardKeyFieldMissing($field, $className) |
||
166 | |||
167 | /** |
||
168 | * @param string $dbName |
||
169 | * @param string $errorMessage |
||
170 | * @return MongoDBException |
||
171 | */ |
||
172 | 1 | public static function failedToEnableSharding($dbName, $errorMessage) |
|
179 | |||
180 | /** |
||
181 | * @param string $className |
||
182 | * @param string $errorMessage |
||
183 | * @return MongoDBException |
||
184 | */ |
||
185 | 1 | public static function failedToEnsureDocumentSharding($className, $errorMessage) |
|
192 | } |
||
193 |