minor #35945 Leverage PHP8's get_debug_type() (nicolas-grekas)

This PR was merged into the 5.1-dev branch.

Discussion
----------

Leverage PHP8's get_debug_type()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

See https://github.com/symfony/polyfill/pull/226 for background.

We might have to port part of the patch to 4.4 when we'll work on having it support PHP 8, but that's not needed for now.

Commits
-------

daf1c6605e Leverage PHP8's get_debug_type()
This commit is contained in:
Nicolas Grekas 2020-03-16 18:33:00 +01:00
commit c650fe6dfc
266 changed files with 466 additions and 464 deletions

View File

@ -93,7 +93,7 @@ class IdReader
} }
if (!$this->om->contains($object)) { if (!$this->om->contains($object)) {
throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', \get_class($object))); throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_debug_type($object)));
} }
$this->om->initializeObject($object); $this->om->initializeObject($object);

View File

@ -53,7 +53,7 @@ class EntityType extends DoctrineType
public function getLoader(ObjectManager $manager, $queryBuilder, string $class) public function getLoader(ObjectManager $manager, $queryBuilder, string $class)
{ {
if (!$queryBuilder instanceof QueryBuilder) { if (!$queryBuilder instanceof QueryBuilder) {
throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder))); throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
} }
return new ORMQueryBuilderLoader($queryBuilder); return new ORMQueryBuilderLoader($queryBuilder);
@ -79,7 +79,7 @@ class EntityType extends DoctrineType
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
{ {
if (!$queryBuilder instanceof QueryBuilder) { if (!$queryBuilder instanceof QueryBuilder) {
throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder))); throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder)));
} }
return [ return [

View File

@ -55,7 +55,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
$user = $repository->findOneBy([$this->property => $username]); $user = $repository->findOneBy([$this->property => $username]);
} else { } else {
if (!$repository instanceof UserLoaderInterface) { if (!$repository instanceof UserLoaderInterface) {
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, \get_class($repository))); throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_debug_type($repository)));
} }
$user = $repository->loadUserByUsername($username); $user = $repository->loadUserByUsername($username);
@ -75,7 +75,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
{ {
$class = $this->getClass(); $class = $this->getClass();
if (!$user instanceof $class) { if (!$user instanceof $class) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
} }
$repository = $this->getRepository(); $repository = $this->getRepository();
@ -114,7 +114,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
{ {
$class = $this->getClass(); $class = $this->getClass();
if (!$user instanceof $class) { if (!$user instanceof $class) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
} }
$repository = $this->getRepository(); $repository = $this->getRepository();

View File

@ -50,7 +50,7 @@ class DoctrineFooType extends Type
return null; return null;
} }
if (!$value instanceof Foo) { if (!$value instanceof Foo) {
throw new ConversionException(sprintf('Expected "%s", got "%s"', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\Foo', \gettype($value))); throw new ConversionException(sprintf('Expected "%s", got "%s"', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\Foo', get_debug_type($value)));
} }
return $foo->bar; return $foo->bar;

View File

@ -71,7 +71,7 @@ class UniqueEntityValidator extends ConstraintValidator
$em = $this->registry->getManagerForClass(\get_class($entity)); $em = $this->registry->getManagerForClass(\get_class($entity));
if (!$em) { if (!$em) {
throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', \get_class($entity))); throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_debug_type($entity)));
} }
} }

View File

@ -21,6 +21,7 @@
"doctrine/persistence": "^1.3", "doctrine/persistence": "^1.3",
"symfony/polyfill-ctype": "~1.8", "symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1|^2" "symfony/service-contracts": "^1.1|^2"
}, },
"require-dev": { "require-dev": {

View File

@ -35,7 +35,7 @@ class TwigErrorRenderer implements ErrorRendererInterface
public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorRenderer = null, $debug = false) public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorRenderer = null, $debug = false)
{ {
if (!\is_bool($debug) && !\is_callable($debug)) { if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 3 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug))); throw new \TypeError(sprintf('Argument 3 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
} }
$this->twig = $twig; $this->twig = $twig;

View File

@ -47,7 +47,7 @@ final class BodyRenderer implements BodyRendererInterface
$messageContext = $message->getContext(); $messageContext = $message->getContext();
if (isset($messageContext['email'])) { if (isset($messageContext['email'])) {
throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', \get_class($message))); throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', get_debug_type($message)));
} }
$vars = array_merge($this->context, $messageContext, [ $vars = array_merge($this->context, $messageContext, [

View File

@ -17,6 +17,7 @@
], ],
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"symfony/polyfill-php80": "^1.15",
"symfony/translation-contracts": "^1.1|^2", "symfony/translation-contracts": "^1.1|^2",
"twig/twig": "^2.10|^3.0" "twig/twig": "^2.10|^3.0"
}, },

View File

