feature #28536 Favor LogicException for missing classes & functions (ro0NL)
This PR was merged into the 4.2-dev branch.
Discussion
----------
Favor LogicException for missing classes & functions
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes-ish
| BC breaks? | no-ish <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | https://github.com/symfony/symfony/pull/28513#issuecomment-423500822
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
- Bug fixes must be submitted against the lowest branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
-->
Commits
-------
c762735075
Favor LogicException for missing classes & functions
This commit is contained in:
commit
eb607ae4dc
@ -118,7 +118,7 @@ abstract class Client
|
||||
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;
|
||||
|
@ -47,7 +47,7 @@ class XmlUtils
|
||||
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);
|
||||
|
@ -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) {
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
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 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
{
|
||||
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();
|
||||
|
@ -1587,7 +1587,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -1692,7 +1692,7 @@ EOF;
|
||||
{
|
||||
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) {
|
||||
|
@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
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) {
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection;
|
||||
|
||||
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 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
||||
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);
|
||||
|
@ -1166,7 +1166,7 @@ class Crawler implements \Countable, \IteratorAggregate
|
||||
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);
|
||||
|
19
src/Symfony/Component/Messenger/Exception/LogicException.php
Normal file
19
src/Symfony/Component/Messenger/Exception/LogicException.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <franssen.roland@gmail.com>
|
||||
*/
|
||||
class LogicException extends \LogicException implements ExceptionInterface
|
||||
{
|
||||
}
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Messenger\Transport\Serialization;
|
||||
|
||||
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 @@ class Serializer implements SerializerInterface
|
||||
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());
|
||||
|
@ -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)) {
|
||||
|
@ -788,7 +788,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
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()) {
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -724,7 +724,7 @@ EOF;
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
|
||||
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);
|
||||
|
@ -15,7 +15,7 @@ use Egulias\EmailValidator\Validation\EmailValidation;
|
||||
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 @@ class EmailValidator extends ConstraintValidator
|
||||
|
||||
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();
|
||||
|
@ -14,7 +14,7 @@ namespace Symfony\Component\Validator\Constraints;
|
||||
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 @@ class ExpressionValidator extends ConstraintValidator
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
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 @@ class ImageValidator extends FileValidator
|
||||
|
||||
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));
|
||||
|
Reference in New Issue
Block a user