private function YamlFileLoader::parseDefinition in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::parseDefinition()
- 8 core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php \Drupal\Core\DependencyInjection\YamlFileLoader::parseDefinition()
Same name and namespace in other branches
- 8.0 vendor/symfony/dependency-injection/Loader/YamlFileLoader.php \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::parseDefinition()
Parses a definition.
Parameters
string $id:
array $service:
string $file:
Throws
InvalidArgumentException When tags are invalid
1 call to YamlFileLoader::parseDefinition()
- YamlFileLoader::parseDefinitions in vendor/
symfony/ dependency-injection/ Loader/ YamlFileLoader.php - Parses definitions.
File
- vendor/
symfony/ dependency-injection/ Loader/ YamlFileLoader.php, line 138
Class
- YamlFileLoader
- YamlFileLoader loads YAML files service definitions.
Namespace
Symfony\Component\DependencyInjection\LoaderCode
private function parseDefinition($id, $service, $file) {
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container
->setAlias($id, substr($service, 1));
return;
}
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));
}
if (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (bool) $service['public'];
$this->container
->setAlias($id, new Alias($service['alias'], $public));
return;
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
}
else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition
->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition
->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition
->setSynthetic($service['synthetic']);
}
if (isset($service['synchronized'])) {
@trigger_error(sprintf('The "synchronized" key of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED);
$definition
->setSynchronized($service['synchronized'], 'request' !== $id);
}
if (isset($service['lazy'])) {
$definition
->setLazy($service['lazy']);
}
if (isset($service['public'])) {
$definition
->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition
->setAbstract($service['abstract']);
}
if (isset($service['factory'])) {
if (is_string($service['factory'])) {
if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
$parts = explode(':', $service['factory']);
$definition
->setFactory(array(
$this
->resolveServices('@' . $parts[0]),
$parts[1],
));
}
else {
$definition
->setFactory($service['factory']);
}
}
else {
$definition
->setFactory(array(
$this
->resolveServices($service['factory'][0]),
$service['factory'][1],
));
}
}
if (isset($service['factory_class'])) {
@trigger_error(sprintf('The "factory_class" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
$definition
->setFactoryClass($service['factory_class']);
}
if (isset($service['factory_method'])) {
@trigger_error(sprintf('The "factory_method" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
$definition
->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
@trigger_error(sprintf('The "factory_service" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
$definition
->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition
->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition
->setArguments($this
->resolveServices($service['arguments']));
}
if (isset($service['properties'])) {
$definition
->setProperties($this
->resolveServices($service['properties']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition
->setConfigurator($service['configurator']);
}
else {
$definition
->setConfigurator(array(
$this
->resolveServices($service['configurator'][0]),
$service['configurator'][1],
));
}
}
if (isset($service['calls'])) {
if (!is_array($service['calls'])) {
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'])) {
$method = $call['method'];
$args = isset($call['arguments']) ? $this
->resolveServices($call['arguments']) : array();
}
else {
$method = $call[0];
$args = isset($call[1]) ? $this
->resolveServices($call[1]) : array();
}
$definition
->addMethodCall($method, $args);
}
}
if (isset($service['tags'])) {
if (!is_array($service['tags'])) {
throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
foreach ($service['tags'] as $tag) {
if (!is_array($tag)) {
throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
}
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']);
foreach ($tag as $attribute => $value) {
if (!is_scalar($value) && null !== $value) {
throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
}
}
$definition
->addTag($name, $tag);
}
}
if (isset($service['decorates'])) {
$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
$definition
->setDecoratedService($service['decorates'], $renameId);
}
$this->container
->setDefinition($id, $definition);
}