@ -47,7 +47,7 @@ class RouterCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterf
return; return;
} }
throw new \LogicException(sprintf('The router "%s" cannot be warmed up because it does not implement "%s".', \get_class($router), WarmableInterface::class)); throw new \LogicException(sprintf('The router "%s" cannot be warmed up because it does not implement "%s".', get_debug_type($router), WarmableInterface::class));
} }
/** /**

View File

@ -116,7 +116,7 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
} }
if (!$configuration instanceof ConfigurationInterface) { if (!$configuration instanceof ConfigurationInterface) {
throw new \LogicException(sprintf('Configuration class "%s" should implement ConfigurationInterface in order to be dumpable.', \get_class($configuration))); throw new \LogicException(sprintf('Configuration class "%s" should implement ConfigurationInterface in order to be dumpable.', get_debug_type($configuration)));
} }
} }

View File

@ -89,7 +89,7 @@ final class ContainerLintCommand extends Command
if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) { if (!$kernel->isDebug() || !(new ConfigCache($kernelContainer->getParameter('debug.container.dump'), true))->isFresh()) {
if (!$kernel instanceof Kernel) { if (!$kernel instanceof Kernel) {
throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', \get_class($kernel), Kernel::class)); throw new RuntimeException(sprintf('This command does not support the application kernel: "%s" does not extend "%s".', get_debug_type($kernel), Kernel::class));
} }
$buildContainer = \Closure::bind(function (): ContainerBuilder { $buildContainer = \Closure::bind(function (): ContainerBuilder {
@ -102,7 +102,7 @@ final class ContainerLintCommand extends Command
$skippedIds = []; $skippedIds = [];
} else { } else {
if (!$kernelContainer instanceof Container) { if (!$kernelContainer instanceof Container) {
throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', \get_class($kernelContainer), Container::class)); throw new RuntimeException(sprintf('This command does not support the application container: "%s" does not extend "%s".', get_debug_type($kernelContainer), Container::class));
} }
(new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump')); (new XmlFileLoader($container = new ContainerBuilder($parameterBag = new EnvPlaceholderParameterBag()), new FileLocator()))->load($kernelContainer->getParameter('debug.container.dump'));

View File

@ -83,7 +83,7 @@ abstract class Descriptor implements DescriptorInterface
$this->describeCallable($object, $options); $this->describeCallable($object, $options);
break; break;
default: default:
throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', \get_class($object))); throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object)));
} }
} }

View File

@ -36,12 +36,12 @@
</service> </service>
<service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag"> <service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag">
<factory service="session" method="getFlashBag"/> <factory service="session" method="getFlashBag" />
</service> </service>
<service id="Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface" alias="session.flash_bag" /> <service id="Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface" alias="session.flash_bag" />
<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag"> <service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag">
<factory service="session" method="getAttributeBag"/> <factory service="session" method="getAttributeBag" />
</service> </service>
<service id="session.storage.mock_file" class="Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage"> <service id="session.storage.mock_file" class="Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage">

View File

@ -171,7 +171,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
return (string) $this->resolve($resolved); return (string) $this->resolve($resolved);
} }
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".', $match[1], $value, \gettype($resolved))); throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".', $match[1], $value, get_debug_type($resolved)));
}, $value); }, $value);
return str_replace('%%', '%', $escapedValue); return str_replace('%%', '%', $escapedValue);

View File

@ -34,7 +34,7 @@ class SodiumVault extends AbstractVault implements EnvVarLoaderInterface
public function __construct(string $secretsDir, $decryptionKey = null) public function __construct(string $secretsDir, $decryptionKey = null)
{ {
if (null !== $decryptionKey && !\is_string($decryptionKey) && !(\is_object($decryptionKey) && method_exists($decryptionKey, '__toString'))) { if (null !== $decryptionKey && !\is_string($decryptionKey) && !(\is_object($decryptionKey) && method_exists($decryptionKey, '__toString'))) {
throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, "%s" given.', \gettype($decryptionKey))); throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, "%s" given.', get_debug_type($decryptionKey)));
} }
$this->pathPrefix = rtrim(strtr($secretsDir, '/', \DIRECTORY_SEPARATOR), \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.basename($secretsDir).'.'; $this->pathPrefix = rtrim(strtr($secretsDir, '/', \DIRECTORY_SEPARATOR), \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.basename($secretsDir).'.';

View File

@ -20,7 +20,7 @@ session_setflash:
injected_flashbag_session_setflash: injected_flashbag_session_setflash:
path: injected_flashbag/session_setflash/{message} path: injected_flashbag/session_setflash/{message}
defaults: { _controller: TestBundle:InjectedFlashbagSession:setFlash} defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController::setFlashAction}
session_showflash: session_showflash:
path: /session_showflash path: /session_showflash

View File

@ -390,7 +390,7 @@ class RouterTest extends TestCase
public function testExceptionOnNonStringParameter() public function testExceptionOnNonStringParameter()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The container parameter "object", used in the route configuration value "/%object%", must be a string or numeric, but it is of type "object".'); $this->expectExceptionMessage('The container parameter "object", used in the route configuration value "/%object%", must be a string or numeric, but it is of type "stdClass".');
$routes = new RouteCollection(); $routes = new RouteCollection();
$routes->add('foo', new Route('/%object%')); $routes->add('foo', new Route('/%object%'));
@ -405,7 +405,7 @@ class RouterTest extends TestCase
public function testExceptionOnNonStringParameterWithSfContainer() public function testExceptionOnNonStringParameterWithSfContainer()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The container parameter "object", used in the route configuration value "/%object%", must be a string or numeric, but it is of type "object".'); $this->expectExceptionMessage('The container parameter "object", used in the route configuration value "/%object%", must be a string or numeric, but it is of type "stdClass".');
$routes = new RouteCollection(); $routes = new RouteCollection();
$routes->add('foo', new Route('/%object%')); $routes->add('foo', new Route('/%object%'));

View File

@ -25,6 +25,7 @@
"symfony/http-foundation": "^4.4|^5.0", "symfony/http-foundation": "^4.4|^5.0",
"symfony/http-kernel": "^5.0", "symfony/http-kernel": "^5.0",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/filesystem": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0",
"symfony/routing": "^5.1" "symfony/routing": "^5.1"

View File

@ -43,7 +43,7 @@ class ArrayUserProvider implements UserProviderInterface
public function refreshUser(UserInterface $user) public function refreshUser(UserInterface $user)
{ {
if (!$user instanceof UserInterface) { if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
} }
$storedUser = $this->getUser($user->getUsername()); $storedUser = $this->getUser($user->getUsername());

View File

@ -21,6 +21,7 @@
"symfony/config": "^4.4|^5.0", "symfony/config": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0",
"symfony/http-kernel": "^5.0", "symfony/http-kernel": "^5.0",
"symfony/polyfill-php80": "^1.15",
"symfony/security-core": "^4.4|^5.0", "symfony/security-core": "^4.4|^5.0",
"symfony/security-csrf": "^4.4|^5.0", "symfony/security-csrf": "^4.4|^5.0",
"symfony/security-guard": "^4.4|^5.0", "symfony/security-guard": "^4.4|^5.0",

View File

@ -164,7 +164,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
foreach (\is_array($e) ? $e : array_keys($values) as $id) { foreach (\is_array($e) ? $e : array_keys($values) as $id) {
$ok = false; $ok = false;
$v = $values[$id]; $v = $values[$id];
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = get_debug_type($v);
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.'); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]); CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
@ -187,7 +187,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
continue; continue;
} }
$ok = false; $ok = false;
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = get_debug_type($v);
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.'); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]); CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }

View File

@ -194,7 +194,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
foreach (\is_array($e) ? $e : array_keys($values) as $id) { foreach (\is_array($e) ? $e : array_keys($values) as $id) {
$ok = false; $ok = false;
$v = $values[$id]; $v = $values[$id];
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = get_debug_type($v);
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.'); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]); CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }
@ -218,7 +218,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
continue; continue;
} }
$ok = false; $ok = false;
$type = \is_object($v) ? \get_class($v) : \gettype($v); $type = get_debug_type($v);
$message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.'); $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]); CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null]);
} }

View File

@ -351,7 +351,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
try { try {
$serialized = serialize($value); $serialized = serialize($value);
} catch (\Exception $e) { } catch (\Exception $e) {
$type = \is_object($value) ? \get_class($value) : \gettype($value); $type = get_debug_type($value);
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage()); $message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]); CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);

View File

@ -49,7 +49,7 @@ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
foreach ($adapters as $adapter) { foreach ($adapters as $adapter) {
if (!$adapter instanceof CacheItemPoolInterface) { if (!$adapter instanceof CacheItemPoolInterface) {
throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', \get_class($adapter), CacheItemPoolInterface::class)); throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', get_debug_type($adapter), CacheItemPoolInterface::class));
} }
if ($adapter instanceof AdapterInterface) { if ($adapter instanceof AdapterInterface) {

View File

@ -62,7 +62,7 @@ class CouchbaseBucketAdapter extends AbstractAdapter
if (\is_string($servers)) { if (\is_string($servers)) {
$servers = [$servers]; $servers = [$servers];
} elseif (!\is_array($servers)) { } elseif (!\is_array($servers)) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be array or string, "%s" given.', __METHOD__, \gettype($servers))); throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be array or string, "%s" given.', __METHOD__, get_debug_type($servers)));
} }
if (!static::isSupported()) { if (!static::isSupported()) {

View File

@ -92,7 +92,7 @@ class MemcachedAdapter extends AbstractAdapter
if (\is_string($servers)) { if (\is_string($servers)) {
$servers = [$servers]; $servers = [$servers];
} elseif (!\is_array($servers)) { } elseif (!\is_array($servers)) {
throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, "%s" given.', \gettype($servers))); throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, "%s" given.', get_debug_type($servers)));
} }
if (!static::isSupported()) { if (!static::isSupported()) {
throw new CacheException('Memcached >= 2.2.0 is required.'); throw new CacheException('Memcached >= 2.2.0 is required.');
@ -313,7 +313,7 @@ class MemcachedAdapter extends AbstractAdapter
return $result; return $result;
} }
throw new CacheException(sprintf('MemcachedAdapter client error: %s.', strtolower($this->client->getResultMessage()))); throw new CacheException(sprintf('MemcachedAdapter client error: "%s".', strtolower($this->client->getResultMessage())));
} }
private function getClient(): \Memcached private function getClient(): \Memcached

View File

@ -82,7 +82,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
} elseif (\is_string($connOrDsn)) { } elseif (\is_string($connOrDsn)) {
$this->dsn = $connOrDsn; $this->dsn = $connOrDsn;
} else { } else {
throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, \is_object($connOrDsn) ? \get_class($connOrDsn) : \gettype($connOrDsn))); throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, get_debug_type($connOrDsn)));
} }
$this->table = isset($options['db_table']) ? $options['db_table'] : $this->table; $this->table = isset($options['db_table']) ? $options['db_table'] : $this->table;

View File

@ -119,7 +119,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
public function getItem($key) public function getItem($key)
{ {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
if (null === $this->values) { if (null === $this->values) {
$this->initialize(); $this->initialize();
@ -154,7 +154,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
{ {
foreach ($keys as $key) { foreach ($keys as $key) {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
} }
if (null === $this->values) { if (null === $this->values) {
@ -172,7 +172,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
public function hasItem($key) public function hasItem($key)
{ {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
if (null === $this->values) { if (null === $this->values) {
$this->initialize(); $this->initialize();
@ -189,7 +189,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
public function deleteItem($key) public function deleteItem($key)
{ {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
if (null === $this->values) { if (null === $this->values) {
$this->initialize(); $this->initialize();
@ -210,7 +210,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
foreach ($keys as $key) { foreach ($keys as $key) {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
if (isset($this->keys[$key])) { if (isset($this->keys[$key])) {
@ -336,7 +336,7 @@ EOF;
try { try {
$value = VarExporter::export($value, $isStaticValue); $value = VarExporter::export($value, $isStaticValue);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, \is_object($value) ? \get_class($value) : 'array'), 0, $e); throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, get_debug_type($value)), 0, $e);
} }
} elseif (\is_string($value)) { } elseif (\is_string($value)) {
// Wrap "N;" in a closure to not confuse it with an encoded `null` // Wrap "N;" in a closure to not confuse it with an encoded `null`
@ -345,7 +345,7 @@ EOF;
} }
$value = var_export($value, true); $value = var_export($value, true);
} elseif (!is_scalar($value)) { } elseif (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, \gettype($value))); throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, get_debug_type($value)));
} else { } else {
$value = var_export($value, true); $value = var_export($value, true);
} }

View File

@ -226,7 +226,7 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
try { try {
$value = VarExporter::export($value, $isStaticValue); $value = VarExporter::export($value, $isStaticValue);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, \is_object($value) ? \get_class($value) : 'array'), 0, $e); throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, get_debug_type($value)), 0, $e);
} }
} elseif (\is_string($value)) { } elseif (\is_string($value)) {
// Wrap "N;" in a closure to not confuse it with an encoded `null` // Wrap "N;" in a closure to not confuse it with an encoded `null`
@ -235,7 +235,7 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
} }
$value = var_export($value, true); $value = var_export($value, true);
} elseif (!is_scalar($value)) { } elseif (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, \gettype($value))); throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable "%s" value.', $key, get_debug_type($value)));
} else { } else {
$value = var_export($value, true); $value = var_export($value, true);
} }

View File

@ -72,7 +72,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null) public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{ {
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) { if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, \get_class($redisClient->getConnection()))); throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redisClient->getConnection())));
} }
if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) { if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) {

View File

@ -41,7 +41,7 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInt
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
{ {
if (!$this->pool instanceof CacheInterface) { if (!$this->pool instanceof CacheInterface) {
throw new \BadMethodCallException(sprintf('Cannot call "%s::get()": this class doesn\'t implement "%s".', \get_class($this->pool), CacheInterface::class)); throw new \BadMethodCallException(sprintf('Cannot call "%s::get()": this class doesn\'t implement "%s".', get_debug_type($this->pool), CacheInterface::class));
} }
$isHit = true; $isHit = true;
@ -54,7 +54,7 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInt
$event = $this->start(__FUNCTION__); $event = $this->start(__FUNCTION__);
try { try {
$value = $this->pool->get($key, $callback, $beta, $metadata); $value = $this->pool->get($key, $callback, $beta, $metadata);
$event->result[$key] = \is_object($value) ? \get_class($value) : \gettype($value); $event->result[$key] = get_debug_type($value);
} finally { } finally {
$event->end = microtime(true); $event->end = microtime(true);
} }

View File

@ -82,7 +82,7 @@ final class CacheItem implements ItemInterface
} elseif ($expiration instanceof \DateTimeInterface) { } elseif ($expiration instanceof \DateTimeInterface) {
$this->expiry = (float) $expiration->format('U.u'); $this->expiry = (float) $expiration->format('U.u');
} else { } else {
throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given.', \is_object($expiration) ? \get_class($expiration) : \gettype($expiration))); throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given.', get_debug_type($expiration)));
} }
return $this; return $this;
@ -102,7 +102,7 @@ final class CacheItem implements ItemInterface
} elseif (\is_int($time)) { } elseif (\is_int($time)) {
$this->expiry = $time + microtime(true); $this->expiry = $time + microtime(true);
} else { } else {
throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given.', \is_object($time) ? \get_class($time) : \gettype($time))); throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given.', get_debug_type($time)));
} }
return $this; return $this;
@ -121,7 +121,7 @@ final class CacheItem implements ItemInterface
} }
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (!\is_string($tag)) { if (!\is_string($tag)) {
throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given.', \is_object($tag) ? \get_class($tag) : \gettype($tag))); throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given.', get_debug_type($tag)));
} }
if (isset($this->newMetadata[self::METADATA_TAGS][$tag])) { if (isset($this->newMetadata[self::METADATA_TAGS][$tag])) {
continue; continue;
@ -156,7 +156,7 @@ final class CacheItem implements ItemInterface
public static function validateKey($key): string public static function validateKey($key): string
{ {
if (!\is_string($key)) { if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', \is_object($key) ? \get_class($key) : \gettype($key))); throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
} }
if ('' === $key) { if ('' === $key) {
throw new InvalidArgumentException('Cache key length must be greater than zero.'); throw new InvalidArgumentException('Cache key length must be greater than zero.');

View File

@ -144,7 +144,7 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf
if ($keys instanceof \Traversable) { if ($keys instanceof \Traversable) {
$keys = iterator_to_array($keys, false); $keys = iterator_to_array($keys, false);
} elseif (!\is_array($keys)) { } elseif (!\is_array($keys)) {
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given.', \is_object($keys) ? \get_class($keys) : \gettype($keys))); throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given.', get_debug_type($keys)));
} }
try { try {
@ -193,7 +193,7 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf
{ {
$valuesIsArray = \is_array($values); $valuesIsArray = \is_array($values);
if (!$valuesIsArray && !$values instanceof \Traversable) { if (!$valuesIsArray && !$values instanceof \Traversable) {
throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given.', \is_object($values) ? \get_class($values) : \gettype($values))); throw new InvalidArgumentException(sprintf('Cache values must be array or Traversable, "%s" given.', get_debug_type($values)));
} }
$items = []; $items = [];
@ -247,7 +247,7 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf
if ($keys instanceof \Traversable) { if ($keys instanceof \Traversable) {
$keys = iterator_to_array($keys, false); $keys = iterator_to_array($keys, false);
} elseif (!\is_array($keys)) { } elseif (!\is_array($keys)) {
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given.', \is_object($keys) ? \get_class($keys) : \gettype($keys))); throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given.', get_debug_type($keys)));
} }
try { try {

View File

@ -56,7 +56,7 @@ trait RedisTrait
} }
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) { if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient))); throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient)));
} }
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) { if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {

View File

@ -25,6 +25,7 @@
"psr/cache": "~1.0", "psr/cache": "~1.0",
"psr/log": "~1.0", "psr/log": "~1.0",
"symfony/cache-contracts": "^1.1.7|^2", "symfony/cache-contracts": "^1.1.7|^2",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1|^2", "symfony/service-contracts": "^1.1|^2",
"symfony/var-exporter": "^4.4|^5.0" "symfony/var-exporter": "^4.4|^5.0"
}, },

View File

@ -207,7 +207,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
protected function finalizeValue($value) protected function finalizeValue($value)
{ {
if (false === $value) { if (false === $value) {
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: "%s".', $this->getPath(), json_encode($value))); throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
} }
foreach ($this->children as $name => $child) { foreach ($this->children as $name => $child) {
@ -250,7 +250,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
protected function validateType($value) protected function validateType($value)
{ {
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) { if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected array, but got %s', $this->getPath(), \gettype($value))); $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) { if ($hint = $this->getInfo()) {
$ex->addHint($hint); $ex->addHint($hint);
} }

View File

@ -26,7 +26,7 @@ class BooleanNode extends ScalarNode
protected function validateType($value) protected function validateType($value)
{ {
if (!\is_bool($value)) { if (!\is_bool($value)) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected boolean, but got %s.', $this->getPath(), \gettype($value))); $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) { if ($hint = $this->getInfo()) {
$ex->addHint($hint); $ex->addHint($hint);
} }

View File

@ -31,7 +31,7 @@ class FloatNode extends NumericNode
} }
if (!\is_float($value)) { if (!\is_float($value)) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected float, but got %s.', $this->getPath(), \gettype($value))); $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "float", but got "%s".', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) { if ($hint = $this->getInfo()) {
$ex->addHint($hint); $ex->addHint($hint);
} }

View File

@ -26,7 +26,7 @@ class IntegerNode extends NumericNode
protected function validateType($value) protected function validateType($value)
{ {
if (!\is_int($value)) { if (!\is_int($value)) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected int, but got %s.', $this->getPath(), \gettype($value))); $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "int", but got "%s".', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) { if ($hint = $this->getInfo()) {
$ex->addHint($hint); $ex->addHint($hint);
} }

View File

@ -175,7 +175,7 @@ class PrototypedArrayNode extends ArrayNode
protected function finalizeValue($value) protected function finalizeValue($value)
{ {
if (false === $value) { if (false === $value) {
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: "%s".', $this->getPath(), json_encode($value))); throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
} }
foreach ($value as $k => $v) { foreach ($value as $k => $v) {

View File

@ -33,7 +33,7 @@ class ScalarNode extends VariableNode
protected function validateType($value) protected function validateType($value)
{ {
if (!is_scalar($value) && null !== $value) { if (!is_scalar($value) && null !== $value) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected scalar, but got %s.', $this->getPath(), \gettype($value))); $ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "scalar", but got "%s".', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) { if ($hint = $this->getInfo()) {
$ex->addHint($hint); $ex->addHint($hint);
} }

View File

@ -96,7 +96,7 @@ class ScalarNodeTest extends TestCase
$node = new ScalarNode('test'); $node = new ScalarNode('test');
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
$this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.'); $this->expectExceptionMessage('Invalid type for path "test". Expected "scalar", but got "array".');
$node->normalize([]); $node->normalize([]);
} }
@ -107,7 +107,7 @@ class ScalarNodeTest extends TestCase
$node->setInfo('"the test value"'); $node->setInfo('"the test value"');
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException'); $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
$this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\""); $this->expectExceptionMessage("Invalid type for path \"test\". Expected \"scalar\", but got \"array\".\nHint: \"the test value\"");
$node->normalize([]); $node->normalize([]);
} }

View File

@ -19,7 +19,8 @@
"php": "^7.2.5", "php": "^7.2.5",
"symfony/deprecation-contracts": "^2.1", "symfony/deprecation-contracts": "^2.1",
"symfony/filesystem": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0",
"symfony/polyfill-ctype": "~1.8" "symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.15"
}, },
"require-dev": { "require-dev": {
"symfony/event-dispatcher": "^4.4|^5.0", "symfony/event-dispatcher": "^4.4|^5.0",

View File

@ -467,7 +467,7 @@ class Application implements ResetInterface
$command->getDefinition(); $command->getDefinition();
if (!$command->getName()) { if (!$command->getName()) {
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command))); throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
} }
$this->commands[$command->getName()] = $command; $this->commands[$command->getName()] = $command;
@ -774,17 +774,16 @@ class Application implements ResetInterface
do { do {
$message = trim($e->getMessage()); $message = trim($e->getMessage());
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$class = \get_class($e); $class = get_debug_type($e);
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class))).'@anonymous' : $class;
$title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''); $title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
$len = Helper::strlen($title); $len = Helper::strlen($title);
} else { } else {
$len = 0; $len = 0;
} }
if (false !== strpos($message, "class@anonymous\0")) { if (false !== strpos($message, "@anonymous\0")) {
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) { $message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0]))).'@anonymous' : $m[0]; return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $message); }, $message);
} }

View File

@ -258,7 +258,7 @@ class Command
$statusCode = $this->execute($input, $output); $statusCode = $this->execute($input, $output);
if (!\is_int($statusCode)) { if (!\is_int($statusCode)) {
throw new \TypeError(sprintf('Return value of "%s::execute()" must be of the type int, "%s" returned.', static::class, \gettype($statusCode))); throw new \TypeError(sprintf('Return value of "%s::execute()" must be of the type int, "%s" returned.', static::class, get_debug_type($statusCode)));
} }
} }

View File

@ -55,7 +55,7 @@ abstract class Descriptor implements DescriptorInterface
$this->describeApplication($object, $options); $this->describeApplication($object, $options);
break; break;
default: default:
throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', \get_class($object))); throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object)));
} }
} }

View File

@ -47,7 +47,7 @@ class ProcessHelper extends Helper
} }
if (!\is_array($cmd)) { if (!\is_array($cmd)) {
throw new \TypeError(sprintf('The "command" argument of "%s()" must be an array or a "%s" instance, "%s" given.', __METHOD__, Process::class, \is_object($cmd) ? \get_class($cmd) : \gettype($cmd))); throw new \TypeError(sprintf('The "command" argument of "%s()" must be an array or a "%s" instance, "%s" given.', __METHOD__, Process::class, get_debug_type($cmd)));
} }
if (\is_string($cmd[0] ?? null)) { if (\is_string($cmd[0] ?? null)) {

View File

@ -218,7 +218,7 @@ class Table
public function setColumnMaxWidth(int $columnIndex, int $width): self public function setColumnMaxWidth(int $columnIndex, int $width): self
{ {
if (!$this->output->getFormatter() instanceof WrappableOutputFormatterInterface) { if (!$this->output->getFormatter() instanceof WrappableOutputFormatterInterface) {
throw new \LogicException(sprintf('Setting a maximum column width is only supported when using a "%s" formatter, got "%s".', WrappableOutputFormatterInterface::class, \get_class($this->output->getFormatter()))); throw new \LogicException(sprintf('Setting a maximum column width is only supported when using a "%s" formatter, got "%s".', WrappableOutputFormatterInterface::class, get_debug_type($this->output->getFormatter())));
} }
$this->columnMaxWidths[$columnIndex] = $width; $this->columnMaxWidths[$columnIndex] = $width;
@ -606,7 +606,7 @@ class Table
$unmergedRows = []; $unmergedRows = [];
foreach ($rows[$line] as $column => $cell) { foreach ($rows[$line] as $column => $cell) {
if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) { if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) {
throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing "__toString()", "%s" given.', \gettype($cell))); throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing "__toString()", "%s" given.', get_debug_type($cell)));
} }
if ($cell instanceof TableCell && $cell->getRowspan() > 1) { if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
$nbLines = $cell->getRowspan() - 1; $nbLines = $cell->getRowspan() - 1;

View File

@ -893,12 +893,12 @@ class ApplicationTest extends TestCase
$application = new Application(); $application = new Application();
$application->setAutoExit(false); $application->setAutoExit(false);
$application->register('foo')->setCode(function () { $application->register('foo')->setCode(function () {
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() { }))); throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', get_debug_type(new class() { })));
}); });
$tester = new ApplicationTester($application); $tester = new ApplicationTester($application);
$tester->run(['command' => 'foo'], ['decorated' => false]); $tester->run(['command' => 'foo'], ['decorated' => false]);
$this->assertStringContainsString('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true)); $this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
} }
public function testRenderExceptionStackTraceContainsRootException() public function testRenderExceptionStackTraceContainsRootException()
@ -916,12 +916,12 @@ class ApplicationTest extends TestCase
$application = new Application(); $application = new Application();
$application->setAutoExit(false); $application->setAutoExit(false);
$application->register('foo')->setCode(function () { $application->register('foo')->setCode(function () {
throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', \get_class(new class() { }))); throw new \InvalidArgumentException(sprintf('Dummy type "%s" is invalid.', get_debug_type(new class() { })));
}); });
$tester = new ApplicationTester($application); $tester = new ApplicationTester($application);
$tester->run(['command' => 'foo'], ['decorated' => false]); $tester->run(['command' => 'foo'], ['decorated' => false]);
$this->assertStringContainsString('Dummy type "@anonymous" is invalid.', $tester->getDisplay(true)); $this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
} }
public function testRun() public function testRun()

View File

@ -19,6 +19,7 @@
"php": "^7.2.5", "php": "^7.2.5",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.8", "symfony/polyfill-php73": "^1.8",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1|^2", "symfony/service-contracts": "^1.1|^2",
"symfony/string": "^5.1" "symfony/string": "^5.1"
}, },

View File

@ -45,7 +45,7 @@ trait ReferenceSetArgumentTrait
{ {
foreach ($values as $k => $v) { foreach ($values as $k => $v) {
if (null !== $v && !$v instanceof Reference) { if (null !== $v && !$v instanceof Reference) {
throw new InvalidArgumentException(sprintf('A "%s" must hold only Reference instances, "%s" given.', __CLASS__, \is_object($v) ? \get_class($v) : \gettype($v))); throw new InvalidArgumentException(sprintf('A "%s" must hold only Reference instances, "%s" given.', __CLASS__, get_debug_type($v)));
} }
} }

View File

@ -209,7 +209,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
$arg = $this->processValue(new Reference($id)); $arg = $this->processValue(new Reference($id));
$this->inExpression = false; $this->inExpression = false;
if (!$arg instanceof Reference) { if (!$arg instanceof Reference) {
throw new RuntimeException(sprintf('"%s::processValue()" must return a Reference when processing an expression, "%s" returned for service("%s").', static::class, \is_object($arg) ? \get_class($arg) : \gettype($arg), $id)); throw new RuntimeException(sprintf('"%s::processValue()" must return a Reference when processing an expression, "%s" returned for service("%s").', static::class, get_debug_type($arg), $id));
} }
$arg = sprintf('"%s"', $arg); $arg = sprintf('"%s"', $arg);
} }

View File

@ -265,7 +265,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
$checkFunction = sprintf('is_%s', $parameter->getType()->getName()); $checkFunction = sprintf('is_%s', $parameter->getType()->getName());
if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) { if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) {
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : \gettype($value), $parameter); throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter);
} }
} }

View File

@ -169,7 +169,7 @@ class MergeExtensionConfigurationContainerBuilder extends ContainerBuilder
*/ */
public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0): self public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0): self
{ {
throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', \get_class($pass), $this->extensionClass)); throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', get_debug_type($pass), $this->extensionClass));
} }
/** /**
@ -177,7 +177,7 @@ class MergeExtensionConfigurationContainerBuilder extends ContainerBuilder
*/ */
public function registerExtension(ExtensionInterface $extension) public function registerExtension(ExtensionInterface $extension)
{ {
throw new LogicException(sprintf('You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.', \get_class($extension), $this->extensionClass)); throw new LogicException(sprintf('You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.', get_debug_type($extension), $this->extensionClass));
} }
/** /**

View File

@ -125,7 +125,7 @@ class PriorityTaggedServiceUtil
$defaultIndex = $rm->invoke(null); $defaultIndex = $rm->invoke(null);
if (!\is_string($defaultIndex)) { if (!\is_string($defaultIndex)) {
throw new InvalidArgumentException(sprintf('Either method "%s::%s()" should return a string (got "%s") or tag "%s" on service "%s" is missing attribute "%s".', $class, $defaultIndexMethod, \gettype($defaultIndex), $tagName, $serviceId, $indexAttribute)); throw new InvalidArgumentException(sprintf('Either method "%s::%s()" should return a string (got "%s") or tag "%s" on service "%s" is missing attribute "%s".', $class, $defaultIndexMethod, get_debug_type($defaultIndex), $tagName, $serviceId, $indexAttribute));
} }
return $defaultIndex; return $defaultIndex;
@ -154,7 +154,7 @@ class PriorityTaggedServiceUtil
$defaultPriority = $rm->invoke(null); $defaultPriority = $rm->invoke(null);
if (!\is_int($defaultPriority)) { if (!\is_int($defaultPriority)) {
throw new InvalidArgumentException(sprintf('Method "%s::%s()" should return an integer (got "%s") or tag "%s" on service "%s" is missing attribute "priority".', $class, $defaultPriorityMethod, \gettype($defaultPriority), $tagName, $serviceId)); throw new InvalidArgumentException(sprintf('Method "%s::%s()" should return an integer (got "%s") or tag "%s" on service "%s" is missing attribute "priority".', $class, $defaultPriorityMethod, get_debug_type($defaultPriority), $tagName, $serviceId));
} }
return $defaultPriority; return $defaultPriority;

View File

@ -71,7 +71,7 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
foreach ($class::getSubscribedServices() as $key => $type) { foreach ($class::getSubscribedServices() as $key => $type) {
if (!\is_string($type) || !preg_match('/^\??[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $type)) { if (!\is_string($type) || !preg_match('/^\??[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $type)) {
throw new InvalidArgumentException(sprintf('"%s::getSubscribedServices()" must return valid PHP types for service "%s" key "%s", "%s" returned.', $class, $this->currentId, $key, \is_string($type) ? $type : \gettype($type))); throw new InvalidArgumentException(sprintf('"%s::getSubscribedServices()" must return valid PHP types for service "%s" key "%s", "%s" returned.', $class, $this->currentId, $key, \is_string($type) ? $type : get_debug_type($type)));
} }
if ($optionalBehavior = '?' === $type[0]) { if ($optionalBehavior = '?' === $type[0]) {
$type = substr($type, 1); $type = substr($type, 1);

View File

@ -134,7 +134,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
} }
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) { if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, "%s", "%s", "%s" or ServiceLocatorArgument, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue))); throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, "%s", "%s", "%s" or ServiceLocatorArgument, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, get_debug_type($bindingValue)));
} }
} }

View File

@ -76,7 +76,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
} }
if (null !== $argument && !$argument instanceof Reference && !$argument instanceof Definition) { if (null !== $argument && !$argument instanceof Reference && !$argument instanceof Definition) {
throw new InvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of "%s" or an instance of "%s", "%s" given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, \gettype($argument))); throw new InvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of "%s" or an instance of "%s", "%s" given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, get_debug_type($argument)));
} }
$typeFound = false; $typeFound = false;

View File

@ -59,7 +59,7 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
continue; continue;
} }
if (!$v instanceof Reference) { if (!$v instanceof Reference) {
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, \is_object($v) ? \get_class($v) : \gettype($v), $k)); throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set, "%s" found for key "%s".', $this->currentId, get_debug_type($v), $k));
} }
if ($i === $k) { if ($i === $k) {
@ -98,7 +98,7 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
{ {
foreach ($refMap as $id => $ref) { foreach ($refMap as $id => $ref) {
if (!$ref instanceof Reference) { if (!$ref instanceof Reference) {
throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', \is_object($ref) ? \get_class($ref) : \gettype($ref), $id)); throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', get_debug_type($ref), $id));
} }
$refMap[$id] = new ServiceClosureArgument($ref); $refMap[$id] = new ServiceClosureArgument($ref);
} }

View File

@ -52,7 +52,7 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
$values = []; $values = [];
if (false === $i = strpos($env, ':')) { if (false === $i = strpos($env, ':')) {
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string']; $default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
$defaultType = null !== $default ? self::getType($default) : 'string'; $defaultType = null !== $default ? get_debug_type($default) : 'string';
$values[$defaultType] = $default; $values[$defaultType] = $default;
} else { } else {
$prefix = substr($env, 0, $i); $prefix = substr($env, 0, $i);
@ -99,18 +99,4 @@ class ValidateEnvPlaceholdersPass implements CompilerPassInterface
$this->extensionConfig = []; $this->extensionConfig = [];
} }
} }
private static function getType($value): string
{
switch ($type = \gettype($value)) {
case 'boolean':
return 'bool';
case 'double':
return 'float';
case 'integer':
return 'int';
}
return $type;
}
} }

View File

@ -1131,7 +1131,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
} }
if (!\is_callable($callable)) { if (!\is_callable($callable)) {
throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', \get_class($service))); throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_debug_type($service)));
} }
$callable($service); $callable($service);
@ -1390,7 +1390,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$completed = true; $completed = true;
} else { } else {
if (!\is_string($resolved) && !is_numeric($resolved)) { if (!\is_string($resolved) && !is_numeric($resolved)) {
throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type "%s" inside string value "%s".', $env, \gettype($resolved), $this->resolveEnvPlaceholders($value))); throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type "%s" inside string value "%s".', $env, get_debug_type($resolved), $this->resolveEnvPlaceholders($value)));
} }
$value = str_ireplace($placeholder, $resolved, $value); $value = str_ireplace($placeholder, $resolved, $value);
} }

View File

@ -1490,7 +1490,7 @@ EOF;
if (\is_array($value)) { if (\is_array($value)) {
$value = $this->exportParameters($value, $path.'/'.$key, $indent + 4); $value = $this->exportParameters($value, $path.'/'.$key, $indent + 4);
} elseif ($value instanceof ArgumentInterface) { } elseif ($value instanceof ArgumentInterface) {
throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain special arguments. "%s" found in "%s".', \get_class($value), $path.'/'.$key)); throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain special arguments. "%s" found in "%s".', get_debug_type($value), $path.'/'.$key));
} elseif ($value instanceof Variable) { } elseif ($value instanceof Variable) {
throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain variable references. Variable "%s" found in "%s".', $value, $path.'/'.$key)); throw new InvalidArgumentException(sprintf('You cannot dump a container with parameters that contain variable references. Variable "%s" found in "%s".', $value, $path.'/'.$key));
} elseif ($value instanceof Definition) { } elseif ($value instanceof Definition) {

View File

@ -264,7 +264,7 @@ class YamlDumper extends Dumper
} elseif ($value instanceof ServiceLocatorArgument) { } elseif ($value instanceof ServiceLocatorArgument) {
$tag = 'service_locator'; $tag = 'service_locator';
} else { } else {
throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', \get_class($value))); throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', get_debug_type($value)));
} }
return new TaggedValue($tag, $this->dumpValue($value->getValues())); return new TaggedValue($tag, $this->dumpValue($value->getValues()));

View File

@ -79,7 +79,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
} }
if (!isset($array[$key]) && !\array_key_exists($key, $array)) { if (!isset($array[$key]) && !\array_key_exists($key, $array)) {
throw new EnvNotFoundException(sprintf('Key "%s" not found in "%s" (resolved from "%s").', $key, json_encode($array), $next)); throw new EnvNotFoundException(sprintf('Key "%s" not found in %s (resolved from "%s").', $key, json_encode($array), $next));
} }
return $array[$key]; return $array[$key];
@ -231,7 +231,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
} }
if (null !== $env && !\is_array($env)) { if (null !== $env && !\is_array($env)) {
throw new RuntimeException(sprintf('Invalid JSON env var "%s": array or null expected, "%s" given.', $name, \gettype($env))); throw new RuntimeException(sprintf('Invalid JSON env var "%s": array or null expected, "%s" given.', $name, get_debug_type($env)));
} }
return $env; return $env;
@ -275,7 +275,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
} }
$value = $this->container->getParameter($match[1]); $value = $this->container->getParameter($match[1]);
if (!is_scalar($value)) { if (!is_scalar($value)) {
throw new RuntimeException(sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, \gettype($value))); throw new RuntimeException(sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, get_debug_type($value)));
} }
return $value; return $value;

View File

@ -91,6 +91,6 @@ abstract class AbstractConfigurator
} }
} }
throw new InvalidArgumentException(sprintf('Cannot use values of type "%s" in service configuration files.', \is_object($value) ? \get_class($value) : \gettype($value))); throw new InvalidArgumentException(sprintf('Cannot use values of type "%s" in service configuration files.', get_debug_type($value)));
} }
} }

View File

@ -57,7 +57,7 @@ abstract class FileLoader extends BaseFileLoader
if ($ignoreNotFound = 'not_found' === $ignoreErrors) { if ($ignoreNotFound = 'not_found' === $ignoreErrors) {
$args[2] = false; $args[2] = false;
} elseif (!\is_bool($ignoreErrors)) { } elseif (!\is_bool($ignoreErrors)) {
throw new \TypeError(sprintf('Invalid argument $ignoreErrors provided to "%s::import()": boolean or "not_found" expected, "%s" given.', static::class, \gettype($ignoreErrors))); throw new \TypeError(sprintf('Invalid argument $ignoreErrors provided to "%s::import()": boolean or "not_found" expected, "%s" given.', static::class, get_debug_type($ignoreErrors)));
} }
try { try {
@ -143,7 +143,7 @@ abstract class FileLoader extends BaseFileLoader
if ($this->isLoadingInstanceof) { if ($this->isLoadingInstanceof) {
if (!$definition instanceof ChildDefinition) { if (!$definition instanceof ChildDefinition) {
throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, \get_class($definition))); throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, get_debug_type($definition)));
} }
$this->instanceof[$id] = $definition; $this->instanceof[$id] = $definition;
} else { } else {

View File

@ -596,7 +596,7 @@ class XmlFileLoader extends FileLoader
$path = str_replace([$ns, str_replace('http://', 'https://', $ns)], str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]); $path = str_replace([$ns, str_replace('http://', 'https://', $ns)], str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]);
if (!is_file($path)) { if (!is_file($path)) {
throw new RuntimeException(sprintf('Extension "%s" references a non-existent XSD file "%s".', \get_class($extension), $path)); throw new RuntimeException(sprintf('Extension "%s" references a non-existent XSD file "%s".', get_debug_type($extension), $path));
} }
$schemaLocations[$items[$i]] = $path; $schemaLocations[$items[$i]] = $path;

View File

@ -213,7 +213,7 @@ class YamlFileLoader extends FileLoader
unset($content['services']['_instanceof']); unset($content['services']['_instanceof']);
if (!\is_array($instanceof)) { if (!\is_array($instanceof)) {
throw new InvalidArgumentException(sprintf('Service "_instanceof" key must be an array, "%s" given in "%s".', \gettype($instanceof), $file)); throw new InvalidArgumentException(sprintf('Service "_instanceof" key must be an array, "%s" given in "%s".', get_debug_type($instanceof), $file));
} }
$this->instanceof = []; $this->instanceof = [];
$this->isLoadingInstanceof = true; $this->isLoadingInstanceof = true;
@ -247,7 +247,7 @@ class YamlFileLoader extends FileLoader
unset($content['services']['_defaults']); unset($content['services']['_defaults']);
if (!\is_array($defaults)) { if (!\is_array($defaults)) {
throw new InvalidArgumentException(sprintf('Service "_defaults" key must be an array, "%s" given in "%s".', \gettype($defaults), $file)); throw new InvalidArgumentException(sprintf('Service "_defaults" key must be an array, "%s" given in "%s".', get_debug_type($defaults), $file));
} }
foreach ($defaults as $key => $default) { foreach ($defaults as $key => $default) {
@ -339,7 +339,7 @@ class YamlFileLoader extends FileLoader
} }
if (!\is_array($service)) { if (!\is_array($service)) {
throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but "%s" found for service "%s" in "%s". Check your YAML syntax.', \gettype($service), $id, $file)); throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but "%s" found for service "%s" in "%s". Check your YAML syntax.', get_debug_type($service), $id, $file));
} }
$this->checkDefinition($id, $service, $file); $this->checkDefinition($id, $service, $file);
@ -465,7 +465,7 @@ class YamlFileLoader extends FileLoader
foreach ($service['calls'] as $k => $call) { foreach ($service['calls'] as $k => $call) {
if (!\is_array($call) && (!\is_string($k) || !$call instanceof TaggedValue)) { if (!\is_array($call) && (!\is_string($k) || !$call instanceof TaggedValue)) {
throw new InvalidArgumentException(sprintf('Invalid method call for service "%s": expected map or array, "%s" given in "%s".', $id, $call instanceof TaggedValue ? '!'.$call->getTag() : \gettype($call), $file)); throw new InvalidArgumentException(sprintf('Invalid method call for service "%s": expected map or array, "%s" given in "%s".', $id, $call instanceof TaggedValue ? '!'.$call->getTag() : get_debug_type($call), $file));
} }
if (\is_string($k)) { if (\is_string($k)) {

View File

@ -48,7 +48,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
} }
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) { if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', \gettype($defaultValue), $name)); throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', get_debug_type($defaultValue), $name));
} }
$uniqueName = md5($name.'_'.self::$counter++); $uniqueName = md5($name.'_'.self::$counter++);
@ -147,7 +147,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
foreach ($this->envPlaceholders as $env => $placeholders) { foreach ($this->envPlaceholders as $env => $placeholders) {
if ($this->has($name = "env($env)") && null !== ($default = $this->parameters[$name]) && !\is_string($default)) { if ($this->has($name = "env($env)") && null !== ($default = $this->parameters[$name]) && !\is_string($default)) {
throw new RuntimeException(sprintf('The default value of env parameter "%s" must be a string or null, "%s" given.', $env, \gettype($default))); throw new RuntimeException(sprintf('The default value of env parameter "%s" must be a string or null, "%s" given.', $env, get_debug_type($default)));
} }
} }
} }

View File

@ -227,7 +227,7 @@ class ParameterBag implements ParameterBagInterface
$resolved = $this->get($key); $resolved = $this->get($key);
if (!\is_string($resolved) && !is_numeric($resolved)) { if (!\is_string($resolved) && !is_numeric($resolved)) {
throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type "%s" inside string value "%s".', $key, \gettype($resolved), $value)); throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type "%s" inside string value "%s".', $key, get_debug_type($resolved), $value));
} }
$resolved = (string) $resolved; $resolved = (string) $resolved;

View File

@ -67,7 +67,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
public function testProcessFailsWhenPassingNullToRequiredArgument() public function testProcessFailsWhenPassingNullToRequiredArgument()
{ {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "NULL" passed.'); $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "null" passed.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -245,7 +245,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
public function testProcessSuccessWhenPassingNullToOptionalThatDoesNotAcceptNull() public function testProcessSuccessWhenPassingNullToOptionalThatDoesNotAcceptNull()
{ {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgumentNotNull::__construct" accepts "int", "NULL" passed.'); $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgumentNotNull::__construct" accepts "int", "null" passed.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -288,7 +288,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
public function testProcessFailsOnPassingScalarTypeToConstructorTypedWithClass() public function testProcessFailsOnPassingScalarTypeToConstructorTypedWithClass()
{ {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "integer" passed.'); $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "int" passed.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -376,7 +376,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
public function testProcessSuccessWhenPassingIntegerToArrayTypedParameter() public function testProcessSuccessWhenPassingIntegerToArrayTypedParameter()
{ {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException::class); $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException::class);
$this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "integer" passed.'); $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "int" passed.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
@ -564,7 +564,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
public function testProcessThrowsOnIterableTypeWhenScalarPassed() public function testProcessThrowsOnIterableTypeWhenScalarPassed()
{ {
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "bar_call": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setIterable" accepts "iterable", "integer" passed.'); $this->expectExceptionMessage('Invalid definition for service "bar_call": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setIterable" accepts "iterable", "int" passed.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();

View File

@ -386,7 +386,7 @@ class IntegrationTest extends TestCase
/** @var ServiceLocator $serviceLocator */ /** @var ServiceLocator $serviceLocator */
$serviceLocator = $s->getParam(); $serviceLocator = $s->getParam();
$this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', \is_object($serviceLocator) ? \get_class($serviceLocator) : \gettype($serviceLocator))); $this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', get_debug_type($serviceLocator)));
$same = [ $same = [
'bar' => $serviceLocator->get('bar'), 'bar' => $serviceLocator->get('bar'),
@ -419,7 +419,7 @@ class IntegrationTest extends TestCase
/** @var ServiceLocator $serviceLocator */ /** @var ServiceLocator $serviceLocator */
$serviceLocator = $s->getParam(); $serviceLocator = $s->getParam();
$this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', \is_object($serviceLocator) ? \get_class($serviceLocator) : \gettype($serviceLocator))); $this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', get_debug_type($serviceLocator)));
$same = [ $same = [
'bar' => $serviceLocator->get('bar'), 'bar' => $serviceLocator->get('bar'),
@ -451,7 +451,7 @@ class IntegrationTest extends TestCase
/** @var ServiceLocator $serviceLocator */ /** @var ServiceLocator $serviceLocator */
$serviceLocator = $s->getParam(); $serviceLocator = $s->getParam();
$this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', \is_object($serviceLocator) ? \get_class($serviceLocator) : \gettype($serviceLocator))); $this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', get_debug_type($serviceLocator)));
$same = [ $same = [
'bar_tab_class_with_defaultmethod' => $serviceLocator->get('bar_tab_class_with_defaultmethod'), 'bar_tab_class_with_defaultmethod' => $serviceLocator->get('bar_tab_class_with_defaultmethod'),
@ -478,7 +478,7 @@ class IntegrationTest extends TestCase
/** @var ServiceLocator $serviceLocator */ /** @var ServiceLocator $serviceLocator */
$serviceLocator = $s->getParam(); $serviceLocator = $s->getParam();
$this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', \is_object($serviceLocator) ? \get_class($serviceLocator) : \gettype($serviceLocator))); $this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', get_debug_type($serviceLocator)));
$expected = [ $expected = [
'bar_tag' => $container->get('bar_tag'), 'bar_tag' => $container->get('bar_tag'),
@ -504,7 +504,7 @@ class IntegrationTest extends TestCase
/** @var ServiceLocator $serviceLocator */ /** @var ServiceLocator $serviceLocator */
$serviceLocator = $s->getParam(); $serviceLocator = $s->getParam();
$this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', \is_object($serviceLocator) ? \get_class($serviceLocator) : \gettype($serviceLocator))); $this->assertTrue($s->getParam() instanceof ServiceLocator, sprintf('Wrong instance, should be an instance of ServiceLocator, %s given', get_debug_type($serviceLocator)));
$expected = [ $expected = [
'baz' => $container->get('bar_tag'), 'baz' => $container->get('bar_tag'),

View File

@ -58,7 +58,7 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
public function testDefaultEnvWithoutPrefixIsValidatedInConfig() public function testDefaultEnvWithoutPrefixIsValidatedInConfig()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "double" given to "env(FLOATISH)".'); $this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "float" given to "env(FLOATISH)".');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->setParameter('env(FLOATISH)', 3.2); $container->setParameter('env(FLOATISH)', 3.2);

View File

@ -707,7 +707,7 @@ class YamlFileLoaderTest extends TestCase
public function testEmptyDefaultsThrowsClearException() public function testEmptyDefaultsThrowsClearException()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./'); $this->expectExceptionMessageRegExp('/Service "_defaults" key must be an array, "null" given in ".+bad_empty_defaults\.yml"\./');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_defaults.yml'); $loader->load('bad_empty_defaults.yml');
@ -716,7 +716,7 @@ class YamlFileLoaderTest extends TestCase
public function testEmptyInstanceofThrowsClearException() public function testEmptyInstanceofThrowsClearException()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./'); $this->expectExceptionMessageRegExp('/Service "_instanceof" key must be an array, "null" given in ".+bad_empty_instanceof\.yml"\./');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_instanceof.yml'); $loader->load('bad_empty_instanceof.yml');

View File

@ -112,7 +112,7 @@ class EnvPlaceholderParameterBagTest extends TestCase
public function testResolveEnvRequiresStrings() public function testResolveEnvRequiresStrings()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The default value of env parameter "INT_VAR" must be a string or null, "integer" given.'); $this->expectExceptionMessage('The default value of env parameter "INT_VAR" must be a string or null, "int" given.');
$bag = new EnvPlaceholderParameterBag(); $bag = new EnvPlaceholderParameterBag();
$bag->get('env(INT_VAR)'); $bag->get('env(INT_VAR)');
@ -123,7 +123,7 @@ class EnvPlaceholderParameterBagTest extends TestCase
public function testGetDefaultScalarEnv() public function testGetDefaultScalarEnv()
{ {
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "integer" given to "env(INT_VAR)".'); $this->expectExceptionMessage('The default value of an env() parameter must be a string or null, but "int" given to "env(INT_VAR)".');
$bag = new EnvPlaceholderParameterBag(); $bag = new EnvPlaceholderParameterBag();
$bag->set('env(INT_VAR)', 2); $bag->set('env(INT_VAR)', 2);

View File

@ -19,11 +19,12 @@
"php": "^7.2.5", "php": "^7.2.5",
"psr/container": "^1.0", "psr/container": "^1.0",
"symfony/deprecation-contracts": "^2.1", "symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1.6|^2" "symfony/service-contracts": "^1.1.6|^2"
}, },
"require-dev": { "require-dev": {
"symfony/yaml": "^4.4|^5.0", "symfony/yaml": "^4.4|^5.0",
"symfony/config": "^5.0", "symfony/config": "^5.1",
"symfony/expression-language": "^4.4|^5.0" "symfony/expression-language": "^4.4|^5.0"
}, },
"suggest": { "suggest": {
@ -34,7 +35,7 @@
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them" "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
}, },
"conflict": { "conflict": {
"symfony/config": "<5.0", "symfony/config": "<5.1",
"symfony/finder": "<4.4", "symfony/finder": "<4.4",
"symfony/proxy-manager-bridge": "<4.4", "symfony/proxy-manager-bridge": "<4.4",
"symfony/yaml": "<4.4" "symfony/yaml": "<4.4"

View File

@ -122,7 +122,7 @@ class Crawler implements \Countable, \IteratorAggregate
} elseif (\is_string($node)) { } elseif (\is_string($node)) {
$this->addContent($node); $this->addContent($node);
} elseif (null !== $node) { } elseif (null !== $node) {
throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', \is_object($node) ? \get_class($node) : \gettype($node))); throw new \InvalidArgumentException(sprintf('Expecting a DOMNodeList or DOMNode instance, an array, a string, or null, but got "%s".', get_debug_type($node)));
} }
} }
@ -802,7 +802,7 @@ class Crawler implements \Countable, \IteratorAggregate
$node = $this->getNode(0); $node = $this->getNode(0);
if (!$node instanceof \DOMElement) { if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node))); throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
} }
return new Link($node, $this->baseHref, $method); return new Link($node, $this->baseHref, $method);
@ -820,7 +820,7 @@ class Crawler implements \Countable, \IteratorAggregate
$links = []; $links = [];
foreach ($this->nodes as $node) { foreach ($this->nodes as $node) {
if (!$node instanceof \DOMElement) { if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', \get_class($node))); throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
} }
$links[] = new Link($node, $this->baseHref, 'get'); $links[] = new Link($node, $this->baseHref, 'get');
@ -845,7 +845,7 @@ class Crawler implements \Countable, \IteratorAggregate
$node = $this->getNode(0); $node = $this->getNode(0);
if (!$node instanceof \DOMElement) { if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node))); throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
} }
return new Image($node, $this->baseHref); return new Image($node, $this->baseHref);
@ -861,7 +861,7 @@ class Crawler implements \Countable, \IteratorAggregate
$images = []; $images = [];
foreach ($this as $node) { foreach ($this as $node) {
if (!$node instanceof \DOMElement) { if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', \get_class($node))); throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_debug_type($node)));
} }
$images[] = new Image($node, $this->baseHref); $images[] = new Image($node, $this->baseHref);
@ -886,7 +886,7 @@ class Crawler implements \Countable, \IteratorAggregate
$node = $this->getNode(0); $node = $this->getNode(0);
if (!$node instanceof \DOMElement) { if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', \get_class($node))); throw new \InvalidArgumentException(sprintf('The selected node should be instance of DOMElement, got "%s".', get_debug_type($node)));
} }
$form = new Form($node, $this->uri, $method, $this->baseHref); $form = new Form($node, $this->uri, $method, $this->baseHref);

