Completed
Pull Request — master (#5860)
by Peter
11:07
created

ORMException::invalidOrientation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
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\ORM;
21
22
use Doctrine\Common\Cache\Cache as CacheDriver;
23
use Exception;
24
25
/**
26
 * Base exception class for all ORM exceptions.
27
 *
28
 * @author Roman Borschel <[email protected]>
29
 * @since 2.0
30
 */
31
class ORMException extends Exception
32
{
33
    /**
34
     * @return ORMException
35
     */
36
    public static function missingMappingDriverImpl()
37
    {
38
        return new self("It's a requirement to specify a Metadata Driver and pass it ".
39
            "to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
40
    }
41
42
    /**
43
     * @param string $queryName
44
     *
45
     * @return ORMException
46
     */
47 2
    public static function namedQueryNotFound($queryName)
48
    {
49 2
        return new self('Could not find a named query by the name "' . $queryName . '"');
50
    }
51
52
    /**
53
     * @param string $nativeQueryName
54
     *
55
     * @return ORMException
56
     */
57
    public static function namedNativeQueryNotFound($nativeQueryName)
58
    {
59
        return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
60
    }
61
62
    /**
63
     * @param object $entity
64
     * @param object $relatedEntity
65
     *
66
     * @return ORMException
67
     */
68
    public static function entityMissingForeignAssignedId($entity, $relatedEntity)
69
    {
70
        return new self(
71
            "Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
72
            "however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " .
73
            "and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
74
            "of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call " .
75
            "EntityManager#flush() between both persist operations."
76
        );
77
    }
78
79
    /**
80
     * @param object $entity
81
     * @param string $field
82
     *
83
     * @return ORMException
84
     */
85 1
    public static function entityMissingAssignedIdForField($entity, $field)
86
    {
87 1
        return new self("Entity of type " . get_class($entity) . " is missing an assigned ID for field  '" . $field . "'. " .
88 1
            "The identifier generation strategy for this entity requires the ID field to be populated before ".
89 1
            "EntityManager#persist() is called. If you want automatically generated identifiers instead " .
90 1
            "you need to adjust the metadata mapping accordingly."
91
        );
92
    }
93
94
    /**
95
     * @param string $field
96
     *
97
     * @return ORMException
98
     */
99 3
    public static function unrecognizedField($field)
100
    {
101 3
        return new self("Unrecognized field: $field");
102
    }
103
104
     /**
105
     *
106
     * @param string $class
107
     * @param string $association
108
     * @param string $given
109
     * @param string $expected
110
     *
111
     * @return \Doctrine\ORM\ORMInvalidArgumentException
112
     */
113
    public static function unexpectedAssociationValue($class, $association, $given, $expected)
114
    {
115
        return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
116
    }
117
118
    /**
119
     * @param string $className
120
     * @param string $field
121
     *
122
     * @return ORMException
123
     */
124 1
    public static function invalidOrientation($className, $field)
125
    {
126 1
        return new self("Invalid order by orientation specified for " . $className . "#" . $field);
127
    }
128
129
    /**
130
     * @param string $mode
131
     *
132
     * @return ORMException
133
     */
134
    public static function invalidFlushMode($mode)
135
    {
136
        return new self("'$mode' is an invalid flush mode.");
137
    }
138
139
    /**
140
     * @return ORMException
141
     */
142 5
    public static function entityManagerClosed()
143
    {
144 5
        return new self("The EntityManager is closed.");
145
    }
146
147
    /**
148
     * @param string $mode
149
     *
150
     * @return ORMException
151
     */
152
    public static function invalidHydrationMode($mode)
153
    {
154
        return new self("'$mode' is an invalid hydration mode.");
155
    }
156
157
    /**
158
     * @param string $methodName
159
     *
160
     * @return ORMException
161
     */
162 1
    public static function findByRequiresParameter($methodName)
163
    {
164 1
        return new self("You need to pass a parameter to '".$methodName."'");
165
    }
166
167
    /**
168
     * @param string $entityName
169
     * @param string $fieldName
170
     * @param string $method
171
     *
172
     * @return ORMException
173
     */
174 1
    public static function invalidFindByCall($entityName, $fieldName, $method)
175
    {
176 1
        return new self(
177 1
            "Entity '".$entityName."' has no field '".$fieldName."'. ".
178 1
            "You can therefore not call '".$method."' on the entities' repository"
179
        );
180
    }
181
182
    /**
183
     * @param string $entityName
184
     * @param string $associationFieldName
185
     *
186
     * @return ORMException
187
     */
188 2
    public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
189
    {
190 2
        return new self(
191 2
            "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
192 2
            "because it is the inverse side of an association. Find methods only work on owning side associations."
193
        );
194
    }
195
196
    /**
197
     * @return ORMException
198
     */
199
    public static function invalidResultCacheDriver()
200
    {
201
        return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
202
    }
203
204
    /**
205
     * @return ORMException
206
     */
207
    public static function notSupported()
208
    {
209
        return new self("This behaviour is (currently) not supported by Doctrine 2");
210
    }
211
212
    /**
213
     * @return ORMException
214
     */
215 1
    public static function queryCacheNotConfigured()
216
    {
217 1
        return new self('Query Cache is not configured.');
218
    }
219
220
    /**
221
     * @return ORMException
222
     */
223 1
    public static function metadataCacheNotConfigured()
224
    {
225 1
        return new self('Class Metadata Cache is not configured.');
226
    }
227
228
    /**
229
     * @param \Doctrine\Common\Cache\Cache $cache
230
     *
231
     * @return ORMException
232
     */
233 1
    public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
234
    {
235 1
        return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
236
    }
237
238
    /**
239
     * @param \Doctrine\Common\Cache\Cache $cache
240
     *
241
     * @return ORMException
242
     */
243 1
    public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
244
    {
245 1
        return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
246
    }
247
248
    /**
249
     * @return ORMException
250
     */
251 3
    public static function proxyClassesAlwaysRegenerating()
252
    {
253 3
        return new self('Proxy Classes are always regenerating.');
254
    }
255
256
    /**
257
     * @param string $entityNamespaceAlias
258
     *
259
     * @return ORMException
260
     */
261 1
    public static function unknownEntityNamespace($entityNamespaceAlias)
262
    {
263 1
        return new self(
264 1
            "Unknown Entity namespace alias '$entityNamespaceAlias'."
265
        );
266
    }
267
268
    /**
269
     * @param string $className
270
     *
271
     * @return ORMException
272
     */
273 1
    public static function invalidEntityRepository($className)
274
    {
275 1
        return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
276
    }
277
278
    /**
279
     * @param string $className
280
     * @param string $fieldName
281
     *
282
     * @return ORMException
283
     */
284 1
    public static function missingIdentifierField($className, $fieldName)
285
    {
286 1
        return new self("The identifier $fieldName is missing for a query of " . $className);
287
    }
288
289
    /**
290
     * @param string $className
291
     * @param string[] $fieldNames
292
     *
293
     * @return ORMException
294
     */
295 2
    public static function unrecognizedIdentifierFields($className, $fieldNames)
296
    {
297 2
        return new self(
298 2
            "Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
299 2
            "are not present on class '" . $className . "'."
300
        );
301
    }
302
303
    /**
304
     * @param string $functionName
305
     *
306
     * @return ORMException
307
     */
308 3
    public static function overwriteInternalDQLFunctionNotAllowed($functionName)
309
    {
310 3
        return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions.");
311
    }
312
313
    /**
314
     * @return ORMException
315
     */
316 1
    public static function cantUseInOperatorOnCompositeKeys()
317
    {
318 1
        return new self("Can't use IN operator on entities that have composite keys.");
319
    }
320
}
321