2010-01-04 14:26:20 +00:00
< ? php
2011-01-15 13:29:43 +00:00
/*
* This file is part of the Symfony package .
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2011-01-15 13:29:43 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Component\DependencyInjection\Loader ;
2010-01-04 14:26:20 +00:00
2011-01-26 23:14:31 +00:00
use Symfony\Component\DependencyInjection\DefinitionDecorator ;
2011-01-07 14:44:29 +00:00
use Symfony\Component\DependencyInjection\Alias ;
2010-08-20 22:09:55 +01:00
use Symfony\Component\DependencyInjection\ContainerInterface ;
use Symfony\Component\DependencyInjection\Definition ;
use Symfony\Component\DependencyInjection\Reference ;
2011-12-04 23:51:22 +00:00
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException ;
2015-04-06 14:14:07 +01:00
use Symfony\Component\DependencyInjection\Exception\RuntimeException ;
2011-02-10 15:15:51 +00:00
use Symfony\Component\Config\Resource\FileResource ;
2015-09-08 20:57:35 +01:00
use Symfony\Component\Yaml\Exception\ParseException ;
2013-05-05 10:27:54 +01:00
use Symfony\Component\Yaml\Parser as YamlParser ;
2013-09-02 11:46:47 +01:00
use Symfony\Component\ExpressionLanguage\Expression ;
2010-01-04 14:26:20 +00:00
/**
* YamlFileLoader loads YAML files service definitions .
*
* The YAML format does not support anonymous services ( cf . the XML loader ) .
*
2011-03-06 11:40:06 +00:00
* @ author Fabien Potencier < fabien @ symfony . com >
2010-01-04 14:26:20 +00:00
*/
class YamlFileLoader extends FileLoader
{
2015-12-24 15:17:45 +00:00
private static $keywords = array (
'alias' => 'alias' ,
'parent' => 'parent' ,
'class' => 'class' ,
'shared' => 'shared' ,
'synthetic' => 'synthetic' ,
'lazy' => 'lazy' ,
'public' => 'public' ,
'abstract' => 'abstract' ,
'deprecated' => 'deprecated' ,
'factory' => 'factory' ,
'file' => 'file' ,
'arguments' => 'arguments' ,
'properties' => 'properties' ,
'configurator' => 'configurator' ,
'calls' => 'calls' ,
'tags' => 'tags' ,
'decorates' => 'decorates' ,
'decoration_inner_name' => 'decoration_inner_name' ,
'decoration_priority' => 'decoration_priority' ,
'autowire' => 'autowire' ,
'autowiring_types' => 'autowiring_types' ,
);
2013-05-05 10:27:54 +01:00
private $yamlParser ;
2010-05-06 12:25:53 +01:00
/**
2014-10-13 20:09:32 +01:00
* { @ inheritdoc }
2010-05-06 12:25:53 +01:00
*/
2014-10-13 20:09:32 +01:00
public function load ( $resource , $type = null )
2010-05-06 12:25:53 +01:00
{
2014-10-13 20:09:32 +01:00
$path = $this -> locator -> locate ( $resource );
2010-01-17 10:21:31 +00:00
2010-05-06 12:25:53 +01:00
$content = $this -> loadFile ( $path );
2010-01-04 14:26:20 +00:00
2010-07-16 08:12:58 +01:00
$this -> container -> addResource ( new FileResource ( $path ));
2010-01-17 10:21:31 +00:00
2010-12-12 07:39:37 +00:00
// empty file
if ( null === $content ) {
2010-07-16 08:12:58 +01:00
return ;
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
2010-05-06 12:25:53 +01:00
// imports
2014-03-27 06:16:27 +00:00
$this -> parseImports ( $content , $path );
2010-01-04 14:26:20 +00:00
2010-05-06 12:25:53 +01:00
// parameters
2010-05-07 15:09:11 +01:00
if ( isset ( $content [ 'parameters' ])) {
2014-07-11 12:56:54 +01:00
if ( ! is_array ( $content [ 'parameters' ])) {
2014-10-13 20:09:32 +01:00
throw new InvalidArgumentException ( sprintf ( 'The "parameters" key should contain an array in %s. Check your YAML syntax.' , $resource ));
2014-07-11 12:56:54 +01:00
}
2010-05-08 14:32:30 +01:00
foreach ( $content [ 'parameters' ] as $key => $value ) {
2010-07-16 08:12:58 +01:00
$this -> container -> setParameter ( $key , $this -> resolveServices ( $value ));
2010-05-06 12:25:53 +01:00
}
}
2010-01-04 14:26:20 +00:00
2010-12-13 00:20:21 +00:00
// extensions
$this -> loadFromExtensions ( $content );
2010-05-06 12:25:53 +01:00
// services
2014-10-13 20:09:32 +01:00
$this -> parseDefinitions ( $content , $resource );
2010-01-04 14:26:20 +00:00
}
2010-07-18 10:26:47 +01:00
/**
2014-10-13 20:09:32 +01:00
* { @ inheritdoc }
2010-07-18 10:26:47 +01:00
*/
2011-02-10 15:15:51 +00:00
public function supports ( $resource , $type = null )
2010-07-18 10:26:47 +01:00
{
2015-04-12 10:10:52 +01:00
return is_string ( $resource ) && in_array ( pathinfo ( $resource , PATHINFO_EXTENSION ), array ( 'yml' , 'yaml' ), true );
2010-07-18 10:26:47 +01:00
}
2011-02-13 18:06:41 +00:00
/**
2014-12-21 17:00:50 +00:00
* Parses all imports .
2011-02-13 18:06:41 +00:00
*
2012-05-18 18:41:48 +01:00
* @ param array $content
2011-03-04 14:26:00 +00:00
* @ param string $file
2011-02-13 18:06:41 +00:00
*/
2011-03-11 13:50:46 +00:00
private function parseImports ( $content , $file )
2010-01-04 14:26:20 +00:00
{
2010-05-07 15:09:11 +01:00
if ( ! isset ( $content [ 'imports' ])) {
2010-05-06 12:25:53 +01:00
return ;
}
2010-01-04 14:26:20 +00:00
2014-07-11 12:56:54 +01:00
if ( ! is_array ( $content [ 'imports' ])) {
throw new InvalidArgumentException ( sprintf ( 'The "imports" key should contain an array in %s. Check your YAML syntax.' , $file ));
}
2016-01-06 13:34:50 +00:00
$defaultDirectory = dirname ( $file );
2010-05-07 15:09:11 +01:00
foreach ( $content [ 'imports' ] as $import ) {
2014-07-11 12:56:54 +01:00
if ( ! is_array ( $import )) {
throw new InvalidArgumentException ( sprintf ( 'The values in the "imports" key should be arrays in %s. Check your YAML syntax.' , $file ));
}
2016-01-06 13:34:50 +00:00
$this -> setCurrentDir ( $defaultDirectory );
2014-04-12 18:44:00 +01:00
$this -> import ( $import [ 'resource' ], null , isset ( $import [ 'ignore_errors' ]) ? ( bool ) $import [ 'ignore_errors' ] : false , $file );
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
}
2011-02-13 18:06:41 +00:00
/**
2014-12-21 17:00:50 +00:00
* Parses definitions .
2011-02-13 18:06:41 +00:00
*
2012-05-18 18:41:48 +01:00
* @ param array $content
2011-03-04 14:26:00 +00:00
* @ param string $file
2011-02-13 18:06:41 +00:00
*/
2011-03-11 13:50:46 +00:00
private function parseDefinitions ( $content , $file )
2010-01-04 14:26:20 +00:00
{
2010-05-07 15:09:11 +01:00
if ( ! isset ( $content [ 'services' ])) {
2010-05-06 12:25:53 +01:00
return ;
}
2010-01-04 14:26:20 +00:00
2014-07-11 12:56:54 +01:00
if ( ! is_array ( $content [ 'services' ])) {
throw new InvalidArgumentException ( sprintf ( 'The "services" key should contain an array in %s. Check your YAML syntax.' , $file ));
}
2010-05-07 15:09:11 +01:00
foreach ( $content [ 'services' ] as $id => $service ) {
2010-07-16 08:12:58 +01:00
$this -> parseDefinition ( $id , $service , $file );
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
}
2011-02-13 18:06:41 +00:00
/**
* Parses a definition .
*
2011-03-04 14:26:00 +00:00
* @ param string $id
2012-05-18 18:41:48 +01:00
* @ param array $service
2011-03-04 14:26:00 +00:00
* @ param string $file
2011-12-13 07:50:54 +00:00
*
2012-09-07 23:56:45 +01:00
* @ throws InvalidArgumentException When tags are invalid
2011-02-13 18:06:41 +00:00
*/
2011-03-11 13:50:46 +00:00
private function parseDefinition ( $id , $service , $file )
2010-01-04 14:26:20 +00:00
{
2010-05-07 15:09:11 +01:00
if ( is_string ( $service ) && 0 === strpos ( $service , '@' )) {
2010-07-16 08:12:58 +01:00
$this -> container -> setAlias ( $id , substr ( $service , 1 ));
2010-01-04 14:26:20 +00:00
2011-01-07 14:44:29 +00:00
return ;
2014-07-11 12:56:54 +01:00
}
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 ));
}
2015-12-24 15:17:45 +00:00
static :: checkDefinition ( $id , $service , $file );
2014-07-11 12:56:54 +01:00
if ( isset ( $service [ 'alias' ])) {
2014-04-12 18:44:00 +01:00
$public = ! array_key_exists ( 'public' , $service ) || ( bool ) $service [ 'public' ];
2011-01-07 14:44:29 +00:00
$this -> container -> setAlias ( $id , new Alias ( $service [ 'alias' ], $public ));
2016-01-09 18:39:03 +00:00
foreach ( $service as $key => $value ) {
if ( ! in_array ( $key , array ( 'alias' , 'public' ))) {
@ trigger_error ( sprintf ( 'The configuration key "%s" is unsupported for alias definition "%s" in "%s". Allowed configuration keys 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 );
}
}
2010-05-06 12:25:53 +01:00
return ;
}
2010-01-04 14:26:20 +00:00
2011-01-26 23:14:31 +00:00
if ( isset ( $service [ 'parent' ])) {
$definition = new DefinitionDecorator ( $service [ 'parent' ]);
} else {
$definition = new Definition ();
}
2010-07-04 17:56:48 +01:00
if ( isset ( $service [ 'class' ])) {
$definition -> setClass ( $service [ 'class' ]);
}
2010-01-04 14:26:20 +00:00
2015-06-15 03:41:59 +01:00
if ( isset ( $service [ 'shared' ])) {
$definition -> setShared ( $service [ 'shared' ]);
}
2011-01-23 11:06:23 +00:00
if ( isset ( $service [ 'synthetic' ])) {
$definition -> setSynthetic ( $service [ 'synthetic' ]);
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
2013-03-29 23:21:12 +00:00
if ( isset ( $service [ 'lazy' ])) {
$definition -> setLazy ( $service [ 'lazy' ]);
}
2010-12-29 19:12:24 +00:00
if ( isset ( $service [ 'public' ])) {
$definition -> setPublic ( $service [ 'public' ]);
}
2011-01-26 23:14:31 +00:00
if ( isset ( $service [ 'abstract' ])) {
$definition -> setAbstract ( $service [ 'abstract' ]);
}
2015-08-10 13:35:12 +01:00
if ( array_key_exists ( 'deprecated' , $service )) {
$definition -> setDeprecated ( true , $service [ 'deprecated' ]);
2015-08-07 16:13:16 +01:00
}
2014-04-13 16:18:39 +01:00
if ( isset ( $service [ 'factory' ])) {
if ( is_string ( $service [ 'factory' ])) {
2014-09-27 17:06:30 +01:00
if ( strpos ( $service [ 'factory' ], ':' ) !== false && strpos ( $service [ 'factory' ], '::' ) === false ) {
2014-04-13 16:18:39 +01:00
$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 ]));
}
}
2010-05-07 15:09:11 +01:00
if ( isset ( $service [ 'file' ])) {
2010-05-06 12:25:53 +01:00
$definition -> setFile ( $service [ 'file' ]);
}
2010-01-04 14:26:20 +00:00
2010-05-07 15:09:11 +01:00
if ( isset ( $service [ 'arguments' ])) {
2010-05-06 12:25:53 +01:00
$definition -> setArguments ( $this -> resolveServices ( $service [ 'arguments' ]));
}
2010-02-09 08:45:23 +00:00
2011-03-04 14:26:00 +00:00
if ( isset ( $service [ 'properties' ])) {
$definition -> setProperties ( $this -> resolveServices ( $service [ 'properties' ]));
}
2010-05-07 15:09:11 +01:00
if ( isset ( $service [ 'configurator' ])) {
2010-05-08 14:32:30 +01:00
if ( is_string ( $service [ 'configurator' ])) {
2010-05-06 12:25:53 +01:00
$definition -> setConfigurator ( $service [ 'configurator' ]);
2010-05-07 15:09:11 +01:00
} else {
2010-05-06 12:25:53 +01:00
$definition -> setConfigurator ( array ( $this -> resolveServices ( $service [ 'configurator' ][ 0 ]), $service [ 'configurator' ][ 1 ]));
}
}
2010-02-09 08:45:23 +00:00
2010-05-07 15:09:11 +01:00
if ( isset ( $service [ 'calls' ])) {
2014-07-11 12:56:54 +01:00
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 ));
}
2010-05-08 14:32:30 +01:00
foreach ( $service [ 'calls' ] as $call ) {
2015-03-10 15:26:38 +00:00
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 );
2010-05-06 12:25:53 +01:00
}
}
2010-01-04 14:26:20 +00:00
2010-08-05 06:34:53 +01:00
if ( isset ( $service [ 'tags' ])) {
2011-02-17 14:31:50 +00:00
if ( ! is_array ( $service [ 'tags' ])) {
2014-07-11 12:56:54 +01:00
throw new InvalidArgumentException ( sprintf ( 'Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.' , $id , $file ));
2011-02-17 14:31:50 +00:00
}
2010-08-05 06:34:53 +01:00
foreach ( $service [ 'tags' ] as $tag ) {
2014-07-11 12:56:54 +01:00
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 ));
}
2011-02-17 14:31:50 +00:00
if ( ! isset ( $tag [ 'name' ])) {
2011-12-04 23:51:22 +00:00
throw new InvalidArgumentException ( sprintf ( 'A "tags" entry is missing a "name" key for service "%s" in %s.' , $id , $file ));
2011-02-17 14:31:50 +00:00
}
2015-12-10 21:20:42 +00:00
if ( ! is_string ( $tag [ 'name' ]) || '' === $tag [ 'name' ]) {
throw new InvalidArgumentException ( sprintf ( 'The tag name for service "%s" in %s must be a non-empty string.' , $id , $file ));
}
2010-08-05 06:34:53 +01:00
$name = $tag [ 'name' ];
unset ( $tag [ 'name' ]);
2010-01-04 14:26:20 +00:00
2012-04-13 15:48:30 +01:00
foreach ( $tag as $attribute => $value ) {
2013-09-15 19:46:31 +01:00
if ( ! is_scalar ( $value ) && null !== $value ) {
2014-09-17 10:45:32 +01:00
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 ));
2012-04-13 15:48:30 +01:00
}
}
2010-08-05 06:34:53 +01:00
$definition -> addTag ( $name , $tag );
2010-05-06 12:25:53 +01:00
}
}
2014-03-31 16:58:40 +01:00
if ( isset ( $service [ 'decorates' ])) {
2016-02-04 14:21:55 +00:00
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 )));
}
2014-04-10 13:44:40 +01:00
$renameId = isset ( $service [ 'decoration_inner_name' ]) ? $service [ 'decoration_inner_name' ] : null ;
2015-07-31 02:41:40 +01:00
$priority = isset ( $service [ 'decoration_priority' ]) ? $service [ 'decoration_priority' ] : 0 ;
$definition -> setDecoratedService ( $service [ 'decorates' ], $renameId , $priority );
2014-03-31 16:58:40 +01:00
}
2015-08-24 02:36:41 +01:00
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 );
}
}
}
2010-07-16 08:12:58 +01:00
$this -> container -> setDefinition ( $id , $definition );
2010-01-04 14:26:20 +00:00
}
2011-02-13 18:06:41 +00:00
/**
* Loads a YAML file .
*
2011-03-04 14:26:00 +00:00
* @ param string $file
2011-12-13 07:50:54 +00:00
*
2011-02-13 18:06:41 +00:00
* @ return array The file content
2014-07-26 13:09:47 +01:00
*
* @ throws InvalidArgumentException when the given file is not a local file or when it does not exist
2011-02-13 18:06:41 +00:00
*/
2012-11-11 11:59:36 +00:00
protected function loadFile ( $file )
2010-01-04 14:26:20 +00:00
{
2015-04-06 14:14:07 +01:00
if ( ! class_exists ( 'Symfony\Component\Yaml\Parser' )) {
throw new RuntimeException ( 'Unable to load YAML config files as the Symfony Yaml Component is not installed.' );
}
2013-05-05 10:27:54 +01:00
if ( ! stream_is_local ( $file )) {
throw new InvalidArgumentException ( sprintf ( 'This is not a local file "%s".' , $file ));
}
if ( ! file_exists ( $file )) {
throw new InvalidArgumentException ( sprintf ( 'The service file "%s" is not valid.' , $file ));
}
if ( null === $this -> yamlParser ) {
$this -> yamlParser = new YamlParser ();
}
2015-09-08 20:57:35 +01:00
try {
$configuration = $this -> yamlParser -> parse ( file_get_contents ( $file ));
} catch ( ParseException $e ) {
2015-09-10 08:57:42 +01:00
throw new InvalidArgumentException ( sprintf ( 'The file "%s" does not contain valid YAML.' , $file ), 0 , $e );
2015-09-08 20:57:35 +01:00
}
return $this -> validate ( $configuration , $file );
2010-01-04 14:26:20 +00:00
}
2010-05-06 12:25:53 +01:00
/**
2011-02-13 18:06:41 +00:00
* Validates a YAML file .
*
2012-05-18 18:41:48 +01:00
* @ param mixed $content
2011-02-13 18:06:41 +00:00
* @ param string $file
2011-12-13 07:50:54 +00:00
*
2011-02-13 18:06:41 +00:00
* @ return array
*
2011-12-04 23:51:22 +00:00
* @ throws InvalidArgumentException When service file is not valid
2010-05-06 12:25:53 +01:00
*/
2011-03-11 13:50:46 +00:00
private function validate ( $content , $file )
2010-01-04 14:26:20 +00:00
{
2010-05-07 15:09:11 +01:00
if ( null === $content ) {
2010-05-06 12:25:53 +01:00
return $content ;
2010-01-04 14:26:20 +00:00
}
2010-05-07 15:09:11 +01:00
if ( ! is_array ( $content )) {
2014-07-11 12:56:54 +01:00
throw new InvalidArgumentException ( sprintf ( 'The service file "%s" is not valid. It should contain an array. Check your YAML syntax.' , $file ));
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
2015-04-09 15:55:17 +01:00
foreach ( $content as $namespace => $data ) {
2011-04-23 10:42:31 +01:00
if ( in_array ( $namespace , array ( 'imports' , 'parameters' , 'services' ))) {
2010-05-06 12:25:53 +01:00
continue ;
}
2011-02-05 18:42:07 +00:00
if ( ! $this -> container -> hasExtension ( $namespace )) {
2011-07-06 14:26:21 +01:00
$extensionNamespaces = array_filter ( array_map ( function ( $ext ) { return $ext -> getAlias (); }, $this -> container -> getExtensions ()));
2011-12-04 23:51:22 +00:00
throw new InvalidArgumentException ( sprintf (
2011-07-06 14:26:21 +01:00
'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'
));
2010-05-06 12:25:53 +01:00
}
}
2010-01-04 14:26:20 +00:00
2010-05-06 12:25:53 +01:00
return $content ;
2010-01-04 14:26:20 +00:00
}
2010-05-06 12:25:53 +01:00
2011-02-13 18:06:41 +00:00
/**
* Resolves services .
*
2014-07-11 12:56:54 +01:00
* @ param string | array $value
2011-12-13 07:50:54 +00:00
*
2014-07-11 12:56:54 +01:00
* @ return array | string | Reference
2011-02-13 18:06:41 +00:00
*/
2011-03-11 13:50:46 +00:00
private function resolveServices ( $value )
2010-01-04 14:26:20 +00:00
{
2010-05-07 15:09:11 +01:00
if ( is_array ( $value )) {
2010-05-06 12:25:53 +01:00
$value = array_map ( array ( $this , 'resolveServices' ), $value );
2013-09-02 11:46:47 +01:00
} elseif ( is_string ( $value ) && 0 === strpos ( $value , '@=' )) {
return new Expression ( substr ( $value , 2 ));
2011-12-18 13:42:59 +00:00
} elseif ( is_string ( $value ) && 0 === strpos ( $value , '@' )) {
2013-03-08 15:38:09 +00:00
if ( 0 === strpos ( $value , '@@' )) {
$value = substr ( $value , 1 );
$invalidBehavior = null ;
} elseif ( 0 === strpos ( $value , '@?' )) {
2011-01-17 22:28:59 +00:00
$value = substr ( $value , 2 );
$invalidBehavior = ContainerInterface :: IGNORE_ON_INVALID_REFERENCE ;
} else {
$value = substr ( $value , 1 );
$invalidBehavior = ContainerInterface :: EXCEPTION_ON_INVALID_REFERENCE ;
}
if ( '=' === substr ( $value , - 1 )) {
$value = substr ( $value , 0 , - 1 );
$strict = false ;
} else {
$strict = true ;
}
2013-03-08 15:38:09 +00:00
if ( null !== $invalidBehavior ) {
$value = new Reference ( $value , $invalidBehavior , $strict );
}
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
2010-05-06 12:25:53 +01:00
return $value ;
}
2010-01-04 14:26:20 +00:00
2011-02-13 18:06:41 +00:00
/**
2014-12-21 17:00:50 +00:00
* Loads from Extensions .
2011-02-13 18:06:41 +00:00
*
2011-03-04 14:26:00 +00:00
* @ param array $content
2011-02-13 18:06:41 +00:00
*/
2011-03-11 13:50:46 +00:00
private function loadFromExtensions ( $content )
2010-01-04 14:26:20 +00:00
{
2011-02-05 18:42:07 +00:00
foreach ( $content as $namespace => $values ) {
2011-04-23 10:42:31 +01:00
if ( in_array ( $namespace , array ( 'imports' , 'parameters' , 'services' ))) {
2010-05-06 12:25:53 +01:00
continue ;
}
2010-01-04 14:26:20 +00:00
2010-05-07 15:09:11 +01:00
if ( ! is_array ( $values )) {
2010-05-06 12:25:53 +01:00
$values = array ();
}
2010-01-04 14:26:20 +00:00
2011-02-05 18:42:07 +00:00
$this -> container -> loadFromExtension ( $namespace , $values );
2010-05-06 12:25:53 +01:00
}
2010-01-04 14:26:20 +00:00
}
2015-12-24 15:17:45 +00:00
/**
* 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 static function checkDefinition ( $id , array $definition , $file )
{
foreach ( $definition as $key => $value ) {
if ( ! isset ( static :: $keywords [ $key ])) {
@ 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 ( '", "' , static :: $keywords )), E_USER_DEPRECATED );
// @deprecated Uncomment the following statement in Symfony 4.0
// and also update the corresponding unit test to make it expect
// an InvalidArgumentException exception.
//throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for service definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', static::$keywords)));
}
}
}
2010-01-04 14:26:20 +00:00
}