mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -12,9 +12,11 @@
|
||||
namespace Symfony\Component\DependencyInjection\Loader;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
@@ -22,6 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
@@ -36,7 +39,7 @@ use Symfony\Component\Yaml\Yaml;
|
||||
*/
|
||||
class YamlFileLoader extends FileLoader
|
||||
{
|
||||
private static $serviceKeywords = [
|
||||
private const SERVICE_KEYWORDS = [
|
||||
'alias' => 'alias',
|
||||
'parent' => 'parent',
|
||||
'class' => 'class',
|
||||
@@ -56,13 +59,13 @@ class YamlFileLoader extends FileLoader
|
||||
'decorates' => 'decorates',
|
||||
'decoration_inner_name' => 'decoration_inner_name',
|
||||
'decoration_priority' => 'decoration_priority',
|
||||
'decoration_on_invalid' => 'decoration_on_invalid',
|
||||
'autowire' => 'autowire',
|
||||
'autowiring_types' => 'autowiring_types',
|
||||
'autoconfigure' => 'autoconfigure',
|
||||
'bind' => 'bind',
|
||||
];
|
||||
|
||||
private static $prototypeKeywords = [
|
||||
private const PROTOTYPE_KEYWORDS = [
|
||||
'resource' => 'resource',
|
||||
'namespace' => 'namespace',
|
||||
'exclude' => 'exclude',
|
||||
@@ -83,7 +86,7 @@ class YamlFileLoader extends FileLoader
|
||||
'bind' => 'bind',
|
||||
];
|
||||
|
||||
private static $instanceofKeywords = [
|
||||
private const INSTANCEOF_KEYWORDS = [
|
||||
'shared' => 'shared',
|
||||
'lazy' => 'lazy',
|
||||
'public' => 'public',
|
||||
@@ -92,9 +95,10 @@ class YamlFileLoader extends FileLoader
|
||||
'calls' => 'calls',
|
||||
'tags' => 'tags',
|
||||
'autowire' => 'autowire',
|
||||
'bind' => 'bind',
|
||||
];
|
||||
|
||||
private static $defaultsKeywords = [
|
||||
private const DEFAULTS_KEYWORDS = [
|
||||
'public' => 'public',
|
||||
'tags' => 'tags',
|
||||
'autowire' => 'autowire',
|
||||
@@ -107,10 +111,12 @@ class YamlFileLoader extends FileLoader
|
||||
private $anonymousServicesCount;
|
||||
private $anonymousServicesSuffix;
|
||||
|
||||
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $type = null)
|
||||
public function load($resource, string $type = null)
|
||||
{
|
||||
$path = $this->locator->locate($resource);
|
||||
|
||||
@@ -120,9 +126,31 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
// empty file
|
||||
if (null === $content) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->loadContent($content, $path);
|
||||
|
||||
// per-env configuration
|
||||
if ($this->env && isset($content['when@'.$this->env])) {
|
||||
if (!\is_array($content['when@'.$this->env])) {
|
||||
throw new InvalidArgumentException(sprintf('The "when@%s" key should contain an array in "%s". Check your YAML syntax.', $this->env, $path));
|
||||
}
|
||||
|
||||
$env = $this->env;
|
||||
$this->env = null;
|
||||
try {
|
||||
$this->loadContent($content['when@'.$env], $path);
|
||||
} finally {
|
||||
$this->env = $env;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function loadContent(array $content, string $path)
|
||||
{
|
||||
// imports
|
||||
$this->parseImports($content, $path);
|
||||
|
||||
@@ -148,13 +176,14 @@ class YamlFileLoader extends FileLoader
|
||||
$this->parseDefinitions($content, $path);
|
||||
} finally {
|
||||
$this->instanceof = [];
|
||||
$this->registerAliasesForSinglyImplementedInterfaces();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
public function supports($resource, string $type = null)
|
||||
{
|
||||
if (!\is_string($resource)) {
|
||||
return false;
|
||||
@@ -167,12 +196,7 @@ class YamlFileLoader extends FileLoader
|
||||
return \in_array($type, ['yaml', 'yml'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses all imports.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
private function parseImports(array $content, $file)
|
||||
private function parseImports(array $content, string $file)
|
||||
{
|
||||
if (!isset($content['imports'])) {
|
||||
return;
|
||||
@@ -192,16 +216,11 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
$this->setCurrentDir($defaultDirectory);
|
||||
$this->import($import['resource'], isset($import['type']) ? $import['type'] : null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file);
|
||||
$this->import($import['resource'], $import['type'] ?? null, $import['ignore_errors'] ?? false, $file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses definitions.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
private function parseDefinitions(array $content, $file)
|
||||
private function parseDefinitions(array $content, string $file, bool $trackBindings = true)
|
||||
{
|
||||
if (!isset($content['services'])) {
|
||||
return;
|
||||
@@ -216,7 +235,7 @@ class YamlFileLoader extends FileLoader
|
||||
unset($content['services']['_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->isLoadingInstanceof = true;
|
||||
@@ -224,28 +243,24 @@ class YamlFileLoader extends FileLoader
|
||||
if (!$service || !\is_array($service)) {
|
||||
throw new InvalidArgumentException(sprintf('Type definition "%s" must be a non-empty array within "_instanceof" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
if (\is_string($service) && 0 === strpos($service, '@')) {
|
||||
if (\is_string($service) && str_starts_with($service, '@')) {
|
||||
throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
$this->parseDefinition($id, $service, $file, []);
|
||||
$this->parseDefinition($id, $service, $file, [], false, $trackBindings);
|
||||
}
|
||||
}
|
||||
|
||||
$this->isLoadingInstanceof = false;
|
||||
$defaults = $this->parseDefaults($content, $file);
|
||||
foreach ($content['services'] as $id => $service) {
|
||||
$this->parseDefinition($id, $service, $file, $defaults);
|
||||
$this->parseDefinition($id, $service, $file, $defaults, false, $trackBindings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function parseDefaults(array &$content, $file)
|
||||
private function parseDefaults(array &$content, string $file): array
|
||||
{
|
||||
if (!\array_key_exists('_defaults', $content['services'])) {
|
||||
return [];
|
||||
@@ -254,12 +269,12 @@ class YamlFileLoader extends FileLoader
|
||||
unset($content['services']['_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) {
|
||||
if (!isset(self::$defaultsKeywords[$key])) {
|
||||
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::$defaultsKeywords)));
|
||||
if (!isset(self::DEFAULTS_KEYWORDS[$key])) {
|
||||
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::DEFAULTS_KEYWORDS)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,11 +288,16 @@ class YamlFileLoader extends FileLoader
|
||||
$tag = ['name' => $tag];
|
||||
}
|
||||
|
||||
if (!isset($tag['name'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "tags" entry in "_defaults" is missing a "name" key in "%s".', $file));
|
||||
if (1 === \count($tag) && \is_array(current($tag))) {
|
||||
$name = key($tag);
|
||||
$tag = current($tag);
|
||||
} else {
|
||||
if (!isset($tag['name'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "tags" entry in "_defaults" is missing a "name" key in "%s".', $file));
|
||||
}
|
||||
$name = $tag['name'];
|
||||
unset($tag['name']);
|
||||
}
|
||||
$name = $tag['name'];
|
||||
unset($tag['name']);
|
||||
|
||||
if (!\is_string($name) || '' === $name) {
|
||||
throw new InvalidArgumentException(sprintf('The tag name in "_defaults" must be a non-empty string in "%s".', $file));
|
||||
@@ -296,19 +316,18 @@ class YamlFileLoader extends FileLoader
|
||||
throw new InvalidArgumentException(sprintf('Parameter "bind" in "_defaults" must be an array in "%s". Check your YAML syntax.', $file));
|
||||
}
|
||||
|
||||
$defaults['bind'] = array_map(function ($v) { return new BoundArgument($v); }, $this->resolveServices($defaults['bind'], $file));
|
||||
foreach ($this->resolveServices($defaults['bind'], $file) as $argument => $value) {
|
||||
$defaults['bind'][$argument] = new BoundArgument($value, true, BoundArgument::DEFAULTS_BINDING, $file);
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isUsingShortSyntax(array $service)
|
||||
private function isUsingShortSyntax(array $service): bool
|
||||
{
|
||||
foreach ($service as $key => $value) {
|
||||
if (\is_string($key) && ('' === $key || '$' !== $key[0])) {
|
||||
if (\is_string($key) && ('' === $key || ('$' !== $key[0] && !str_contains($key, '\\')))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -319,24 +338,24 @@ class YamlFileLoader extends FileLoader
|
||||
/**
|
||||
* Parses a definition.
|
||||
*
|
||||
* @param string $id
|
||||
* @param array|string $service
|
||||
* @param string $file
|
||||
* @param array|string|null $service
|
||||
*
|
||||
* @throws InvalidArgumentException When tags are invalid
|
||||
*/
|
||||
private function parseDefinition($id, $service, $file, array $defaults)
|
||||
private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true)
|
||||
{
|
||||
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
|
||||
@trigger_error(sprintf('Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0. Rename the "%s" service or define it in XML instead.', $id), \E_USER_DEPRECATED);
|
||||
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
|
||||
}
|
||||
if (\is_string($service) && 0 === strpos($service, '@')) {
|
||||
$this->container->setAlias($id, $alias = new Alias(substr($service, 1)));
|
||||
|
||||
if (\is_string($service) && str_starts_with($service, '@')) {
|
||||
$alias = new Alias(substr($service, 1));
|
||||
|
||||
if (isset($defaults['public'])) {
|
||||
$alias->setPublic($defaults['public']);
|
||||
}
|
||||
|
||||
return;
|
||||
return $return ? $alias : $this->container->setAlias($id, $alias);
|
||||
}
|
||||
|
||||
if (\is_array($service) && $this->isUsingShortSyntax($service)) {
|
||||
@@ -348,13 +367,58 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (isset($service['stack'])) {
|
||||
if (!\is_array($service['stack'])) {
|
||||
throw new InvalidArgumentException(sprintf('A stack must be an array of definitions, "%s" given for service "%s" in "%s". Check your YAML syntax.', get_debug_type($service), $id, $file));
|
||||
}
|
||||
|
||||
$stack = [];
|
||||
|
||||
foreach ($service['stack'] as $k => $frame) {
|
||||
if (\is_array($frame) && 1 === \count($frame) && !isset(self::SERVICE_KEYWORDS[key($frame)])) {
|
||||
$frame = [
|
||||
'class' => key($frame),
|
||||
'arguments' => current($frame),
|
||||
];
|
||||
}
|
||||
|
||||
if (\is_array($frame) && isset($frame['stack'])) {
|
||||
throw new InvalidArgumentException(sprintf('Service stack "%s" cannot contain another stack in "%s".', $id, $file));
|
||||
}
|
||||
|
||||
$definition = $this->parseDefinition($id.'" at index "'.$k, $frame, $file, $defaults, true);
|
||||
|
||||
if ($definition instanceof Definition) {
|
||||
$definition->setInstanceofConditionals($this->instanceof);
|
||||
}
|
||||
|
||||
$stack[$k] = $definition;
|
||||
}
|
||||
|
||||
if ($diff = array_diff(array_keys($service), ['stack', 'public', 'deprecated'])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid attribute "%s"; supported ones are "public" and "deprecated" for service "%s" in "%s". Check your YAML syntax.', implode('", "', $diff), $id, $file));
|
||||
}
|
||||
|
||||
$service = [
|
||||
'parent' => '',
|
||||
'arguments' => $stack,
|
||||
'tags' => ['container.stack'],
|
||||
'public' => $service['public'] ?? null,
|
||||
'deprecated' => $service['deprecated'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
$definition = isset($service[0]) && $service[0] instanceof Definition ? array_shift($service) : null;
|
||||
$return = null === $definition ? $return : true;
|
||||
|
||||
$this->checkDefinition($id, $service, $file);
|
||||
|
||||
if (isset($service['alias'])) {
|
||||
$this->container->setAlias($id, $alias = new Alias($service['alias']));
|
||||
$alias = new Alias($service['alias']);
|
||||
|
||||
if (isset($service['public'])) {
|
||||
$alias->setPublic($service['public']);
|
||||
} elseif (isset($defaults['public'])) {
|
||||
@@ -362,52 +426,54 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
foreach ($service as $key => $value) {
|
||||
if (!\in_array($key, ['alias', 'public'])) {
|
||||
@trigger_error(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), \E_USER_DEPRECATED);
|
||||
if (!\in_array($key, ['alias', 'public', 'deprecated'])) {
|
||||
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias", "public" and "deprecated".', $key, $id, $file));
|
||||
}
|
||||
|
||||
if ('deprecated' === $key) {
|
||||
$deprecation = \is_array($value) ? $value : ['message' => $value];
|
||||
|
||||
if (!isset($deprecation['package'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if (!isset($deprecation['version'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return $return ? $alias : $this->container->setAlias($id, $alias);
|
||||
}
|
||||
|
||||
if ($this->isLoadingInstanceof) {
|
||||
if (null !== $definition) {
|
||||
// no-op
|
||||
} elseif ($this->isLoadingInstanceof) {
|
||||
$definition = new ChildDefinition('');
|
||||
} elseif (isset($service['parent'])) {
|
||||
if (!empty($this->instanceof)) {
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" cannot use the "parent" option in the same file where "_instanceof" configuration is defined as using both is not supported. Move your child definitions to a separate file.', $id));
|
||||
}
|
||||
|
||||
foreach ($defaults as $k => $v) {
|
||||
if ('tags' === $k) {
|
||||
// since tags are never inherited from parents, there is no confusion
|
||||
// thus we can safely add them as defaults to ChildDefinition
|
||||
continue;
|
||||
}
|
||||
if ('bind' === $k) {
|
||||
throw new InvalidArgumentException(sprintf('Attribute "bind" on service "%s" cannot be inherited from "_defaults" when a "parent" is set. Move your child definitions to a separate file.', $id));
|
||||
}
|
||||
if (!isset($service[$k])) {
|
||||
throw new InvalidArgumentException(sprintf('Attribute "%s" on service "%s" cannot be inherited from "_defaults" when a "parent" is set. Move your child definitions to a separate file or define this attribute explicitly.', $k, $id));
|
||||
}
|
||||
if ('' !== $service['parent'] && '@' === $service['parent'][0]) {
|
||||
throw new InvalidArgumentException(sprintf('The value of the "parent" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['parent'], substr($service['parent'], 1)));
|
||||
}
|
||||
|
||||
$definition = new ChildDefinition($service['parent']);
|
||||
} else {
|
||||
$definition = new Definition();
|
||||
|
||||
if (isset($defaults['public'])) {
|
||||
$definition->setPublic($defaults['public']);
|
||||
}
|
||||
if (isset($defaults['autowire'])) {
|
||||
$definition->setAutowired($defaults['autowire']);
|
||||
}
|
||||
if (isset($defaults['autoconfigure'])) {
|
||||
$definition->setAutoconfigured($defaults['autoconfigure']);
|
||||
}
|
||||
|
||||
$definition->setChanges([]);
|
||||
}
|
||||
|
||||
if (isset($defaults['public'])) {
|
||||
$definition->setPublic($defaults['public']);
|
||||
}
|
||||
if (isset($defaults['autowire'])) {
|
||||
$definition->setAutowired($defaults['autowire']);
|
||||
}
|
||||
if (isset($defaults['autoconfigure'])) {
|
||||
$definition->setAutoconfigured($defaults['autoconfigure']);
|
||||
}
|
||||
|
||||
$definition->setChanges([]);
|
||||
|
||||
if (isset($service['class'])) {
|
||||
$definition->setClass($service['class']);
|
||||
}
|
||||
@@ -421,7 +487,10 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
if (isset($service['lazy'])) {
|
||||
$definition->setLazy($service['lazy']);
|
||||
$definition->setLazy((bool) $service['lazy']);
|
||||
if (\is_string($service['lazy'])) {
|
||||
$definition->addTag('proxy', ['interface' => $service['lazy']]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($service['public'])) {
|
||||
@@ -432,8 +501,18 @@ class YamlFileLoader extends FileLoader
|
||||
$definition->setAbstract($service['abstract']);
|
||||
}
|
||||
|
||||
if (\array_key_exists('deprecated', $service)) {
|
||||
$definition->setDeprecated(true, $service['deprecated']);
|
||||
if (isset($service['deprecated'])) {
|
||||
$deprecation = \is_array($service['deprecated']) ? $service['deprecated'] : ['message' => $service['deprecated']];
|
||||
|
||||
if (!isset($deprecation['package'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if (!isset($deprecation['version'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
|
||||
}
|
||||
|
||||
if (isset($service['factory'])) {
|
||||
@@ -461,23 +540,53 @@ class YamlFileLoader extends FileLoader
|
||||
throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
foreach ($service['calls'] as $call) {
|
||||
if (isset($call['method'])) {
|
||||
foreach ($service['calls'] as $k => $call) {
|
||||
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() : get_debug_type($call), $file));
|
||||
}
|
||||
|
||||
if (\is_string($k)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid method call for service "%s", did you forgot a leading dash before "%s: ..." in "%s"?', $id, $k, $file));
|
||||
}
|
||||
|
||||
if (isset($call['method']) && \is_string($call['method'])) {
|
||||
$method = $call['method'];
|
||||
$args = isset($call['arguments']) ? $this->resolveServices($call['arguments'], $file) : [];
|
||||
$args = $call['arguments'] ?? [];
|
||||
$returnsClone = $call['returns_clone'] ?? false;
|
||||
} else {
|
||||
$method = $call[0];
|
||||
$args = isset($call[1]) ? $this->resolveServices($call[1], $file) : [];
|
||||
if (1 === \count($call) && \is_string(key($call))) {
|
||||
$method = key($call);
|
||||
$args = $call[$method];
|
||||
|
||||
if ($args instanceof TaggedValue) {
|
||||
if ('returns_clone' !== $args->getTag()) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported tag "!%s", did you mean "!returns_clone" for service "%s" in "%s"?', $args->getTag(), $id, $file));
|
||||
}
|
||||
|
||||
$returnsClone = true;
|
||||
$args = $args->getValue();
|
||||
} else {
|
||||
$returnsClone = false;
|
||||
}
|
||||
} elseif (empty($call[0])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid call for service "%s": the method must be defined as the first index of an array or as the only key of a map in "%s".', $id, $file));
|
||||
} else {
|
||||
$method = $call[0];
|
||||
$args = $call[1] ?? [];
|
||||
$returnsClone = $call[2] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_array($args)) {
|
||||
throw new InvalidArgumentException(sprintf('The second parameter for function call "%s" must be an array of its arguments for service "%s" in "%s". Check your YAML syntax.', $method, $id, $file));
|
||||
}
|
||||
$definition->addMethodCall($method, $args);
|
||||
|
||||
$args = $this->resolveServices($args, $file);
|
||||
$definition->addMethodCall($method, $args, $returnsClone);
|
||||
}
|
||||
}
|
||||
|
||||
$tags = isset($service['tags']) ? $service['tags'] : [];
|
||||
$tags = $service['tags'] ?? [];
|
||||
if (!\is_array($tags)) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
@@ -491,11 +600,16 @@ class YamlFileLoader extends FileLoader
|
||||
$tag = ['name' => $tag];
|
||||
}
|
||||
|
||||
if (!isset($tag['name'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in "%s".', $id, $file));
|
||||
if (1 === \count($tag) && \is_array(current($tag))) {
|
||||
$name = key($tag);
|
||||
$tag = current($tag);
|
||||
} else {
|
||||
if (!isset($tag['name'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in "%s".', $id, $file));
|
||||
}
|
||||
$name = $tag['name'];
|
||||
unset($tag['name']);
|
||||
}
|
||||
$name = $tag['name'];
|
||||
unset($tag['name']);
|
||||
|
||||
if (!\is_string($name) || '' === $name) {
|
||||
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', $id, $file));
|
||||
@@ -510,41 +624,38 @@ class YamlFileLoader extends FileLoader
|
||||
$definition->addTag($name, $tag);
|
||||
}
|
||||
|
||||
if (isset($service['decorates'])) {
|
||||
if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
|
||||
throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
|
||||
if (null !== $decorates = $service['decorates'] ?? null) {
|
||||
if ('' !== $decorates && '@' === $decorates[0]) {
|
||||
throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($decorates, 1)));
|
||||
}
|
||||
|
||||
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
|
||||
$priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
|
||||
$definition->setDecoratedService($service['decorates'], $renameId, $priority);
|
||||
$decorationOnInvalid = \array_key_exists('decoration_on_invalid', $service) ? $service['decoration_on_invalid'] : 'exception';
|
||||
if ('exception' === $decorationOnInvalid) {
|
||||
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
} elseif ('ignore' === $decorationOnInvalid) {
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
||||
} elseif (null === $decorationOnInvalid) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
|
||||
} elseif ('null' === $decorationOnInvalid) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid value "%s" for attribute "decoration_on_invalid" on service "%s". Did you mean null (without quotes) in "%s"?', $decorationOnInvalid, $id, $file));
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('Invalid value "%s" for attribute "decoration_on_invalid" on service "%s". Did you mean "exception", "ignore" or null in "%s"?', $decorationOnInvalid, $id, $file));
|
||||
}
|
||||
|
||||
$renameId = $service['decoration_inner_name'] ?? null;
|
||||
$priority = $service['decoration_priority'] ?? 0;
|
||||
|
||||
$definition->setDecoratedService($decorates, $renameId, $priority, $invalidBehavior);
|
||||
}
|
||||
|
||||
if (isset($service['autowire'])) {
|
||||
$definition->setAutowired($service['autowire']);
|
||||
}
|
||||
|
||||
if (isset($service['autowiring_types'])) {
|
||||
if (\is_string($service['autowiring_types'])) {
|
||||
$definition->addAutowiringType($service['autowiring_types']);
|
||||
} else {
|
||||
if (!\is_array($service['autowiring_types'])) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
foreach ($service['autowiring_types'] as $autowiringType) {
|
||||
if (!\is_string($autowiringType)) {
|
||||
throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
$definition->addAutowiringType($autowiringType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($defaults['bind']) || isset($service['bind'])) {
|
||||
// deep clone, to avoid multiple process of the same instance in the passes
|
||||
$bindings = isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : [];
|
||||
$bindings = $definition->getBindings();
|
||||
$bindings += isset($defaults['bind']) ? unserialize(serialize($defaults['bind'])) : [];
|
||||
|
||||
if (isset($service['bind'])) {
|
||||
if (!\is_array($service['bind'])) {
|
||||
@@ -552,29 +663,39 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
$bindings = array_merge($bindings, $this->resolveServices($service['bind'], $file));
|
||||
$bindingType = $this->isLoadingInstanceof ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING;
|
||||
foreach ($bindings as $argument => $value) {
|
||||
if (!$value instanceof BoundArgument) {
|
||||
$bindings[$argument] = new BoundArgument($value, $trackBindings, $bindingType, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$definition->setBindings($bindings);
|
||||
}
|
||||
|
||||
if (isset($service['autoconfigure'])) {
|
||||
if (!$definition instanceof ChildDefinition) {
|
||||
$definition->setAutoconfigured($service['autoconfigure']);
|
||||
} elseif ($service['autoconfigure']) {
|
||||
throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also have "autoconfigure". Try setting "autoconfigure: false" for the service.', $id));
|
||||
}
|
||||
$definition->setAutoconfigured($service['autoconfigure']);
|
||||
}
|
||||
|
||||
if (\array_key_exists('namespace', $service) && !\array_key_exists('resource', $service)) {
|
||||
throw new InvalidArgumentException(sprintf('A "resource" attribute must be set when the "namespace" attribute is set for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
if (\array_key_exists('resource', $service)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid "resource" attribute found for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
if (\array_key_exists('resource', $service)) {
|
||||
if (!\is_string($service['resource'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "resource" attribute must be of type string for service "%s" in "%s". Check your YAML syntax.', $id, $file));
|
||||
}
|
||||
$exclude = isset($service['exclude']) ? $service['exclude'] : null;
|
||||
$namespace = isset($service['namespace']) ? $service['namespace'] : $id;
|
||||
$exclude = $service['exclude'] ?? null;
|
||||
$namespace = $service['namespace'] ?? $id;
|
||||
$this->registerClasses($definition, $namespace, $service['resource'], $exclude);
|
||||
} else {
|
||||
$this->setDefinition($id, $definition);
|
||||
@@ -584,26 +705,21 @@ class YamlFileLoader extends FileLoader
|
||||
/**
|
||||
* Parses a callable.
|
||||
*
|
||||
* @param string|array $callable A callable
|
||||
* @param string $parameter A parameter (e.g. 'factory' or 'configurator')
|
||||
* @param string $id A service identifier
|
||||
* @param string $file A parsed file
|
||||
* @param string|array $callable A callable reference
|
||||
*
|
||||
* @throws InvalidArgumentException When errors occur
|
||||
*
|
||||
* @return string|array A parsed callable
|
||||
* @return string|array|Reference
|
||||
*/
|
||||
private function parseCallable($callable, $parameter, $id, $file)
|
||||
private function parseCallable($callable, string $parameter, string $id, string $file)
|
||||
{
|
||||
if (\is_string($callable)) {
|
||||
if ('' !== $callable && '@' === $callable[0]) {
|
||||
throw new InvalidArgumentException(sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $parameter, $id, $callable, substr($callable, 1)));
|
||||
}
|
||||
if (!str_contains($callable, ':')) {
|
||||
return [$this->resolveServices($callable, $file), '__invoke'];
|
||||
}
|
||||
|
||||
if (false !== strpos($callable, ':') && false === strpos($callable, '::')) {
|
||||
$parts = explode(':', $callable);
|
||||
|
||||
return [$this->resolveServices('@'.$parts[0], $file), $parts[1]];
|
||||
throw new InvalidArgumentException(sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s" in "%s").', $parameter, $id, $callable, substr($callable, 1), $file));
|
||||
}
|
||||
|
||||
return $callable;
|
||||
@@ -627,15 +743,13 @@ class YamlFileLoader extends FileLoader
|
||||
/**
|
||||
* Loads a YAML file.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return array The file content
|
||||
* @return array|null
|
||||
*
|
||||
* @throws InvalidArgumentException when the given file is not a local file or when it does not exist
|
||||
*/
|
||||
protected function loadFile($file)
|
||||
protected function loadFile(string $file)
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Yaml\Parser')) {
|
||||
if (!class_exists(\Symfony\Component\Yaml\Parser::class)) {
|
||||
throw new RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
|
||||
}
|
||||
|
||||
@@ -643,7 +757,7 @@ class YamlFileLoader extends FileLoader
|
||||
throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
|
||||
}
|
||||
|
||||
if (!file_exists($file)) {
|
||||
if (!is_file($file)) {
|
||||
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
|
||||
}
|
||||
|
||||
@@ -651,18 +765,10 @@ class YamlFileLoader extends FileLoader
|
||||
$this->yamlParser = new YamlParser();
|
||||
}
|
||||
|
||||
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($file, &$prevErrorHandler) {
|
||||
$message = \E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$file.'"$0', $message) : $message;
|
||||
|
||||
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
|
||||
});
|
||||
|
||||
try {
|
||||
$configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
|
||||
} catch (ParseException $e) {
|
||||
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $file).$e->getMessage(), 0, $e);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
return $this->validate($configuration, $file);
|
||||
@@ -671,14 +777,9 @@ class YamlFileLoader extends FileLoader
|
||||
/**
|
||||
* Validates a YAML file.
|
||||
*
|
||||
* @param mixed $content
|
||||
* @param string $file
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws InvalidArgumentException When service file is not valid
|
||||
*/
|
||||
private function validate($content, $file)
|
||||
private function validate($content, string $file): ?array
|
||||
{
|
||||
if (null === $content) {
|
||||
return $content;
|
||||
@@ -689,12 +790,12 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
foreach ($content as $namespace => $data) {
|
||||
if (\in_array($namespace, ['imports', 'parameters', 'services'])) {
|
||||
if (\in_array($namespace, ['imports', 'parameters', 'services']) || 0 === strpos($namespace, 'when@')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->container->hasExtension($namespace)) {
|
||||
$extensionNamespaces = array_filter(array_map(function ($ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
|
||||
$extensionNamespaces = array_filter(array_map(function (ExtensionInterface $ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
|
||||
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $namespace, $file, $namespace, $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'));
|
||||
}
|
||||
}
|
||||
@@ -703,15 +804,9 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves services.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $file
|
||||
* @param bool $isParameter
|
||||
*
|
||||
* @return array|string|Reference|ArgumentInterface
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolveServices($value, $file, $isParameter = false)
|
||||
private function resolveServices($value, string $file, bool $isParameter = false)
|
||||
{
|
||||
if ($value instanceof TaggedValue) {
|
||||
$argument = $value->getValue();
|
||||
@@ -726,12 +821,48 @@ class YamlFileLoader extends FileLoader
|
||||
throw new InvalidArgumentException(sprintf('"!iterator" tag only accepts arrays of "@service" references in "%s".', $file));
|
||||
}
|
||||
}
|
||||
if ('tagged' === $value->getTag()) {
|
||||
if (!\is_string($argument) || !$argument) {
|
||||
throw new InvalidArgumentException(sprintf('"!tagged" tag only accepts non empty string in "%s".', $file));
|
||||
if ('service_closure' === $value->getTag()) {
|
||||
$argument = $this->resolveServices($argument, $file, $isParameter);
|
||||
|
||||
if (!$argument instanceof Reference) {
|
||||
throw new InvalidArgumentException(sprintf('"!service_closure" tag only accepts service references in "%s".', $file));
|
||||
}
|
||||
|
||||
return new TaggedIteratorArgument($argument);
|
||||
return new ServiceClosureArgument($argument);
|
||||
}
|
||||
if ('service_locator' === $value->getTag()) {
|
||||
if (!\is_array($argument)) {
|
||||
throw new InvalidArgumentException(sprintf('"!service_locator" tag only accepts maps in "%s".', $file));
|
||||
}
|
||||
|
||||
$argument = $this->resolveServices($argument, $file, $isParameter);
|
||||
|
||||
try {
|
||||
return new ServiceLocatorArgument($argument);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new InvalidArgumentException(sprintf('"!service_locator" tag only accepts maps of "@service" references in "%s".', $file));
|
||||
}
|
||||
}
|
||||
if (\in_array($value->getTag(), ['tagged', 'tagged_iterator', 'tagged_locator'], true)) {
|
||||
$forLocator = 'tagged_locator' === $value->getTag();
|
||||
|
||||
if (\is_array($argument) && isset($argument['tag']) && $argument['tag']) {
|
||||
if ($diff = array_diff(array_keys($argument), ['tag', 'index_by', 'default_index_method', 'default_priority_method'])) {
|
||||
throw new InvalidArgumentException(sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "tag", "index_by", "default_index_method", and "default_priority_method".', $value->getTag(), implode('", "', $diff)));
|
||||
}
|
||||
|
||||
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator, $argument['default_priority_method'] ?? null);
|
||||
} elseif (\is_string($argument) && $argument) {
|
||||
$argument = new TaggedIteratorArgument($argument, null, null, $forLocator);
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('"!%s" tags only accept a non empty string or an array with a key "tag" in "%s".', $value->getTag(), $file));
|
||||
}
|
||||
|
||||
if ($forLocator) {
|
||||
$argument = new ServiceLocatorArgument($argument);
|
||||
}
|
||||
|
||||
return $argument;
|
||||
}
|
||||
if ('service' === $value->getTag()) {
|
||||
if ($isParameter) {
|
||||
@@ -743,20 +874,23 @@ class YamlFileLoader extends FileLoader
|
||||
$instanceof = $this->instanceof;
|
||||
$this->instanceof = [];
|
||||
|
||||
$id = sprintf('%d_%s', ++$this->anonymousServicesCount, preg_replace('/^.*\\\\/', '', isset($argument['class']) ? $argument['class'] : '').$this->anonymousServicesSuffix);
|
||||
$id = sprintf('.%d_%s', ++$this->anonymousServicesCount, preg_replace('/^.*\\\\/', '', $argument['class'] ?? '').$this->anonymousServicesSuffix);
|
||||
$this->parseDefinition($id, $argument, $file, []);
|
||||
|
||||
if (!$this->container->hasDefinition($id)) {
|
||||
throw new InvalidArgumentException(sprintf('Creating an alias using the tag "!service" is not allowed in "%s".', $file));
|
||||
}
|
||||
|
||||
$this->container->getDefinition($id)->setPublic(false);
|
||||
$this->container->getDefinition($id);
|
||||
|
||||
$this->isLoadingInstanceof = $isLoadingInstanceof;
|
||||
$this->instanceof = $instanceof;
|
||||
|
||||
return new Reference($id);
|
||||
}
|
||||
if ('abstract' === $value->getTag()) {
|
||||
return new AbstractArgument($value->getValue());
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Unsupported tag "!%s".', $value->getTag()));
|
||||
}
|
||||
@@ -765,20 +899,24 @@ class YamlFileLoader extends FileLoader
|
||||
foreach ($value as $k => $v) {
|
||||
$value[$k] = $this->resolveServices($v, $file, $isParameter);
|
||||
}
|
||||
} elseif (\is_string($value) && 0 === strpos($value, '@=')) {
|
||||
} elseif (\is_string($value) && str_starts_with($value, '@=')) {
|
||||
if ($isParameter) {
|
||||
throw new InvalidArgumentException(sprintf('Using expressions in parameters is not allowed in "%s".', $file));
|
||||
}
|
||||
|
||||
if (!class_exists(Expression::class)) {
|
||||
throw new \LogicException(sprintf('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".'));
|
||||
throw new \LogicException('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
|
||||
}
|
||||
|
||||
return new Expression(substr($value, 2));
|
||||
} elseif (\is_string($value) && 0 === strpos($value, '@')) {
|
||||
if (0 === strpos($value, '@@')) {
|
||||
} elseif (\is_string($value) && str_starts_with($value, '@')) {
|
||||
if (str_starts_with($value, '@@')) {
|
||||
$value = substr($value, 1);
|
||||
$invalidBehavior = null;
|
||||
} elseif (0 === strpos($value, '@!')) {
|
||||
} elseif (str_starts_with($value, '@!')) {
|
||||
$value = substr($value, 2);
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE;
|
||||
} elseif (0 === strpos($value, '@?')) {
|
||||
} elseif (str_starts_with($value, '@?')) {
|
||||
$value = substr($value, 2);
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
||||
} else {
|
||||
@@ -786,11 +924,6 @@ class YamlFileLoader extends FileLoader
|
||||
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
if ('=' === substr($value, -1)) {
|
||||
@trigger_error(sprintf('The "=" suffix that used to disable strict references in Symfony 2.x is deprecated since Symfony 3.3 and will be unsupported in 4.0. Remove it in "%s".', $value), \E_USER_DEPRECATED);
|
||||
$value = substr($value, 0, -1);
|
||||
}
|
||||
|
||||
if (null !== $invalidBehavior) {
|
||||
$value = new Reference($value, $invalidBehavior);
|
||||
}
|
||||
@@ -799,13 +932,10 @@ class YamlFileLoader extends FileLoader
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads from Extensions.
|
||||
*/
|
||||
private function loadFromExtensions(array $content)
|
||||
{
|
||||
foreach ($content as $namespace => $values) {
|
||||
if (\in_array($namespace, ['imports', 'parameters', 'services'])) {
|
||||
if (\in_array($namespace, ['imports', 'parameters', 'services']) || 0 === strpos($namespace, 'when@')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -817,30 +947,19 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the keywords used to define a service.
|
||||
*
|
||||
* @param string $id The service name
|
||||
* @param array $definition The service definition to check
|
||||
* @param string $file The loaded YAML file
|
||||
*/
|
||||
private function checkDefinition($id, array $definition, $file)
|
||||
private function checkDefinition(string $id, array $definition, string $file)
|
||||
{
|
||||
if ($throw = $this->isLoadingInstanceof) {
|
||||
$keywords = self::$instanceofKeywords;
|
||||
} elseif ($throw = (isset($definition['resource']) || isset($definition['namespace']))) {
|
||||
$keywords = self::$prototypeKeywords;
|
||||
if ($this->isLoadingInstanceof) {
|
||||
$keywords = self::INSTANCEOF_KEYWORDS;
|
||||
} elseif (isset($definition['resource']) || isset($definition['namespace'])) {
|
||||
$keywords = self::PROTOTYPE_KEYWORDS;
|
||||
} else {
|
||||
$keywords = self::$serviceKeywords;
|
||||
$keywords = self::SERVICE_KEYWORDS;
|
||||
}
|
||||
|
||||
foreach ($definition as $key => $value) {
|
||||
if (!isset($keywords[$key])) {
|
||||
if ($throw) {
|
||||
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', $keywords)));
|
||||
}
|
||||
|
||||
@trigger_error(sprintf('The configuration key "%s" is unsupported for service definition "%s" in "%s". Allowed configuration keys are "%s". The YamlFileLoader object will raise an exception instead in Symfony 4.0 when detecting an unsupported service configuration key.', $key, $id, $file, implode('", "', $keywords)), \E_USER_DEPRECATED);
|
||||
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', $keywords)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user