1 | <?php |
||
20 | class MongoDBException extends \Exception |
||
21 | { |
||
22 | /** |
||
23 | * @return MongoDBException |
||
24 | */ |
||
25 | public static function detachedDocumentCannotBeRemoved() |
||
26 | { |
||
27 | return new self('Detached document cannot be removed'); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return MongoDBException |
||
32 | */ |
||
33 | public static function invalidDocumentState(int $state) |
||
37 | |||
38 | /** |
||
39 | * @param string $className |
||
40 | * @return MongoDBException |
||
41 | */ |
||
42 | public static function documentNotMappedToCollection($className) |
||
43 | { |
||
44 | return new self(sprintf('The "%s" document is not mapped to a MongoDB database collection.', $className)); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return MongoDBException |
||
49 | */ |
||
50 | 5 | public static function documentManagerClosed() |
|
51 | { |
||
52 | 5 | return new self('The DocumentManager is closed.'); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $documentNamespaceAlias |
||
57 | * @return MongoDBException |
||
58 | */ |
||
59 | public static function unknownDocumentNamespace($documentNamespaceAlias) |
||
60 | { |
||
61 | return new self(sprintf("Unknown Document namespace alias '%s'.", $documentNamespaceAlias)); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $className |
||
66 | * @return MongoDBException |
||
67 | */ |
||
68 | 1 | public static function cannotPersistMappedSuperclass($className) |
|
69 | { |
||
70 | 1 | return new self('Cannot persist an embedded document, aggregation result document or mapped superclass ' . $className); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $className |
||
75 | * @return MongoDBException |
||
76 | */ |
||
77 | public static function invalidDocumentRepository($className) |
||
78 | { |
||
79 | return new self(sprintf("Invalid repository class '%s'. It must be a %s.", $className, ObjectRepository::class)); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param string $type |
||
84 | * @param string|array $expected |
||
85 | * @param mixed $got |
||
86 | * @return MongoDBException |
||
87 | */ |
||
88 | 4 | public static function invalidValueForType($type, $expected, $got) |
|
89 | { |
||
90 | 4 | if (is_array($expected)) { |
|
91 | 4 | $expected = sprintf( |
|
92 | 4 | '%s or %s', |
|
93 | 4 | implode(', ', array_slice($expected, 0, -1)), |
|
94 | 4 | end($expected) |
|
95 | ); |
||
96 | } |
||
97 | 4 | if (is_object($got)) { |
|
98 | 2 | $gotType = get_class($got); |
|
99 | 2 | } elseif (is_array($got)) { |
|
100 | $gotType = 'array'; |
||
101 | } else { |
||
102 | 2 | $gotType = 'scalar'; |
|
103 | } |
||
104 | 4 | return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType)); |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param string $field |
||
109 | * @param string $className |
||
110 | * @return MongoDBException |
||
111 | */ |
||
112 | public static function shardKeyFieldCannotBeChanged($field, $className) |
||
116 | |||
117 | /** |
||
118 | * @param string $field |
||
119 | * @param string $className |
||
120 | * @return MongoDBException |
||
121 | */ |
||
122 | public static function shardKeyFieldMissing($field, $className) |
||
126 | |||
127 | /** |
||
128 | * @param string $dbName |
||
129 | * @param string $errorMessage |
||
130 | * @return MongoDBException |
||
131 | */ |
||
132 | public static function failedToEnableSharding($dbName, $errorMessage) |
||
140 | |||
141 | /** |
||
142 | * @param string $className |
||
143 | * @param string $errorMessage |
||
144 | * @return MongoDBException |
||
145 | */ |
||
146 | public static function failedToEnsureDocumentSharding($className, $errorMessage) |
||
154 | |||
155 | /** |
||
156 | * @return MongoDBException |
||
157 | */ |
||
158 | public static function commitInProgress() |
||
162 | |||
163 | /** |
||
164 | * @return MongoDBException |
||
165 | */ |
||
166 | public static function cannotRefreshDocument() |
||
170 | } |
||
171 |