From c76273507589b6e6a8db86a8964d4a7f48eb451f Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Fri, 21 Sep 2018 13:50:11 +0200 Subject: [PATCH] Favor LogicException for missing classes & functions --- src/Symfony/Component/BrowserKit/Client.php | 2 +- .../Component/Config/Util/XmlUtils.php | 2 +- .../Console/Command/LockableTrait.php | 3 +-- .../Compiler/AbstractRecursivePass.php | 3 ++- .../DependencyInjection/ContainerBuilder.php | 2 +- .../DependencyInjection/Dumper/PhpDumper.php | 2 +- .../DependencyInjection/Dumper/YamlDumper.php | 3 ++- .../DependencyInjection/EnvVarProcessor.php | 3 ++- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- .../Messenger/Exception/LogicException.php | 19 +++++++++++++++++++ .../Transport/Serialization/Serializer.php | 4 ++-- src/Symfony/Component/Process/Process.php | 2 +- .../PropertyAccess/PropertyAccessor.php | 2 +- .../Extractor/PhpDocExtractor.php | 2 +- .../Routing/Loader/AnnotationFileLoader.php | 2 +- .../Matcher/Dumper/PhpMatcherDumper.php | 2 +- .../Component/Routing/Matcher/UrlMatcher.php | 2 +- .../Normalizer/ObjectNormalizer.php | 4 ++-- .../Validator/Constraints/EmailValidator.php | 4 ++-- .../Constraints/ExpressionValidator.php | 4 ++-- .../Validator/Constraints/ImageValidator.php | 4 ++-- 21 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 src/Symfony/Component/Messenger/Exception/LogicException.php diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index e3056a31207a4..a8e4f440e98a9 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -118,7 +118,7 @@ public function getMaxRedirects() public function insulate($insulated = true) { if ($insulated && !class_exists('Symfony\\Component\\Process\\Process')) { - throw new \RuntimeException('Unable to isolate requests as the Symfony Process Component is not installed.'); + throw new \LogicException('Unable to isolate requests as the Symfony Process Component is not installed.'); } $this->insulated = (bool) $insulated; diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index d761e4e80fbad..3a660563cd548 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -47,7 +47,7 @@ private function __construct() public static function parse($content, $schemaOrCallable = null) { if (!\extension_loaded('dom')) { - throw new \RuntimeException('Extension DOM is required.'); + throw new \LogicException('Extension DOM is required.'); } $internalErrors = libxml_use_internal_errors(true); diff --git a/src/Symfony/Component/Console/Command/LockableTrait.php b/src/Symfony/Component/Console/Command/LockableTrait.php index 6c634ce44667a..f4ebe45bf37c7 100644 --- a/src/Symfony/Component/Console/Command/LockableTrait.php +++ b/src/Symfony/Component/Console/Command/LockableTrait.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Exception\LogicException; -use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Lock\Factory; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\Store\FlockStore; @@ -36,7 +35,7 @@ trait LockableTrait private function lock($name = null, $blocking = false) { if (!class_exists(SemaphoreStore::class)) { - throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.'); + throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); } if (null !== $this->lock) { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php index 8d6ea6b37c3f0..64c4edbc45af0 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php @@ -14,6 +14,7 @@ use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ExpressionLanguage; use Symfony\Component\DependencyInjection\Reference; @@ -197,7 +198,7 @@ private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists(ExpressionLanguage::class)) { - throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $providers = $this->container->getExpressionLanguageProviders(); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 5cfac704ce175..39c5b3f9d1055 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1587,7 +1587,7 @@ private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { - throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index b107d47ae8ed0..baf36c42cf8c1 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1692,7 +1692,7 @@ private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { - throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $providers = $this->container->getExpressionLanguageProviders(); $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 2a49c538751e9..3ca193c7c9478 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Reference; @@ -45,7 +46,7 @@ class YamlDumper extends Dumper public function dump(array $options = array()) { if (!class_exists('Symfony\Component\Yaml\Dumper')) { - throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.'); + throw new LogicException('Unable to dump the container as the Symfony Yaml Component is not installed.'); } if (null === $this->dumper) { diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index a33d3932afcaa..67a0687c24586 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -13,6 +13,7 @@ use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException; +use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** @@ -180,7 +181,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) private static function phpize($value) { if (!class_exists(XmlUtils::class)) { - throw new RuntimeException('The Symfony Config component is required to cast env vars to "bool", "int" or "float".'); + throw new LogicException('The Symfony Config component is required to cast env vars to "bool", "int" or "float".'); } return XmlUtils::phpize($value); diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 360ddbe26b3a3..77c392daf5310 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1166,7 +1166,7 @@ private function createSubCrawler($nodes) private function createCssSelectorConverter(): CssSelectorConverter { if (!\class_exists(CssSelectorConverter::class)) { - throw new \RuntimeException('To filter with a CSS selector, install the CssSelector component ("composer require symfony/css-selector"). Or use filterXpath instead.'); + throw new \LogicException('To filter with a CSS selector, install the CssSelector component ("composer require symfony/css-selector"). Or use filterXpath instead.'); } return new CssSelectorConverter($this->isHtml); diff --git a/src/Symfony/Component/Messenger/Exception/LogicException.php b/src/Symfony/Component/Messenger/Exception/LogicException.php new file mode 100644 index 0000000000000..75f97d270f17d --- /dev/null +++ b/src/Symfony/Component/Messenger/Exception/LogicException.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Exception; + +/** + * @author Roland Franssen + */ +class LogicException extends \LogicException implements ExceptionInterface +{ +} diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php index cdb873083a699..2087503e5086c 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php @@ -13,7 +13,7 @@ use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Exception\InvalidArgumentException; -use Symfony\Component\Messenger\Exception\RuntimeException; +use Symfony\Component\Messenger\Exception\LogicException; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -39,7 +39,7 @@ public function __construct(SymfonySerializerInterface $serializer, string $form public static function create(): self { if (!class_exists(SymfonySerializer::class)) { - throw new RuntimeException(sprintf('The default Messenger Serializer requires Symfony\'s Serializer component. Try running "composer require symfony/serializer".')); + throw new LogicException(sprintf('The default Messenger Serializer requires Symfony\'s Serializer component. Try running "composer require symfony/serializer".')); } $encoders = array(new XmlEncoder(), new JsonEncoder()); diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index a2933495253f4..f6443cf5b3dfd 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -140,7 +140,7 @@ class Process implements \IteratorAggregate public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) { if (!\function_exists('proc_open')) { - throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.'); + throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.'); } if (!\is_array($command)) { diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 12b4a673828a0..1ee155e7c3111 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -788,7 +788,7 @@ private function getPropertyPath($propertyPath): PropertyPath public static function createCache($namespace, $defaultLifetime, $version, LoggerInterface $logger = null) { if (!class_exists('Symfony\Component\Cache\Adapter\ApcuAdapter')) { - throw new \RuntimeException(sprintf('The Symfony Cache component must be installed to use %s().', __METHOD__)); + throw new \LogicException(sprintf('The Symfony Cache component must be installed to use %s().', __METHOD__)); } if (!ApcuAdapter::isSupported()) { diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index f6f3ba06d1bf2..cdb111bf02bf5 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -54,7 +54,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property public function __construct(DocBlockFactoryInterface $docBlockFactory = null, array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null) { if (!class_exists(DocBlockFactory::class)) { - throw new \RuntimeException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed.', __CLASS__)); + throw new \LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed.', __CLASS__)); } $this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance(); diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index ecd68e04f5269..b69fa99c4ae16 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -32,7 +32,7 @@ class AnnotationFileLoader extends FileLoader public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader) { if (!\function_exists('token_get_all')) { - throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.'); + throw new \LogicException('The Tokenizer extension is required for the routing annotation loaders.'); } parent::__construct($locator); diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 14e5cc341e807..1e939a8607d18 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -724,7 +724,7 @@ private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { - throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders); } diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 095e6dc2dee39..d900607ba787c 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -246,7 +246,7 @@ protected function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { - throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders); } diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index 77c98377ee70a..5de0687789360 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -15,7 +15,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; -use Symfony\Component\Serializer\Exception\RuntimeException; +use Symfony\Component\Serializer\Exception\LogicException; use Symfony\Component\Serializer\Mapping\AttributeMetadata; use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; @@ -33,7 +33,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null) { if (!\class_exists(PropertyAccess::class)) { - throw new RuntimeException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.'); + throw new LogicException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.'); } parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor, $classDiscriminatorResolver); diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 15bb8dda13cb8..d373368583dd0 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -15,7 +15,7 @@ use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Exception\RuntimeException; +use Symfony\Component\Validator\Exception\LogicException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -100,7 +100,7 @@ public function validate($value, Constraint $constraint) if (Email::VALIDATION_MODE_STRICT === $constraint->mode) { if (!class_exists('\Egulias\EmailValidator\EmailValidator')) { - throw new RuntimeException('Strict email validation requires egulias/email-validator ~1.2|~2.0'); + throw new LogicException('Strict email validation requires egulias/email-validator ~1.2|~2.0'); } $strictValidator = new \Egulias\EmailValidator\EmailValidator(); diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 5f40cfd3f60c2..b72a83365b7b7 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -14,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Exception\RuntimeException; +use Symfony\Component\Validator\Exception\LogicException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -55,7 +55,7 @@ private function getExpressionLanguage() { if (null === $this->expressionLanguage) { if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) { - throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); + throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); } $this->expressionLanguage = new ExpressionLanguage(); } diff --git a/src/Symfony/Component/Validator/Constraints/ImageValidator.php b/src/Symfony/Component/Validator/Constraints/ImageValidator.php index 4b6a6f3b20c6a..d41054c28bbfb 100644 --- a/src/Symfony/Component/Validator/Constraints/ImageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ImageValidator.php @@ -13,7 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; -use Symfony\Component\Validator\Exception\RuntimeException; +use Symfony\Component\Validator\Exception\LogicException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -218,7 +218,7 @@ public function validate($value, Constraint $constraint) if ($constraint->detectCorrupted) { if (!\function_exists('imagecreatefromstring')) { - throw new RuntimeException('Corrupted images detection requires installed and enabled GD extension'); + throw new LogicException('Corrupted images detection requires installed and enabled GD extension'); } $resource = @imagecreatefromstring(file_get_contents($value));