View File

@ -18,7 +18,8 @@
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"symfony/polyfill-ctype": "~1.8", "symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0" "symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15"
}, },
"require-dev": { "require-dev": {
"symfony/css-selector": "^4.4|^5.0", "symfony/css-selector": "^4.4|^5.0",

View File

@ -406,7 +406,7 @@ class DebugClassLoader
} }
$deprecations = []; $deprecations = [];
$className = isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00") ? (get_parent_class($class) ?: key(class_implements($class))).'@anonymous' : $class; $className = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
// Don't trigger deprecations for classes in the same vendor // Don't trigger deprecations for classes in the same vendor
if ($class !== $className) { if ($class !== $className) {

View File

@ -435,7 +435,7 @@ class ErrorHandler
$context = $e; $context = $e;
} }
if (false !== strpos($message, "class@anonymous\0")) { if (false !== strpos($message, "@anonymous\0")) {
$logMessage = $this->parseAnonymousClass($message); $logMessage = $this->parseAnonymousClass($message);
} else { } else {
$logMessage = $this->levels[$type].': '.$message; $logMessage = $this->levels[$type].': '.$message;
@ -558,7 +558,7 @@ class ErrorHandler
} }
if ($this->loggedErrors & $type) { if ($this->loggedErrors & $type) {
if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) { if (false !== strpos($message = $exception->getMessage(), "@anonymous\0")) {
$message = $this->parseAnonymousClass($message); $message = $this->parseAnonymousClass($message);
} }
@ -768,8 +768,8 @@ class ErrorHandler
*/ */
private function parseAnonymousClass(string $message): string private function parseAnonymousClass(string $message): string
{ {
return preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', static function ($m) { return preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', static function ($m) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0]))).'@anonymous' : $m[0]; return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $message); }, $message);
} }
} }

