Completed
Pull Request — develop (#6743)
by Grégoire
65:04
created

ORMException::queryCacheUsesNonPersistentCache()   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 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM;
6
7
use Doctrine\Common\Cache\Cache as CacheDriver;
8
use Exception;
9
10
/**
11
 * Base exception class for all ORM exceptions.
12
 *
13
 * @author Roman Borschel <[email protected]>
14
 * @since 2.0
15
 */
16
class ORMException extends Exception
17
{
18
    /**
19
     * @return ORMException
20
     */
21
    public static function missingMappingDriverImpl()
22
    {
23
        return new self("It's a requirement to specify a Metadata Driver and pass it ".
24
            "to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().");
25
    }
26
27
    /**
28
     * @param string $queryName
29
     *
30
     * @return ORMException
31
     */
32
    public static function namedQueryNotFound($queryName)
33
    {
34
        return new self('Could not find a named query by the name "' . $queryName . '"');
35
    }
36
37
    /**
38
     * @param string $nativeQueryName
39
     *
40
     * @return ORMException
41
     */
42
    public static function namedNativeQueryNotFound($nativeQueryName)
43
    {
44
        return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
45
    }
46
47 2
    /**
48
     * @param string $field
49 2
     *
50
     * @return ORMException
51
     */
52
    public static function unrecognizedField($field)
53
    {
54
        return new self("Unrecognized field: $field");
55
    }
56
57
    /**
58
     *
59
     * @param string $class
60
     * @param string $association
61
     * @param string $given
62
     * @param string $expected
63
     *
64
     * @return \Doctrine\ORM\ORMInvalidArgumentException
65
     */
66
    public static function unexpectedAssociationValue($class, $association, $given, $expected)
67
    {
68
        return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected));
69
    }
70
71
    /**
72
     * @param string $className
73
     * @param string $field
74
     *
75
     * @return ORMException
76
     */
77
    public static function invalidOrientation($className, $field)
78
    {
79
        return new self("Invalid order by orientation specified for " . $className . "#" . $field);
80
    }
81
82
    /**
83
     * @return ORMException
84
     */
85 1
    public static function entityManagerClosed()
86
    {
87 1
        return new self("The EntityManager is closed.");
88 1
    }
89 1
90 1
    /**
91
     * @param string $mode
92
     *
93
     * @return ORMException
94
     */
95
    public static function invalidHydrationMode($mode)
96
    {
97
        return new self("'$mode' is an invalid hydration mode.");
98
    }
99 3
100
    /**
101 3
     * @return ORMException
102
     */
103
    public static function mismatchedEventManager()
104
    {
105
        return new self("Cannot use different EventManager instances for EntityManager and Connection.");
106
    }
107
108
    /**
109
     * @param string $methodName
110
     *
111
     * @return ORMException
112
     */
113
    public static function findByRequiresParameter($methodName)
114
    {
115
        return new self("You need to pass a parameter to '".$methodName."'");
116
    }
117
118
    /**
119
     * @param string $entityName
120
     * @param string $associationFieldName
121
     *
122
     * @return ORMException
123
     */
124 1
    public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
125
    {
126 1
        return new self(
127
            "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
128
            "because it is the inverse side of an association. Find methods only work on owning side associations."
129
        );
130
    }
131
132
    /**
133
     * @return ORMException
134
     */
135
    public static function invalidResultCacheDriver()
136
    {
137
        return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
138
    }
139
140
    /**
141
     * @return ORMException
142 5
     */
143
    public static function notSupported()
144 5
    {
145
        return new self("This behaviour is (currently) not supported by Doctrine 2");
146
    }
147
148
    /**
149
     * @return ORMException
150
     */
151
    public static function queryCacheNotConfigured()
152
    {
153
        return new self('Query Cache is not configured.');
154
    }
155
156
    /**
157
     * @return ORMException
158
     */
159
    public static function metadataCacheNotConfigured()
160
    {
161
        return new self('Class Metadata Cache is not configured.');
162
    }
163
164
    /**
165
     * @param \Doctrine\Common\Cache\Cache $cache
166
     *
167
     * @return ORMException
168
     */
169
    public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
170 1
    {
171
        return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
172 1
    }
173
174
    /**
175
     * @param \Doctrine\Common\Cache\Cache $cache
176
     *
177
     * @return ORMException
178
     */
179
    public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
180
    {
181
        return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.');
182 1
    }
183
184 1
    /**
185 1
     * @return ORMException
186 1
     */
187
    public static function proxyClassesAlwaysRegenerating()
188
    {
189
        return new self('Proxy Classes are always regenerating.');
190
    }
191
192
    /**
193
     * @param string $entityNamespaceAlias
194
     *
195
     * @return ORMException
196 2
     */
197
    public static function unknownEntityNamespace($entityNamespaceAlias)
198 2
    {
199 2
        return new self(
200 2
            "Unknown Entity namespace alias '$entityNamespaceAlias'."
201
        );
202
    }
203
204
    /**
205
     * @param string $className
206
     *
207
     * @return ORMException
208
     */
209
    public static function invalidEntityRepository($className)
210
    {
211
        return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
212
    }
213
214
    /**
215
     * @param string $className
216
     * @param string $fieldName
217
     *
218
     * @return ORMException
219
     */
220
    public static function missingIdentifierField($className, $fieldName)
221
    {
222
        return new self("The identifier $fieldName is missing for a query of " . $className);
223 1
    }
224
225 1
    /**
226
     * @param string $className
227
     * @param string[] $fieldNames
228
     *
229
     * @return ORMException
230
     */
231 1
    public static function unrecognizedIdentifierFields($className, $fieldNames)
232
    {
233 1
        return new self(
234
            "Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " .
235
            "are not present on class '" . $className . "'."
236
        );
237
    }
238
239
    /**
240
     * @return ORMException
241 1
     */
242
    public static function cantUseInOperatorOnCompositeKeys()
243 1
    {
244
        return new self("Can't use IN operator on entities that have composite keys.");
245
    }
246
}
247