From 4cfdf5d19402c3ea94f77663971d692b9717a18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojte=CC=8Cch=20Lacina?= Date: Thu, 21 Mar 2019 22:23:53 +0100 Subject: [PATCH] PSR-4 Autoloading - Exceptions were moved in separated files - Added aliases for exceptions - Composer require PHP at ^7.1 --- composer.json | 15 +- src/Kdyby/Doctrine/Connection.php | 5 +- src/Kdyby/Doctrine/DI/OrmExtension.php | 8 +- .../EntityManagerUnitOfWorkSnapshotPanel.php | 2 +- src/Kdyby/Doctrine/Diagnostics/Panel.php | 10 +- .../Doctrine/Entities/SerializableMixin.php | 2 +- src/Kdyby/Doctrine/EntityManager.php | 2 + src/Kdyby/Doctrine/EntityRepository.php | 5 +- .../Doctrine/Exception/DBALException.php | 57 ++++ .../Exception/DuplicateEntryException.php | 45 +++ .../Exception/EmptyValueException.php | 44 +++ src/Kdyby/Doctrine/Exception/IException.php | 15 + .../Exception/InvalidArgumentException.php | 15 + .../Exception/InvalidStateException.php | 15 + .../Exception/MissingClassException.php | 13 + .../Exception/NotImplementedException.php | 13 + .../Exception/NotSupportedException.php | 13 + .../Doctrine/Exception/QueryException.php | 31 ++ .../Exception/ReadOnlyCollectionException.php | 19 ++ .../Exception/StaticClassException.php | 13 + .../Exception/UnexpectedValueException.php | 13 + .../Doctrine/Mapping/ClassMetadataFactory.php | 2 +- .../Mapping/ResultSetMappingBuilder.php | 2 +- src/Kdyby/Doctrine/NativeQueryBuilder.php | 1 + src/Kdyby/Doctrine/NativeQueryWrapper.php | 1 + src/Kdyby/Doctrine/QueryObject.php | 2 + src/Kdyby/Doctrine/ResultSet.php | 4 +- .../Tools/NonLockingUniqueInserter.php | 2 +- src/Kdyby/Doctrine/exceptions.php | 274 ------------------ tests/KdybyTests/Doctrine/Connection.phpt | 4 +- .../KdybyTests/DoctrineMocks/TestTypeMock.php | 4 +- 31 files changed, 346 insertions(+), 305 deletions(-) create mode 100644 src/Kdyby/Doctrine/Exception/DBALException.php create mode 100644 src/Kdyby/Doctrine/Exception/DuplicateEntryException.php create mode 100644 src/Kdyby/Doctrine/Exception/EmptyValueException.php create mode 100644 src/Kdyby/Doctrine/Exception/IException.php create mode 100644 src/Kdyby/Doctrine/Exception/InvalidArgumentException.php create mode 100644 src/Kdyby/Doctrine/Exception/InvalidStateException.php create mode 100644 src/Kdyby/Doctrine/Exception/MissingClassException.php create mode 100644 src/Kdyby/Doctrine/Exception/NotImplementedException.php create mode 100644 src/Kdyby/Doctrine/Exception/NotSupportedException.php create mode 100644 src/Kdyby/Doctrine/Exception/QueryException.php create mode 100644 src/Kdyby/Doctrine/Exception/ReadOnlyCollectionException.php create mode 100644 src/Kdyby/Doctrine/Exception/StaticClassException.php create mode 100644 src/Kdyby/Doctrine/Exception/UnexpectedValueException.php delete mode 100644 src/Kdyby/Doctrine/exceptions.php diff --git a/composer.json b/composer.json index d1004c7c..2616e1a6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "issues": "https://github.com/kdyby/doctrine/issues" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "doctrine/orm": "~2.5", "doctrine/dbal": "~2.5", "kdyby/console": "^2.7.1", @@ -44,18 +44,15 @@ }, "minimum-stability": "dev", "autoload": { - "psr-0": { + "psr-4": { "Kdyby\\Doctrine\\": "src/", "Kdyby\\Persistence\\": "src/" - }, - "classmap": [ - "src/Kdyby/Doctrine/exceptions.php" - ] + } }, "autoload-dev": { - "classmap": [ - "tests/KdybyTests" - ] + "psr-4": { + "KdybyTests\\": "tests/KdybyTests/" + } }, "extra": { "branch-alias": { diff --git a/src/Kdyby/Doctrine/Connection.php b/src/Kdyby/Doctrine/Connection.php index ca8d4a86..cebba8e9 100644 --- a/src/Kdyby/Doctrine/Connection.php +++ b/src/Kdyby/Doctrine/Connection.php @@ -15,6 +15,9 @@ use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Driver; use Kdyby; +use Kdyby\Doctrine\Exception\DBALException; +use Kdyby\Doctrine\Exception\DuplicateEntryException; +use Kdyby\Doctrine\Exception\EmptyValueException; use Nette; use PDO; use Tracy; @@ -375,7 +378,7 @@ public static function create(array $params, Doctrine\DBAL\Configuration $config * @param \Exception|\Throwable $e * @param string $query * @param array $params - * @return \Kdyby\Doctrine\DBALException|\Exception|\Throwable + * @return \Kdyby\Doctrine\Exception\DBALException|\Exception|\Throwable */ public function resolveException($e, $query = NULL, $params = []) { diff --git a/src/Kdyby/Doctrine/DI/OrmExtension.php b/src/Kdyby/Doctrine/DI/OrmExtension.php index 1837eef3..3d1d75af 100644 --- a/src/Kdyby/Doctrine/DI/OrmExtension.php +++ b/src/Kdyby/Doctrine/DI/OrmExtension.php @@ -171,12 +171,12 @@ public function loadConfiguration() } if (empty($config)) { - throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); + throw new Kdyby\Doctrine\Exception\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); } foreach ($config as $name => $emConfig) { if (!is_array($emConfig) || (empty($emConfig['dbname']) && empty($emConfig['driver']))) { - throw new Kdyby\Doctrine\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); + throw new Kdyby\Doctrine\Exception\UnexpectedValueException("Please configure the Doctrine extensions using the section '{$this->name}:' in your config file."); } /** @var mixed[] $emConfig */ @@ -224,7 +224,7 @@ protected function loadConsole() $cli->setClass($command); } else { - throw new Kdyby\Doctrine\NotSupportedException; + throw new Kdyby\Doctrine\Exception\NotSupportedException; } } } @@ -845,7 +845,7 @@ private function addCollapsePathsToTracy(Method $init) $blueScreen = \Tracy\Debugger::class . '::getBlueScreen()'; $commonDirname = dirname(Nette\Reflection\ClassType::from(Doctrine\Common\Version::class)->getFileName()); - $init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(Nette\Reflection\ClassType::from(Kdyby\Doctrine\Exception::class)->getFileName())]); + $init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(Nette\Reflection\ClassType::from(Kdyby\Doctrine\Exception\IException::class)->getFileName())]); $init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(dirname(dirname(dirname($commonDirname))))]); // this should be vendor/doctrine foreach ($this->proxyAutoloaders as $dir) { $init->addBody($blueScreen . '->collapsePaths[] = ?;', [$dir]); diff --git a/src/Kdyby/Doctrine/Diagnostics/EntityManagerUnitOfWorkSnapshotPanel.php b/src/Kdyby/Doctrine/Diagnostics/EntityManagerUnitOfWorkSnapshotPanel.php index f4b94bd9..1f042363 100644 --- a/src/Kdyby/Doctrine/Diagnostics/EntityManagerUnitOfWorkSnapshotPanel.php +++ b/src/Kdyby/Doctrine/Diagnostics/EntityManagerUnitOfWorkSnapshotPanel.php @@ -108,7 +108,7 @@ public function renderEntityManagerException($e) public function bindEntityManager(Doctrine\ORM\EntityManager $em) { if ($this->em !== NULL) { - throw new Kdyby\Doctrine\InvalidStateException(sprintf('%s is already bound to an entity manager.', __CLASS__)); + throw new Kdyby\Doctrine\Exception\InvalidStateException(sprintf('%s is already bound to an entity manager.', __CLASS__)); } $this->em = $em; diff --git a/src/Kdyby/Doctrine/Diagnostics/Panel.php b/src/Kdyby/Doctrine/Diagnostics/Panel.php index fb1de875..0e3db79d 100644 --- a/src/Kdyby/Doctrine/Diagnostics/Panel.php +++ b/src/Kdyby/Doctrine/Diagnostics/Panel.php @@ -333,7 +333,7 @@ public function renderQueryException($e) 'panel' => $this->dumpQuery($sql, $params, $types, $source), ]; - } elseif ($e instanceof Kdyby\Doctrine\QueryException && $e->query !== NULL) { + } elseif ($e instanceof Kdyby\Doctrine\Exception\QueryException && $e->query !== NULL) { if ($e->query instanceof Doctrine\ORM\Query) { return [ 'tab' => 'DQL', @@ -409,7 +409,7 @@ public static function renderException($e, Nette\DI\Container $dic) ]; } - } elseif ($e instanceof Kdyby\Doctrine\DBALException && $e->query !== NULL) { + } elseif ($e instanceof Kdyby\Doctrine\Exception\DBALException && $e->query !== NULL) { return [ 'tab' => 'SQL', 'panel' => self::highlightQuery(static::formatQuery($e->query, $e->params, [])), @@ -600,7 +600,7 @@ public static function formatQuery($query, $params, array $types = [], AbstractP if (Nette\Utils\Validators::isList($params)) { $parts = explode('?', $query); if (count($params) > $parts) { - throw new Kdyby\Doctrine\InvalidStateException("Too mny parameters passed to query."); + throw new Kdyby\Doctrine\Exception\InvalidStateException("Too mny parameters passed to query."); } return implode('', Kdyby\Doctrine\Helpers::zipper($parts, $params)); @@ -803,7 +803,7 @@ private static function editorLink($file, $line, $text = NULL) public function enableLogging() { if ($this->connection === NULL) { - throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is not bound to connection."); + throw new Kdyby\Doctrine\Exception\InvalidStateException("Doctrine Panel is not bound to connection."); } $config = $this->connection->getConfiguration(); @@ -826,7 +826,7 @@ public function enableLogging() public function bindConnection(Doctrine\DBAL\Connection $connection) { if ($this->connection !== NULL) { - throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is already bound to connection."); + throw new Kdyby\Doctrine\Exception\InvalidStateException("Doctrine Panel is already bound to connection."); } $this->connection = $connection; diff --git a/src/Kdyby/Doctrine/Entities/SerializableMixin.php b/src/Kdyby/Doctrine/Entities/SerializableMixin.php index 9ff4982e..331bc731 100644 --- a/src/Kdyby/Doctrine/Entities/SerializableMixin.php +++ b/src/Kdyby/Doctrine/Entities/SerializableMixin.php @@ -11,7 +11,7 @@ namespace Kdyby\Doctrine\Entities; use Kdyby; -use Kdyby\Doctrine\StaticClassException; +use Kdyby\Doctrine\Exception\StaticClassException; use Nette; use Nette\Reflection\ClassType; use Serializable; diff --git a/src/Kdyby/Doctrine/EntityManager.php b/src/Kdyby/Doctrine/EntityManager.php index 63372755..a4d6e21a 100644 --- a/src/Kdyby/Doctrine/EntityManager.php +++ b/src/Kdyby/Doctrine/EntityManager.php @@ -17,6 +17,8 @@ use Doctrine\ORM\Query; use Kdyby; use Kdyby\Doctrine\Diagnostics\EntityManagerUnitOfWorkSnapshotPanel; +use Kdyby\Doctrine\Exception\NotSupportedException; +use Kdyby\Doctrine\Exception\QueryException; use Kdyby\Doctrine\QueryObject; use Kdyby\Doctrine\Tools\NonLockingUniqueInserter; use Kdyby\Persistence; diff --git a/src/Kdyby/Doctrine/EntityRepository.php b/src/Kdyby/Doctrine/EntityRepository.php index 2f268c93..5b31c920 100644 --- a/src/Kdyby/Doctrine/EntityRepository.php +++ b/src/Kdyby/Doctrine/EntityRepository.php @@ -15,6 +15,7 @@ use Doctrine\ORM\NoResultException; use Doctrine\ORM\NonUniqueResultException; use Kdyby; +use Kdyby\Doctrine\Exception\QueryException; use Kdyby\Persistence; use Nette; @@ -286,7 +287,7 @@ public function getReference($id) /** * @param \Exception $e * @param \Kdyby\Persistence\Query $queryObject - * @return \Kdyby\Doctrine\QueryException + * @return \Kdyby\Doctrine\Exception\QueryException */ private function handleQueryException(\Exception $e, Persistence\Query $queryObject) { @@ -301,7 +302,7 @@ private function handleQueryException(\Exception $e, Persistence\Query $queryObj * @param \Exception $e * @param \Doctrine\ORM\Query $query * @param string $message - * @return \Exception|\Kdyby\Doctrine\QueryException + * @return \Exception|\Kdyby\Doctrine\Exception\QueryException */ private function handleException(\Exception $e, Doctrine\ORM\Query $query = NULL, $message = NULL) { diff --git a/src/Kdyby/Doctrine/Exception/DBALException.php b/src/Kdyby/Doctrine/Exception/DBALException.php new file mode 100644 index 00000000..969022ec --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/DBALException.php @@ -0,0 +1,57 @@ + + * @deprecated + */ +class DBALException extends \RuntimeException implements IException +{ + + /** + * @var string|NULL + */ + public $query; + + /** + * @var array + */ + public $params = []; + + /** + * @var \Doctrine\DBAL\Connection|NULL + */ + public $connection; + + + /** + * @param \Exception|\Throwable $previous + * @param string|NULL $query + * @param array $params + * @param \Doctrine\DBAL\Connection|NULL $connection + * @param string|NULL $message + */ + public function __construct($previous, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL, $message = NULL) + { + parent::__construct($message ?: $previous->getMessage(), $previous->getCode(), $previous); + $this->query = $query; + $this->params = $params; + $this->connection = $connection; + } + + + /** + * This is just a paranoia, hopes no one actually serializes exceptions. + * + * @return array + */ + public function __sleep() + { + return ['message', 'code', 'file', 'line', 'errorInfo', 'query', 'params']; + } + +} + +class_alias(DBALException::class, 'Kdyby\Doctrine\DBALException'); diff --git a/src/Kdyby/Doctrine/Exception/DuplicateEntryException.php b/src/Kdyby/Doctrine/Exception/DuplicateEntryException.php new file mode 100644 index 00000000..6641aa46 --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/DuplicateEntryException.php @@ -0,0 +1,45 @@ + + * @deprecated + */ +class DuplicateEntryException extends DBALException +{ + + /** + * @var array + */ + public $columns; + + + /** + * @param \Exception|\Throwable $previous + * @param array $columns + * @param string $query + * @param array $params + * @param \Doctrine\DBAL\Connection $connection + */ + public function __construct($previous, $columns = [], $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL) + { + parent::__construct($previous, $query, $params, $connection); + $this->columns = $columns; + } + + + /** + * @return array + */ + public function __sleep() + { + return array_merge(parent::__sleep(), ['columns']); + } + +} + +class_alias(DuplicateEntryException::class, 'Kdyby\Doctrine\DuplicateEntryException'); diff --git a/src/Kdyby/Doctrine/Exception/EmptyValueException.php b/src/Kdyby/Doctrine/Exception/EmptyValueException.php new file mode 100644 index 00000000..d557e8fb --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/EmptyValueException.php @@ -0,0 +1,44 @@ + + * @deprecated + */ +class EmptyValueException extends DBALException +{ + + /** + * @var string|NULL + */ + public $column; + + + /** + * @param \Exception|\Throwable $previous + * @param string|NULL $column + * @param string $query + * @param array $params + * @param \Doctrine\DBAL\Connection $connection + */ + public function __construct($previous, $column = NULL, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL) + { + parent::__construct($previous, $query, $params, $connection); + $this->column = $column; + } + + + /** + * @return array + */ + public function __sleep() + { + return array_merge(parent::__sleep(), ['column']); + } + +} + +class_alias(EmptyValueException::class, 'Kdyby\Doctrine\EmptyValueException'); diff --git a/src/Kdyby/Doctrine/Exception/IException.php b/src/Kdyby/Doctrine/Exception/IException.php new file mode 100644 index 00000000..5f37916f --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/IException.php @@ -0,0 +1,15 @@ + + */ +interface IException +{ + +} + +class_alias(IException::class, 'Kdyby\Doctrine\Exception'); diff --git a/src/Kdyby/Doctrine/Exception/InvalidArgumentException.php b/src/Kdyby/Doctrine/Exception/InvalidArgumentException.php new file mode 100644 index 00000000..6214e9a8 --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/InvalidArgumentException.php @@ -0,0 +1,15 @@ + + */ +class InvalidArgumentException extends \InvalidArgumentException implements IException +{ + +} + +class_alias(InvalidArgumentException::class, 'Kdyby\Doctrine\InvalidArgumentException'); diff --git a/src/Kdyby/Doctrine/Exception/InvalidStateException.php b/src/Kdyby/Doctrine/Exception/InvalidStateException.php new file mode 100644 index 00000000..aa8d70f6 --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/InvalidStateException.php @@ -0,0 +1,15 @@ + + */ +class InvalidStateException extends \RuntimeException implements IException +{ + +} + +class_alias(InvalidStateException::class, 'Kdyby\Doctrine\InvalidStateException'); diff --git a/src/Kdyby/Doctrine/Exception/MissingClassException.php b/src/Kdyby/Doctrine/Exception/MissingClassException.php new file mode 100644 index 00000000..40a68b32 --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/MissingClassException.php @@ -0,0 +1,13 @@ + + */ +class NotSupportedException extends \LogicException implements IException +{ + +} + +class_alias(NotSupportedException::class, 'Kdyby\Doctrine\NotSupportedException'); diff --git a/src/Kdyby/Doctrine/Exception/QueryException.php b/src/Kdyby/Doctrine/Exception/QueryException.php new file mode 100644 index 00000000..e93a5ab3 --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/QueryException.php @@ -0,0 +1,31 @@ + + */ +class QueryException extends \RuntimeException implements IException +{ + + /** + * @var \Doctrine\ORM\AbstractQuery|NULL + */ + public $query; + + + /** + * @param \Exception|\Throwable $previous + * @param \Doctrine\ORM\AbstractQuery|NULL $query + * @param string|NULL $message + */ + public function __construct($previous, Doctrine\ORM\AbstractQuery $query = NULL, $message = NULL) + { + parent::__construct($message ?: $previous->getMessage(), 0, $previous); + $this->query = $query; + } + +} + +class_alias(QueryException::class, 'Kdyby\Doctrine\QueryException'); diff --git a/src/Kdyby/Doctrine/Exception/ReadOnlyCollectionException.php b/src/Kdyby/Doctrine/Exception/ReadOnlyCollectionException.php new file mode 100644 index 00000000..3feb243a --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/ReadOnlyCollectionException.php @@ -0,0 +1,19 @@ + + */ +class StaticClassException extends \LogicException implements IException +{ + +} + +class_alias(StaticClassException::class, 'Kdyby\Doctrine\StaticClassException'); diff --git a/src/Kdyby/Doctrine/Exception/UnexpectedValueException.php b/src/Kdyby/Doctrine/Exception/UnexpectedValueException.php new file mode 100644 index 00000000..5c3e44fd --- /dev/null +++ b/src/Kdyby/Doctrine/Exception/UnexpectedValueException.php @@ -0,0 +1,13 @@ + + */ +class UnexpectedValueException extends \UnexpectedValueException implements IException +{ + +} + +class_alias(UnexpectedValueException::class, 'Kdyby\Doctrine\UnexpectedValueException'); diff --git a/src/Kdyby/Doctrine/Mapping/ClassMetadataFactory.php b/src/Kdyby/Doctrine/Mapping/ClassMetadataFactory.php index 542783b2..db71c0ec 100644 --- a/src/Kdyby/Doctrine/Mapping/ClassMetadataFactory.php +++ b/src/Kdyby/Doctrine/Mapping/ClassMetadataFactory.php @@ -67,7 +67,7 @@ protected function loadMetadata($name) } if (!class_exists($name)) { - throw new Kdyby\Doctrine\MissingClassException("Metadata of class $name was not found, because the class is missing or cannot be autoloaded."); + throw new Kdyby\Doctrine\Exception\MissingClassException("Metadata of class $name was not found, because the class is missing or cannot be autoloaded."); } return parent::loadMetadata($origName); diff --git a/src/Kdyby/Doctrine/Mapping/ResultSetMappingBuilder.php b/src/Kdyby/Doctrine/Mapping/ResultSetMappingBuilder.php index 0618bf3f..0a9893ad 100644 --- a/src/Kdyby/Doctrine/Mapping/ResultSetMappingBuilder.php +++ b/src/Kdyby/Doctrine/Mapping/ResultSetMappingBuilder.php @@ -252,7 +252,7 @@ public function generateSelectClause($tableAliases = []) if (!$class->hasField($fieldName)) { if (!$class->isInheritanceTypeSingleTable() && !$class->isInheritanceTypeJoined()) { - throw new Kdyby\Doctrine\UnexpectedValueException("Entity " . $class->getName() . " has no field '$fieldName' for column '$columnName'."); + throw new Kdyby\Doctrine\Exception\UnexpectedValueException("Entity " . $class->getName() . " has no field '$fieldName' for column '$columnName'."); } foreach ($class->subClasses as $subClass) { diff --git a/src/Kdyby/Doctrine/NativeQueryBuilder.php b/src/Kdyby/Doctrine/NativeQueryBuilder.php index 5cb1e08a..0b265db0 100644 --- a/src/Kdyby/Doctrine/NativeQueryBuilder.php +++ b/src/Kdyby/Doctrine/NativeQueryBuilder.php @@ -12,6 +12,7 @@ use Doctrine; use Kdyby; +use Kdyby\Doctrine\Exception\InvalidArgumentException; use Nette; diff --git a/src/Kdyby/Doctrine/NativeQueryWrapper.php b/src/Kdyby/Doctrine/NativeQueryWrapper.php index 002e105e..e1c157c4 100644 --- a/src/Kdyby/Doctrine/NativeQueryWrapper.php +++ b/src/Kdyby/Doctrine/NativeQueryWrapper.php @@ -17,6 +17,7 @@ use Doctrine\ORM\NativeQuery; use Doctrine\ORM\Query; use Kdyby; +use Kdyby\Doctrine\Exception\NotImplementedException; use Nette; diff --git a/src/Kdyby/Doctrine/QueryObject.php b/src/Kdyby/Doctrine/QueryObject.php index 1687cb17..311642dd 100644 --- a/src/Kdyby/Doctrine/QueryObject.php +++ b/src/Kdyby/Doctrine/QueryObject.php @@ -15,6 +15,8 @@ use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Tools\Pagination\Paginator; use Kdyby; +use Kdyby\Doctrine\Exception\NotSupportedException; +use Kdyby\Doctrine\Exception\UnexpectedValueException; use Kdyby\Persistence\Queryable; use Nette; diff --git a/src/Kdyby/Doctrine/ResultSet.php b/src/Kdyby/Doctrine/ResultSet.php index b225f0c3..0ffd54c8 100644 --- a/src/Kdyby/Doctrine/ResultSet.php +++ b/src/Kdyby/Doctrine/ResultSet.php @@ -14,6 +14,8 @@ use Doctrine\ORM\ORMException; use Doctrine\ORM\Tools\Pagination\Paginator as ResultPaginator; use Kdyby; +use Kdyby\Doctrine\Exception\InvalidArgumentException; +use Kdyby\Doctrine\Exception\QueryException; use Kdyby\Persistence\Queryable; use Nette; use Nette\Utils\Strings; @@ -278,7 +280,7 @@ public function isEmpty() /** - * @throws \Kdyby\Doctrine\QueryException + * @throws \Kdyby\Doctrine\Exception\QueryException * @return int */ public function getTotalCount() diff --git a/src/Kdyby/Doctrine/Tools/NonLockingUniqueInserter.php b/src/Kdyby/Doctrine/Tools/NonLockingUniqueInserter.php index 7cedcf14..bb808359 100644 --- a/src/Kdyby/Doctrine/Tools/NonLockingUniqueInserter.php +++ b/src/Kdyby/Doctrine/Tools/NonLockingUniqueInserter.php @@ -106,7 +106,7 @@ public function persist($entity) return FALSE; - } catch (Kdyby\Doctrine\DuplicateEntryException $e) { + } catch (Kdyby\Doctrine\Exception\DuplicateEntryException $e) { $this->db->rollBack(); return FALSE; diff --git a/src/Kdyby/Doctrine/exceptions.php b/src/Kdyby/Doctrine/exceptions.php deleted file mode 100644 index 968ef90f..00000000 --- a/src/Kdyby/Doctrine/exceptions.php +++ /dev/null @@ -1,274 +0,0 @@ - - */ -interface Exception -{ - -} - - - -/** - * @author Filip Procházka - */ -class InvalidStateException extends \RuntimeException implements Exception -{ - -} - - - -/** - * @author Filip Procházka - */ -class InvalidArgumentException extends \InvalidArgumentException implements Exception -{ - -} - - - -/** - * @author Filip Procházka - */ -class NotSupportedException extends \LogicException implements Exception -{ - -} - - - -/** - * @author Filip Procházka - */ -class StaticClassException extends \LogicException implements Exception -{ - -} - - - -/** - * The exception that is thrown when a requested method or operation is not implemented. - */ -class NotImplementedException extends \LogicException implements Exception -{ - -} - - - -/** - * When class is not found - */ -class MissingClassException extends \LogicException implements Exception -{ - -} - - - -/** - * @author Filip Procházka - */ -class UnexpectedValueException extends \UnexpectedValueException implements Exception -{ - -} - - - -/** - * @author Filip Procházka - * @deprecated - */ -class DBALException extends \RuntimeException implements Exception -{ - - /** - * @var string|NULL - */ - public $query; - - /** - * @var array - */ - public $params = []; - - /** - * @var \Doctrine\DBAL\Connection|NULL - */ - public $connection; - - - - /** - * @param \Exception|\Throwable $previous - * @param string|NULL $query - * @param array $params - * @param \Doctrine\DBAL\Connection|NULL $connection - * @param string|NULL $message - */ - public function __construct($previous, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL, $message = NULL) - { - parent::__construct($message ?: $previous->getMessage(), $previous->getCode(), $previous); - $this->query = $query; - $this->params = $params; - $this->connection = $connection; - } - - - - /** - * This is just a paranoia, hopes no one actually serializes exceptions. - * - * @return array - */ - public function __sleep() - { - return ['message', 'code', 'file', 'line', 'errorInfo', 'query', 'params']; - } - -} - - - -/** - * @author Filip Procházka - * @deprecated - */ -class DuplicateEntryException extends DBALException -{ - - /** - * @var array - */ - public $columns; - - - - /** - * @param \Exception|\Throwable $previous - * @param array $columns - * @param string $query - * @param array $params - * @param \Doctrine\DBAL\Connection $connection - */ - public function __construct($previous, $columns = [], $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL) - { - parent::__construct($previous, $query, $params, $connection); - $this->columns = $columns; - } - - - - /** - * @return array - */ - public function __sleep() - { - return array_merge(parent::__sleep(), ['columns']); - } - -} - - - -/** - * @author Filip Procházka - * @deprecated - */ -class EmptyValueException extends DBALException -{ - - /** - * @var string|NULL - */ - public $column; - - - - /** - * @param \Exception|\Throwable $previous - * @param string|NULL $column - * @param string $query - * @param array $params - * @param \Doctrine\DBAL\Connection $connection - */ - public function __construct($previous, $column = NULL, $query = NULL, $params = [], Doctrine\DBAL\Connection $connection = NULL) - { - parent::__construct($previous, $query, $params, $connection); - $this->column = $column; - } - - - - /** - * @return array - */ - public function __sleep() - { - return array_merge(parent::__sleep(), ['column']); - } - -} - - - -/** - * @author Filip Procházka - */ -class QueryException extends \RuntimeException implements Exception -{ - - /** - * @var \Doctrine\ORM\AbstractQuery|NULL - */ - public $query; - - - - /** - * @param \Exception|\Throwable $previous - * @param \Doctrine\ORM\AbstractQuery|NULL $query - * @param string|NULL $message - */ - public function __construct($previous, Doctrine\ORM\AbstractQuery $query = NULL, $message = NULL) - { - parent::__construct($message ?: $previous->getMessage(), 0, $previous); - $this->query = $query; - } - -} - - - -/** - * @author Michael Moravec - */ -class ReadOnlyCollectionException extends NotSupportedException -{ - /** - * @throws ReadOnlyCollectionException - */ - public static function invalidAccess($what) - { - return new static('Could not ' . $what . ' read-only collection, write/modify operations are forbidden.'); - } -} diff --git a/tests/KdybyTests/Doctrine/Connection.phpt b/tests/KdybyTests/Doctrine/Connection.phpt index 0c4362b3..6b1498df 100644 --- a/tests/KdybyTests/Doctrine/Connection.phpt +++ b/tests/KdybyTests/Doctrine/Connection.phpt @@ -111,8 +111,8 @@ class ConnectionTest extends Tester\TestCase ); return [ - [$empty, \Kdyby\Doctrine\EmptyValueException::class, ['column' => 'name']], - [$unique, \Kdyby\Doctrine\DuplicateEntryException::class, ['columns' => ['uniq_name_surname' => ['name', 'surname']]]], + [$empty, \Kdyby\Doctrine\Exception\EmptyValueException::class, ['column' => 'name']], + [$unique, \Kdyby\Doctrine\Exception\DuplicateEntryException::class, ['columns' => ['uniq_name_surname' => ['name', 'surname']]]], ]; } diff --git a/tests/KdybyTests/DoctrineMocks/TestTypeMock.php b/tests/KdybyTests/DoctrineMocks/TestTypeMock.php index 004f59af..1da32a10 100644 --- a/tests/KdybyTests/DoctrineMocks/TestTypeMock.php +++ b/tests/KdybyTests/DoctrineMocks/TestTypeMock.php @@ -26,12 +26,12 @@ class TestTypeMock extends Doctrine\DBAL\Types\Type * @param array $fieldDeclaration * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * - * @throws \Kdyby\Doctrine\InvalidStateException + * @throws \Kdyby\Doctrine\Exception\InvalidStateException * @return mixed */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - throw new Kdyby\Doctrine\InvalidStateException( + throw new Kdyby\Doctrine\Exception\InvalidStateException( "Please, use the 'columnDefinition' property of @Column() annotation." ); }