View File

@ -46,11 +46,11 @@ class HtmlErrorRenderer implements ErrorRendererInterface
public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null) public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null)
{ {
if (!\is_bool($debug) && !\is_callable($debug)) { if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug))); throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
} }
if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) { if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) {
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \is_object($outputBuffer) ? \get_class($outputBuffer) : \gettype($outputBuffer))); throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($outputBuffer)));
} }
$this->debug = $debug; $this->debug = $debug;

View File

@ -35,11 +35,11 @@ class SerializerErrorRenderer implements ErrorRendererInterface
public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false) public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
{ {
if (!\is_string($format) && !\is_callable($format)) { if (!\is_string($format) && !\is_callable($format)) {
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \is_object($format) ? \get_class($format) : \gettype($format))); throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($format)));
} }
if (!\is_bool($debug) && !\is_callable($debug)) { if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \is_object($debug) ? \get_class($debug) : \gettype($debug))); throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
} }
$this->serializer = $serializer; $this->serializer = $serializer;

View File

@ -142,7 +142,7 @@ class FlattenException
*/ */
public function setClass($class): self public function setClass($class): self
{ {
$this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class))).'@anonymous' : $class; $this->class = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
return $this; return $this;
} }
@ -199,9 +199,9 @@ class FlattenException
*/ */
public function setMessage($message): self public function setMessage($message): self
{ {
if (false !== strpos($message, "class@anonymous\0")) { if (false !== strpos($message, "@anonymous\0")) {
$message = preg_replace_callback('/class@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) { $message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0]))).'@anonymous' : $m[0]; return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $message); }, $message);
} }

View File

@ -18,6 +18,7 @@
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"psr/log": "^1.0", "psr/log": "^1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/var-dumper": "^4.4|^5.0" "symfony/var-dumper": "^4.4|^5.0"
}, },
"require-dev": { "require-dev": {

View File

@ -43,7 +43,7 @@ final class WrappedListener
$this->stoppedPropagation = false; $this->stoppedPropagation = false;
if (\is_array($listener)) { if (\is_array($listener)) {
$this->name = \is_object($listener[0]) ? \get_class($listener[0]) : $listener[0]; $this->name = \is_object($listener[0]) ? get_debug_type($listener[0]) : $listener[0];
$this->pretty = $this->name.'::'.$listener[1]; $this->pretty = $this->name.'::'.$listener[1];
} elseif ($listener instanceof \Closure) { } elseif ($listener instanceof \Closure) {
$r = new \ReflectionFunction($listener); $r = new \ReflectionFunction($listener);
@ -58,7 +58,7 @@ final class WrappedListener
} elseif (\is_string($listener)) { } elseif (\is_string($listener)) {
$this->pretty = $this->name = $listener; $this->pretty = $this->name = $listener;
} else { } else {
$this->name = \get_class($listener); $this->name = get_debug_type($listener);
$this->pretty = $this->name.'::__invoke'; $this->pretty = $this->name.'::__invoke';
} }

View File

@ -18,7 +18,8 @@
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"symfony/deprecation-contracts": "^2.1", "symfony/deprecation-contracts": "^2.1",
"symfony/event-dispatcher-contracts": "^2" "symfony/event-dispatcher-contracts": "^2",
"symfony/polyfill-php80": "^1.15"
}, },
"require-dev": { "require-dev": {
"symfony/dependency-injection": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0",

View File

@ -83,7 +83,7 @@ class GetAttrNode extends Node
throw new \RuntimeException('Unable to call method of a non-object.'); throw new \RuntimeException('Unable to call method of a non-object.');
} }
if (!\is_callable($toCall = [$obj, $this->nodes['attribute']->attributes['value']])) { if (!\is_callable($toCall = [$obj, $this->nodes['attribute']->attributes['value']])) {
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], \get_class($obj))); throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_debug_type($obj)));
} }
return $toCall(...array_values($this->nodes['arguments']->evaluate($functions, $values))); return $toCall(...array_values($this->nodes['arguments']->evaluate($functions, $values)));

