Skip to content

Commit 77e3e5c

Browse files
authored
Merge pull request #6743 from greg0ire/split_orm_exception
Split orm exception
2 parents c7718ef + 10aac31 commit 77e3e5c

File tree

88 files changed

+814
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+814
-404
lines changed

lib/Doctrine/ORM/AbstractQuery.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\Collections\Collection;
99
use Doctrine\DBAL\Cache\QueryCacheProfile;
1010
use Doctrine\DBAL\Driver\Statement;
11+
use Doctrine\ORM\Cache\Exception\InvalidResultCacheDriver;
1112
use Doctrine\ORM\Cache\Logging\CacheLogger;
1213
use Doctrine\ORM\Cache\QueryCacheKey;
1314
use Doctrine\ORM\Cache\TimestampCacheKey;
@@ -497,7 +498,7 @@ public function setResultCacheProfile(?QueryCacheProfile $profile = null)
497498
public function setResultCacheDriver($resultCacheDriver = null)
498499
{
499500
if ($resultCacheDriver !== null && ! ($resultCacheDriver instanceof \Doctrine\Common\Cache\Cache)) {
500-
throw ORMException::invalidResultCacheDriver();
501+
throw InvalidResultCacheDriver::create();
501502
}
502503

503504
$this->queryCacheProfile = $this->queryCacheProfile

lib/Doctrine/ORM/Cache/CacheException.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/Doctrine/ORM/Cache/DefaultQueryCache.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Doctrine\ORM\Cache;
66

77
use Doctrine\ORM\Cache;
8+
use Doctrine\ORM\Cache\Exception\FeatureNotImplemented;
9+
use Doctrine\ORM\Cache\Exception\NonCacheableEntity;
810
use Doctrine\ORM\Cache\Logging\CacheLogger;
911
use Doctrine\ORM\Cache\Persister\CachedPersister;
1012
use Doctrine\ORM\EntityManagerInterface;
@@ -229,19 +231,19 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []
229231
public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = [])
230232
{
231233
if ($rsm->scalarMappings) {
232-
throw new CacheException('Second level cache does not support scalar results.');
234+
throw FeatureNotImplemented::scalarResults();
233235
}
234236

235237
if (count($rsm->entityMappings) > 1) {
236-
throw new CacheException('Second level cache does not support multiple root entities.');
238+
throw FeatureNotImplemented::multipleRootEntities();
237239
}
238240

239241
if (! $rsm->isSelect) {
240-
throw new CacheException('Second-level cache query supports only select statements.');
242+
throw FeatureNotImplemented::nonSelectStatements();
241243
}
242244

243245
if (isset($hints[Query::HINT_FORCE_PARTIAL_LOAD]) && $hints[Query::HINT_FORCE_PARTIAL_LOAD]) {
244-
throw new CacheException('Second level cache does not support partial entities.');
246+
throw FeatureNotImplemented::partialEntities();
245247
}
246248

247249
if (! ($key->cacheMode & Cache::MODE_PUT)) {
@@ -255,7 +257,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
255257
$persister = $unitOfWork->getEntityPersister($entityName);
256258

257259
if (! ($persister instanceof CachedPersister)) {
258-
throw CacheException::nonCacheableEntity($entityName);
260+
throw NonCacheableEntity::fromEntity($entityName);
259261
}
260262

261263
$region = $persister->getCacheRegion();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
use Doctrine\ORM\Exception\ORMException;
8+
9+
/**
10+
* Exception for cache.
11+
*/
12+
interface CacheException extends ORMException
13+
{
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
use function sprintf;
8+
9+
class CannotUpdateReadOnlyCollection extends \LogicException implements CacheException
10+
{
11+
public static function fromEntityAndField(string $sourceEntity, string $fieldName) : self
12+
{
13+
return new self(sprintf(
14+
'Cannot update a readonly collection "%s#%s"',
15+
$sourceEntity,
16+
$fieldName
17+
));
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
use function sprintf;
8+
9+
class CannotUpdateReadOnlyEntity extends \LogicException implements CacheException
10+
{
11+
public static function fromEntity(string $entityName) : self
12+
{
13+
return new self(sprintf('Cannot update a readonly entity "%s"', $entityName));
14+
}
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
class FeatureNotImplemented extends \LogicException implements CacheException
8+
{
9+
public static function scalarResults() : self
10+
{
11+
return new self('Second level cache does not support scalar results.');
12+
}
13+
14+
public static function multipleRootEntities() : self
15+
{
16+
return new self('Second level cache does not support multiple root entities.');
17+
}
18+
19+
public static function nonSelectStatements() : self
20+
{
21+
return new self('Second-level cache query supports only select statements.');
22+
}
23+
24+
public static function partialEntities() : self
25+
{
26+
return new self('Second level cache does not support partial entities.');
27+
}
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
final class InvalidResultCacheDriver extends \LogicException implements CacheException
8+
{
9+
public static function create() : self
10+
{
11+
return new self(
12+
'Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.'
13+
);
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
final class MetadataCacheNotConfigured extends \LogicException implements CacheException
8+
{
9+
public static function create() : self
10+
{
11+
return new self('Class Metadata Cache is not configured.');
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Cache\Exception;
6+
7+
use Doctrine\Common\Cache\Cache;
8+
use function get_class;
9+
10+
final class MetadataCacheUsesNonPersistentCache extends \LogicException implements CacheException
11+
{
12+
public static function fromDriver(Cache $cache) : self
13+
{
14+
return new self(
15+
'Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.'
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)