View File

@ -18,6 +18,7 @@
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"symfony/cache": "^4.4|^5.0", "symfony/cache": "^4.4|^5.0",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1|^2" "symfony/service-contracts": "^1.1|^2"
}, },
"autoload": { "autoload": {

View File

@ -41,7 +41,7 @@ abstract class AbstractStaticOption
final public function __construct($formType, $option, $vary = null) final public function __construct($formType, $option, $vary = null)
{ {
if (!$formType instanceof FormTypeInterface && !$formType instanceof FormTypeExtensionInterface) { if (!$formType instanceof FormTypeInterface && !$formType instanceof FormTypeExtensionInterface) {
throw new \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class, \is_object($formType) ? \get_class($formType) : \gettype($formType))); throw new \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class, get_debug_type($formType)));
} }
$hash = CachingFactoryDecorator::generateHash([static::class, $formType, $vary]); $hash = CachingFactoryDecorator::generateHash([static::class, $formType, $vary]);

View File

@ -58,7 +58,7 @@ abstract class Descriptor implements DescriptorInterface
$this->describeOption($object, $options); $this->describeOption($object, $options);
break; break;
default: default:
throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', \get_class($object))); throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object)));
} }
} }

View File

@ -15,6 +15,6 @@ class UnexpectedTypeException extends InvalidArgumentException
{ {
public function __construct($value, string $expectedType) public function __construct($value, string $expectedType)
{ {
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, \is_object($value) ? \get_class($value) : \gettype($value))); parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, get_debug_type($value)));
} }
} }

View File

@ -38,7 +38,7 @@ class WeekToArrayTransformer implements DataTransformerInterface
} }
if (!\is_string($value)) { if (!\is_string($value)) {
throw new TransformationFailedException(sprintf('Value is expected to be a string but was "%s".', \is_object($value) ? \get_class($value) : \gettype($value))); throw new TransformationFailedException(sprintf('Value is expected to be a string but was "%s".', get_debug_type($value)));
} }
if (0 === preg_match('/^(?P<year>\d{4})-W(?P<week>\d{2})$/', $value, $matches)) { if (0 === preg_match('/^(?P<year>\d{4})-W(?P<week>\d{2})$/', $value, $matches)) {
@ -68,7 +68,7 @@ class WeekToArrayTransformer implements DataTransformerInterface
} }
if (!\is_array($value)) { if (!\is_array($value)) {
throw new TransformationFailedException(sprintf('Value is expected to be an array, but was "%s".', \is_object($value) ? \get_class($value) : \gettype($value))); throw new TransformationFailedException(sprintf('Value is expected to be an array, but was "%s".', get_debug_type($value)));
} }
if (!\array_key_exists('year', $value)) { if (!\array_key_exists('year', $value)) {
@ -88,11 +88,11 @@ class WeekToArrayTransformer implements DataTransformerInterface
} }
if (!\is_int($value['year'])) { if (!\is_int($value['year'])) {
throw new TransformationFailedException(sprintf('Year is expected to be an integer, but was "%s".', \is_object($value['year']) ? \get_class($value['year']) : \gettype($value['year']))); throw new TransformationFailedException(sprintf('Year is expected to be an integer, but was "%s".', get_debug_type($value['year'])));
} }
if (!\is_int($value['week'])) { if (!\is_int($value['week'])) {
throw new TransformationFailedException(sprintf('Week is expected to be an integer, but was "%s".', \is_object($value['week']) ? \get_class($value['week']) : \gettype($value['week']))); throw new TransformationFailedException(sprintf('Week is expected to be an integer, but was "%s".', get_debug_type($value['week'])));
} }
// The 28th December is always in the last week of the year // The 28th December is always in the last week of the year

View File

@ -50,7 +50,7 @@ class TransformationFailureListener implements EventSubscriberInterface
} }
} }
$clientDataAsString = is_scalar($form->getViewData()) ? (string) $form->getViewData() : \gettype($form->getViewData()); $clientDataAsString = is_scalar($form->getViewData()) ? (string) $form->getViewData() : get_debug_type($form->getViewData());
$messageTemplate = 'The value {{ value }} is not valid.'; $messageTemplate = 'The value {{ value }} is not valid.';
if (null !== $this->translator) { if (null !== $this->translator) {

View File

@ -61,7 +61,7 @@ class FormType extends BaseType
} }
if (!method_exists($builder, 'setIsEmptyCallback')) { if (!method_exists($builder, 'setIsEmptyCallback')) {
trigger_deprecation('symfony/form', '5.1', 'Not implementing the "%s::setIsEmptyCallback()" method in "%s" is deprecated.', FormConfigBuilderInterface::class, \get_class($builder)); trigger_deprecation('symfony/form', '5.1', 'Not implementing the "%s::setIsEmptyCallback()" method in "%s" is deprecated.', FormConfigBuilderInterface::class, get_debug_type($builder));
return; return;
} }

View File

@ -125,7 +125,7 @@ class FormValidator extends ConstraintValidator
if ($childrenSynchronized) { if ($childrenSynchronized) {
$clientDataAsString = is_scalar($form->getViewData()) $clientDataAsString = is_scalar($form->getViewData())
? (string) $form->getViewData() ? (string) $form->getViewData()
: \gettype($form->getViewData()); : get_debug_type($form->getViewData());
$failure = $form->getTransformationFailure(); $failure = $form->getTransformationFailure();

View File

@ -357,11 +357,9 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
$dataClass = $this->config->getDataClass(); $dataClass = $this->config->getDataClass();
if (null !== $dataClass && !$viewData instanceof $dataClass) { if (null !== $dataClass && !$viewData instanceof $dataClass) {
$actualType = \is_object($viewData) $actualType = get_debug_type($viewData);
? 'an instance of class '.\get_class($viewData)
: 'a(n) '.\gettype($viewData);
throw new LogicException('The form\'s view data is expected to be an instance of class '.$dataClass.', but is '.$actualType.'. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms '.$actualType.' to an instance of '.$dataClass.'.'); throw new LogicException('The form\'s view data is expected to be a "'.$dataClass.'", but it is a "'.$actualType.'". You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms "'.$actualType.'" to an instance of "'.$dataClass.'".');
} }
} }

View File

@ -48,7 +48,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
{ {
foreach ($errors as $error) { foreach ($errors as $error) {
if (!($error instanceof FormError || $error instanceof self)) { if (!($error instanceof FormError || $error instanceof self)) {
throw new InvalidArgumentException(sprintf('The errors must be instances of "Symfony\Component\Form\FormError" or "%s". Got: "%s".', __CLASS__, \is_object($error) ? \get_class($error) : \gettype($error))); throw new InvalidArgumentException(sprintf('The errors must be instances of "Symfony\Component\Form\FormError" or "%s". Got: "%s".', __CLASS__, get_debug_type($error)));
} }
} }

View File

@ -96,7 +96,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
try { try {
$options = $this->getOptionsResolver()->resolve($options); $options = $this->getOptionsResolver()->resolve($options);
} catch (ExceptionInterface $e) { } catch (ExceptionInterface $e) {
throw new $e(sprintf('An error has occurred resolving the options of the form "%s": %s.', \get_class($this->getInnerType()), $e->getMessage()), $e->getCode(), $e); throw new $e(sprintf('An error has occurred resolving the options of the form "%s": %s.', get_debug_type($this->getInnerType()), $e->getMessage()), $e->getCode(), $e);
} }
// Should be decoupled from the specific option at some point // Should be decoupled from the specific option at some point

View File

@ -106,11 +106,11 @@ class WeekToArrayTransformerTest extends TestCase
return [ return [
'missing year' => [['week' => 1], 'Key "year" is missing.'], 'missing year' => [['week' => 1], 'Key "year" is missing.'],
'missing week' => [['year' => 2019], 'Key "week" is missing.'], 'missing week' => [['year' => 2019], 'Key "week" is missing.'],
'integer instead of array' => [0, 'Value is expected to be an array, but was "integer"'], 'integer instead of array' => [0, 'Value is expected to be an array, but was "int"'],
'string instead of array' => ['12345', 'Value is expected to be an array, but was "string"'], 'string instead of array' => ['12345', 'Value is expected to be an array, but was "string"'],
'week invalid' => [['year' => 2019, 'week' => 66], 'Week "66" does not exist for year "2019".'], 'week invalid' => [['year' => 2019, 'week' => 66], 'Week "66" does not exist for year "2019".'],
'year null' => [['year' => null, 'week' => 1], 'Year is expected to be an integer, but was "NULL".'], 'year null' => [['year' => null, 'week' => 1], 'Year is expected to be an integer, but was "null".'],
'week null' => [['year' => 2019, 'week' => null], 'Week is expected to be an integer, but was "NULL".'], 'week null' => [['year' => 2019, 'week' => null], 'Week is expected to be an integer, but was "null".'],
'year non-integer' => [['year' => '2019', 'week' => 1], 'Year is expected to be an integer, but was "string".'], 'year non-integer' => [['year' => '2019', 'week' => 1], 'Year is expected to be an integer, but was "string".'],
'week non-integer' => [['year' => 2019, 'week' => '1'], 'Week is expected to be an integer, but was "string".'], 'week non-integer' => [['year' => 2019, 'week' => '1'], 'Week is expected to be an integer, but was "string".'],
'unexpected key' => [['year' => 2019, 'bar' => 'baz', 'week' => 1, 'foo' => 'foobar'], 'Expected only keys "year" and "week" to be present, but also got ["bar", "foo"].'], 'unexpected key' => [['year' => 2019, 'bar' => 'baz', 'week' => 1, 'foo' => 'foobar'], 'Expected only keys "year" and "week" to be present, but also got ["bar", "foo"].'],

Some files were not shown because too many files have changed in this diff Show More