2010-02-17 13:55:05 +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-07-09 09:05:26 +01:00
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection ;
2010-02-17 13:55:05 +00:00
2016-02-21 18:44:16 +00:00
use Doctrine\Common\Annotations\Reader ;
2017-12-10 21:39:54 +00:00
use Doctrine\Common\Annotations\AnnotationRegistry ;
2016-11-04 20:47:40 +00:00
use Symfony\Bridge\Monolog\Processor\DebugProcessor ;
2017-03-31 11:45:36 +01:00
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController ;
use Symfony\Bundle\FrameworkBundle\Controller\Controller ;
2017-06-02 19:02:43 +01:00
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader ;
2017-12-15 05:43:42 +00:00
use Symfony\Bundle\FullStack ;
2017-09-28 18:35:07 +01:00
use Symfony\Component\Cache\Adapter\AbstractAdapter ;
2015-12-04 22:03:03 +00:00
use Symfony\Component\Cache\Adapter\AdapterInterface ;
2017-03-08 19:24:49 +00:00
use Symfony\Component\Cache\Adapter\ArrayAdapter ;
2017-09-15 21:03:33 +01:00
use Symfony\Component\Cache\ResettableInterface ;
2017-04-04 12:58:36 +01:00
use Symfony\Component\Config\FileLocator ;
2016-12-14 21:05:29 +00:00
use Symfony\Component\Config\Loader\LoaderInterface ;
2017-03-08 10:59:12 +00:00
use Symfony\Component\Config\Resource\DirectoryResource ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Config\ResourceCheckerInterface ;
2017-04-04 12:58:36 +01:00
use Symfony\Component\Console\Application ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Console\Command\Command ;
2016-11-28 06:44:11 +00:00
use Symfony\Component\DependencyInjection\Alias ;
2018-01-05 12:03:30 +00:00
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument ;
2016-11-28 07:50:06 +00:00
use Symfony\Component\DependencyInjection\ChildDefinition ;
2010-08-20 22:09:55 +01:00
use Symfony\Component\DependencyInjection\ContainerBuilder ;
2013-09-04 16:33:26 +01:00
use Symfony\Component\DependencyInjection\ContainerInterface ;
2014-12-25 03:17:33 +00:00
use Symfony\Component\DependencyInjection\Definition ;
2016-10-22 17:25:15 +01:00
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface ;
2017-01-29 19:47:50 +00:00
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException ;
2014-09-03 13:55:20 +01:00
use Symfony\Component\DependencyInjection\Exception\LogicException ;
2011-01-24 19:50:31 +00:00
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader ;
2018-01-03 11:52:04 +00:00
use Symfony\Component\DependencyInjection\Parameter ;
2017-12-03 14:58:49 +00:00
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface ;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\DependencyInjection\Reference ;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface ;
use Symfony\Component\EventDispatcher\EventSubscriberInterface ;
2017-03-17 13:38:55 +00:00
use Symfony\Component\ExpressionLanguage\ExpressionLanguage ;
2010-09-27 08:46:15 +01:00
use Symfony\Component\Finder\Finder ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Form\FormTypeGuesserInterface ;
use Symfony\Component\Form\FormTypeInterface ;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface ;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface ;
2017-07-30 15:50:35 +01:00
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface ;
2011-01-16 09:17:38 +00:00
use Symfony\Component\HttpKernel\DependencyInjection\Extension ;
2017-01-29 19:47:50 +00:00
use Symfony\Component\Lock\Factory ;
use Symfony\Component\Lock\Lock ;
use Symfony\Component\Lock\LockInterface ;
use Symfony\Component\Lock\Store\StoreFactory ;
use Symfony\Component\Lock\StoreInterface ;
2015-12-04 22:03:03 +00:00
use Symfony\Component\PropertyAccess\PropertyAccessor ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface ;
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface ;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface ;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface ;
2017-06-02 19:02:43 +01:00
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader ;
use Symfony\Component\Routing\Loader\AnnotationFileLoader ;
2017-07-21 19:01:38 +01:00
use Symfony\Component\Security\Core\Security ;
2017-12-15 05:43:42 +00:00
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface ;
2017-05-19 16:54:24 +01:00
use Symfony\Component\Serializer\Encoder\DecoderInterface ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Serializer\Encoder\EncoderInterface ;
2017-04-15 17:59:12 +01:00
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata ;
2016-04-25 18:10:03 +01:00
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory ;
2017-08-01 16:22:43 +01:00
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer ;
2017-05-19 16:54:24 +01:00
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Serializer\Normalizer\NormalizerInterface ;
2017-06-12 15:27:27 +01:00
use Symfony\Component\Stopwatch\Stopwatch ;
2017-08-06 11:59:30 +01:00
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand ;
2017-09-24 10:13:45 +01:00
use Symfony\Component\Translation\Translator ;
2017-03-31 11:45:36 +01:00
use Symfony\Component\Validator\ConstraintValidatorInterface ;
use Symfony\Component\Validator\ObjectInitializerInterface ;
2017-04-04 12:58:36 +01:00
use Symfony\Component\WebLink\HttpHeaderSerializer ;
2016-03-25 15:43:30 +00:00
use Symfony\Component\Workflow ;
2017-08-06 11:59:30 +01:00
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand ;
2017-11-27 17:35:30 +00:00
use Symfony\Component\Yaml\Yaml ;
2010-02-17 13:55:05 +00:00
/**
2010-09-20 20:01:41 +01:00
* FrameworkExtension .
2010-02-17 13:55:05 +00:00
*
2011-03-06 11:40:06 +00:00
* @ author Fabien Potencier < fabien @ symfony . com >
2011-01-24 19:50:31 +00:00
* @ author Jeremy Mikola < jmikola @ gmail . com >
2014-12-25 03:17:33 +00:00
* @ author Kévin Dunglas < dunglas @ gmail . com >
2016-03-25 15:43:30 +00:00
* @ author Grégoire Pineau < lyrixx @ lyrixx . info >
2010-02-17 13:55:05 +00:00
*/
2010-09-20 20:01:41 +01:00
class FrameworkExtension extends Extension
2010-02-17 13:55:05 +00:00
{
2013-09-26 14:56:56 +01:00
private $formConfigEnabled = false ;
2015-03-20 23:12:36 +00:00
private $translationConfigEnabled = false ;
2013-10-09 09:42:58 +01:00
private $sessionConfigEnabled = false ;
2016-09-30 00:48:22 +01:00
private $annotationsConfigEnabled = false ;
2017-04-27 16:08:18 +01:00
private $validatorConfigEnabled = false ;
2013-09-26 14:56:56 +01:00
2015-12-10 10:46:31 +00:00
/**
* @ var string | null
*/
private $kernelRootHash ;
2010-06-07 08:08:35 +01:00
/**
2011-01-24 19:50:31 +00:00
* Responds to the app . config configuration parameter .
2010-06-07 08:08:35 +01:00
*
2014-12-25 10:36:58 +00:00
* @ throws LogicException
2010-06-07 08:08:35 +01:00
*/
2011-02-15 04:58:18 +00:00
public function load ( array $configs , ContainerBuilder $container )
2010-02-24 14:42:04 +00:00
{
2016-10-25 09:15:38 +01:00
$loader = new XmlFileLoader ( $container , new FileLocator ( dirname ( __DIR__ ) . '/Resources/config' ));
2010-07-17 16:40:38 +01:00
2011-01-24 19:50:31 +00:00
$loader -> load ( 'web.xml' );
$loader -> load ( 'services.xml' );
2013-01-31 09:37:27 +00:00
$loader -> load ( 'fragment_renderer.xml' );
2010-10-25 15:55:20 +01:00
2017-12-03 14:58:49 +00:00
if ( ! interface_exists ( ContainerBagInterface :: class )) {
$container -> removeDefinition ( 'parameter_bag' );
$container -> removeAlias ( ContainerBagInterface :: class );
$container -> removeAlias ( ParameterBagInterface :: class );
}
2016-12-20 19:36:42 +00:00
if ( class_exists ( Application :: class )) {
$loader -> load ( 'console.xml' );
2017-08-06 11:59:30 +01:00
if ( ! class_exists ( BaseXliffLintCommand :: class )) {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.xliff_lint' );
2017-08-06 11:59:30 +01:00
}
if ( ! class_exists ( BaseYamlLintCommand :: class )) {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.yaml_lint' );
2017-08-06 11:59:30 +01:00
}
2016-12-20 19:36:42 +00:00
}
2010-10-25 15:55:20 +01:00
2016-04-14 11:03:03 +01:00
// Load Cache configuration first as it is used by other components
2016-04-28 17:07:16 +01:00
$loader -> load ( 'cache.xml' );
2016-04-14 11:03:03 +01:00
2011-05-21 19:33:02 +01:00
$configuration = $this -> getConfiguration ( $configs , $container );
2011-07-18 16:46:00 +01:00
$config = $this -> processConfiguration ( $configuration , $configs );
2010-09-15 19:49:16 +01:00
2016-09-30 00:48:22 +01:00
$this -> annotationsConfigEnabled = $this -> isConfigEnabled ( $container , $config [ 'annotations' ]);
2017-03-15 10:56:07 +00:00
$this -> translationConfigEnabled = $this -> isConfigEnabled ( $container , $config [ 'translator' ]);
2016-09-30 00:48:22 +01:00
2016-09-28 05:49:39 +01:00
// A translator must always be registered (as support is included by
2016-12-14 21:05:29 +00:00
// default in the Form and Validator component). If disabled, an identity
// translator will be used and everything will still work as expected.
if ( $this -> isConfigEnabled ( $container , $config [ 'translator' ]) || $this -> isConfigEnabled ( $container , $config [ 'form' ]) || $this -> isConfigEnabled ( $container , $config [ 'validation' ])) {
if ( ! class_exists ( 'Symfony\Component\Translation\Translator' ) && $this -> isConfigEnabled ( $container , $config [ 'translator' ])) {
throw new LogicException ( 'Translation support cannot be enabled as the Translation component is not installed.' );
}
2017-09-24 10:13:45 +01:00
if ( class_exists ( Translator :: class )) {
$loader -> load ( 'identity_translator.xml' );
}
2016-09-28 05:49:39 +01:00
}
2012-09-29 19:56:08 +01:00
if ( isset ( $config [ 'secret' ])) {
$container -> setParameter ( 'kernel.secret' , $config [ 'secret' ]);
}
2011-02-06 20:29:13 +00:00
2013-02-27 13:12:14 +00:00
$container -> setParameter ( 'kernel.http_method_override' , $config [ 'http_method_override' ]);
2013-08-06 08:14:49 +01:00
$container -> setParameter ( 'kernel.trusted_hosts' , $config [ 'trusted_hosts' ]);
2011-10-05 10:09:51 +01:00
$container -> setParameter ( 'kernel.default_locale' , $config [ 'default_locale' ]);
2016-08-31 09:43:03 +01:00
if ( ! $container -> hasParameter ( 'debug.file_link_format' )) {
if ( ! $container -> hasParameter ( 'templating.helper.code.file_link_format' )) {
$links = array (
'textmate' => 'txmt://open?url=file://%%f&line=%%l' ,
'macvim' => 'mvim://open?url=file://%%f&line=%%l' ,
'emacs' => 'emacs://open?url=file://%%f&line=%%l' ,
'sublime' => 'subl://open?url=file://%%f&line=%%l' ,
2017-03-01 14:46:28 +00:00
'phpstorm' => 'phpstorm://open?file=%%f&line=%%l' ,
2017-12-10 09:05:02 +00:00
'atom' => 'atom://core/open/file?filename=%%f&line=%%l' ,
2016-08-31 09:43:03 +01:00
);
$ide = $config [ 'ide' ];
$container -> setParameter ( 'templating.helper.code.file_link_format' , str_replace ( '%' , '%%' , ini_get ( 'xdebug.file_link_format' ) ? : get_cfg_var ( 'xdebug.file_link_format' )) ? : ( isset ( $links [ $ide ]) ? $links [ $ide ] : $ide ));
}
$container -> setParameter ( 'debug.file_link_format' , '%templating.helper.code.file_link_format%' );
}
2011-02-10 20:40:00 +00:00
if ( ! empty ( $config [ 'test' ])) {
2011-01-24 19:50:31 +00:00
$loader -> load ( 'test.xml' );
2011-01-24 10:16:22 +00:00
}
2016-02-04 17:27:46 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'session' ])) {
2013-10-09 09:42:58 +01:00
$this -> sessionConfigEnabled = true ;
2011-05-18 12:14:51 +01:00
$this -> registerSessionConfiguration ( $config [ 'session' ], $container , $loader );
}
2016-02-04 17:27:46 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'request' ])) {
2013-12-25 21:24:54 +00:00
$this -> registerRequestConfiguration ( $config [ 'request' ], $container , $loader );
}
2017-12-15 05:43:42 +00:00
if ( null === $config [ 'csrf_protection' ][ 'enabled' ]) {
$config [ 'csrf_protection' ][ 'enabled' ] = $this -> sessionConfigEnabled && ! class_exists ( FullStack :: class ) && interface_exists ( CsrfTokenManagerInterface :: class );
}
$this -> registerSecurityCsrfConfiguration ( $config [ 'csrf_protection' ], $container , $loader );
2013-01-23 14:18:20 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'form' ])) {
2017-11-21 23:40:17 +00:00
if ( ! class_exists ( 'Symfony\Component\Form\Form' )) {
throw new LogicException ( 'Form support cannot be enabled as the Form component is not installed.' );
}
2013-09-26 14:56:56 +01:00
$this -> formConfigEnabled = true ;
2011-05-18 12:14:51 +01:00
$this -> registerFormConfiguration ( $config , $container , $loader );
2013-11-30 10:58:54 +00:00
2017-11-04 21:11:56 +00:00
if ( class_exists ( 'Symfony\Component\Validator\Validation' )) {
$config [ 'validation' ][ 'enabled' ] = true ;
} else {
2017-09-24 10:13:45 +01:00
$container -> setParameter ( 'validator.translation_domain' , 'validators' );
$container -> removeDefinition ( 'form.type_extension.form.validator' );
$container -> removeDefinition ( 'form.type_guesser.validator' );
2014-09-03 13:55:20 +01:00
}
2017-07-27 14:45:21 +01:00
} else {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.form_debug' );
2011-05-18 12:14:51 +01:00
}
2016-02-04 17:27:46 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'assets' ])) {
2016-09-28 05:29:33 +01:00
if ( ! class_exists ( 'Symfony\Component\Asset\Package' )) {
throw new LogicException ( 'Asset support cannot be enabled as the Asset component is not installed.' );
}
2014-12-28 18:57:17 +00:00
$this -> registerAssetsConfiguration ( $config [ 'assets' ], $container , $loader );
}
2016-02-04 17:27:46 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'templating' ])) {
2016-09-28 16:50:27 +01:00
if ( ! class_exists ( 'Symfony\Component\Templating\PhpEngine' )) {
throw new LogicException ( 'Templating support cannot be enabled as the Templating component is not installed.' );
}
2016-08-31 09:43:03 +01:00
$this -> registerTemplatingConfiguration ( $config [ 'templating' ], $container , $loader );
2013-01-22 09:24:26 +00:00
}
2013-01-23 14:18:20 +00:00
$this -> registerValidationConfiguration ( $config [ 'validation' ], $container , $loader );
$this -> registerEsiConfiguration ( $config [ 'esi' ], $container , $loader );
2014-03-23 00:04:57 +00:00
$this -> registerSsiConfiguration ( $config [ 'ssi' ], $container , $loader );
2013-01-31 09:37:27 +00:00
$this -> registerFragmentsConfiguration ( $config [ 'fragments' ], $container , $loader );
2016-12-14 21:05:29 +00:00
$this -> registerTranslatorConfiguration ( $config [ 'translator' ], $container , $loader );
2015-03-20 23:12:36 +00:00
$this -> registerProfilerConfiguration ( $config [ 'profiler' ], $container , $loader );
2016-06-07 15:56:06 +01:00
$this -> registerCacheConfiguration ( $config [ 'cache' ], $container );
2016-03-25 15:43:30 +00:00
$this -> registerWorkflowConfiguration ( $config [ 'workflows' ], $container , $loader );
2016-08-08 14:40:30 +01:00
$this -> registerDebugConfiguration ( $config [ 'php_errors' ], $container , $loader );
2017-07-22 10:58:19 +01:00
$this -> registerRouterConfiguration ( $config [ 'router' ], $container , $loader );
2011-05-03 13:36:42 +01:00
$this -> registerAnnotationsConfiguration ( $config [ 'annotations' ], $container , $loader );
2017-10-18 15:30:35 +01:00
$this -> registerPropertyAccessConfiguration ( $config [ 'property_access' ], $container , $loader );
2014-08-21 18:05:54 +01:00
2016-06-23 18:03:12 +01:00
if ( $this -> isConfigEnabled ( $container , $config [ 'serializer' ])) {
2017-11-21 23:40:17 +00:00
if ( ! class_exists ( 'Symfony\Component\Serializer\Serializer' )) {
throw new LogicException ( 'Serializer support cannot be enabled as the Serializer component is not installed.' );
}
2014-12-25 03:17:33 +00:00
$this -> registerSerializerConfiguration ( $config [ 'serializer' ], $container , $loader );
2013-01-20 18:39:49 +00:00
}
2016-06-23 18:03:12 +01:00
if ( $this -> isConfigEnabled ( $container , $config [ 'property_info' ])) {
2015-09-28 12:22:50 +01:00
$this -> registerPropertyInfoConfiguration ( $config [ 'property_info' ], $container , $loader );
}
2017-01-29 19:47:50 +00:00
if ( $this -> isConfigEnabled ( $container , $config [ 'lock' ])) {
$this -> registerLockConfiguration ( $config [ 'lock' ], $container , $loader );
}
2017-04-04 12:58:36 +01:00
if ( $this -> isConfigEnabled ( $container , $config [ 'web_link' ])) {
if ( ! class_exists ( HttpHeaderSerializer :: class )) {
throw new LogicException ( 'WebLink support cannot be enabled as the WebLink component is not installed.' );
}
$loader -> load ( 'web_link.xml' );
}
2016-06-28 13:49:00 +01:00
$this -> addAnnotatedClassesToCompile ( array (
2017-08-03 12:53:37 +01:00
'**\\Controller\\' ,
'**\\Entity\\' ,
2016-06-28 13:49:00 +01:00
// Added explicitly so that we don't rely on the class map being dumped to make it work
2017-11-09 12:35:46 +00:00
'Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController' ,
2016-06-28 13:49:00 +01:00
'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller' ,
));
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( Command :: class )
-> addTag ( 'console.command' );
$container -> registerForAutoconfiguration ( ResourceCheckerInterface :: class )
-> addTag ( 'config_cache.resource_checker' );
2016-10-22 17:25:15 +01:00
$container -> registerForAutoconfiguration ( EnvVarProcessorInterface :: class )
-> addTag ( 'container.env_var_processor' );
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( ServiceSubscriberInterface :: class )
-> addTag ( 'container.service_subscriber' );
2017-07-30 15:50:35 +01:00
$container -> registerForAutoconfiguration ( ArgumentValueResolverInterface :: class )
-> addTag ( 'controller.argument_value_resolver' );
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( AbstractController :: class )
-> addTag ( 'controller.service_arguments' );
$container -> registerForAutoconfiguration ( Controller :: class )
-> addTag ( 'controller.service_arguments' );
$container -> registerForAutoconfiguration ( DataCollectorInterface :: class )
-> addTag ( 'data_collector' );
$container -> registerForAutoconfiguration ( FormTypeInterface :: class )
-> addTag ( 'form.type' );
$container -> registerForAutoconfiguration ( FormTypeGuesserInterface :: class )
-> addTag ( 'form.type_guesser' );
$container -> registerForAutoconfiguration ( CacheClearerInterface :: class )
-> addTag ( 'kernel.cache_clearer' );
$container -> registerForAutoconfiguration ( CacheWarmerInterface :: class )
-> addTag ( 'kernel.cache_warmer' );
$container -> registerForAutoconfiguration ( EventSubscriberInterface :: class )
-> addTag ( 'kernel.event_subscriber' );
2017-09-15 21:03:33 +01:00
$container -> registerForAutoconfiguration ( ResettableInterface :: class )
-> addTag ( 'kernel.reset' , array ( 'method' => 'reset' ));
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( PropertyListExtractorInterface :: class )
-> addTag ( 'property_info.list_extractor' );
$container -> registerForAutoconfiguration ( PropertyTypeExtractorInterface :: class )
-> addTag ( 'property_info.type_extractor' );
$container -> registerForAutoconfiguration ( PropertyDescriptionExtractorInterface :: class )
-> addTag ( 'property_info.description_extractor' );
$container -> registerForAutoconfiguration ( PropertyAccessExtractorInterface :: class )
-> addTag ( 'property_info.access_extractor' );
$container -> registerForAutoconfiguration ( EncoderInterface :: class )
-> addTag ( 'serializer.encoder' );
2017-05-19 16:54:24 +01:00
$container -> registerForAutoconfiguration ( DecoderInterface :: class )
-> addTag ( 'serializer.encoder' );
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( NormalizerInterface :: class )
-> addTag ( 'serializer.normalizer' );
2017-05-19 16:54:24 +01:00
$container -> registerForAutoconfiguration ( DenormalizerInterface :: class )
-> addTag ( 'serializer.normalizer' );
2017-03-31 11:45:36 +01:00
$container -> registerForAutoconfiguration ( ConstraintValidatorInterface :: class )
-> addTag ( 'validator.constraint_validator' );
$container -> registerForAutoconfiguration ( ObjectInitializerInterface :: class )
-> addTag ( 'validator.initializer' );
2017-11-05 13:56:21 +00:00
if ( ! $container -> getParameter ( 'kernel.debug' )) {
// remove tagged iterator argument for resource checkers
$container -> getDefinition ( 'config_cache_factory' ) -> setArguments ( array ());
}
2010-02-17 13:55:05 +00:00
}
2014-05-10 23:14:12 +01:00
/**
* { @ inheritdoc }
*/
public function getConfiguration ( array $config , ContainerBuilder $container )
{
return new Configuration ( $container -> getParameter ( 'kernel.debug' ));
}
2017-10-22 17:42:21 +01:00
private function registerFormConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2010-09-15 19:49:16 +01:00
{
2011-05-18 11:54:16 +01:00
$loader -> load ( 'form.xml' );
2017-09-05 12:45:10 +01:00
2015-11-10 23:41:32 +00:00
if ( null === $config [ 'form' ][ 'csrf_protection' ][ 'enabled' ]) {
$config [ 'form' ][ 'csrf_protection' ][ 'enabled' ] = $config [ 'csrf_protection' ][ 'enabled' ];
}
2013-11-30 09:53:03 +00:00
2013-10-09 09:42:58 +01:00
if ( $this -> isConfigEnabled ( $container , $config [ 'form' ][ 'csrf_protection' ])) {
2011-05-18 11:54:16 +01:00
$loader -> load ( 'form_csrf.xml' );
2013-01-23 14:18:20 +00:00
$container -> setParameter ( 'form.type_extension.csrf.enabled' , true );
2015-09-04 21:24:52 +01:00
$container -> setParameter ( 'form.type_extension.csrf.field_name' , $config [ 'form' ][ 'csrf_protection' ][ 'field_name' ]);
2013-01-23 14:18:20 +00:00
} else {
$container -> setParameter ( 'form.type_extension.csrf.enabled' , false );
2011-05-18 11:54:16 +01:00
}
2017-09-24 10:13:45 +01:00
if ( ! class_exists ( Translator :: class )) {
$container -> removeDefinition ( 'form.type_extension.upload.validator' );
}
2010-09-15 19:49:16 +01:00
}
2013-01-23 14:18:20 +00:00
private function registerEsiConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2011-01-17 15:21:46 +00:00
{
2013-01-23 14:18:20 +00:00
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2017-06-22 20:48:55 +01:00
$container -> removeDefinition ( 'fragment.renderer.esi' );
2013-01-23 14:18:20 +00:00
return ;
2011-01-17 15:21:46 +00:00
}
2013-01-23 14:18:20 +00:00
$loader -> load ( 'esi.xml' );
2011-01-17 15:21:46 +00:00
}
2014-03-23 00:04:57 +00:00
private function registerSsiConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2017-06-22 20:48:55 +01:00
$container -> removeDefinition ( 'fragment.renderer.ssi' );
2014-03-23 00:04:57 +00:00
return ;
}
$loader -> load ( 'ssi.xml' );
}
2013-01-31 09:37:27 +00:00
private function registerFragmentsConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2013-01-22 09:24:26 +00:00
{
2013-01-23 14:18:20 +00:00
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2017-06-22 20:48:55 +01:00
$container -> removeDefinition ( 'fragment.renderer.hinclude' );
2013-01-23 14:18:20 +00:00
return ;
2013-01-22 09:24:26 +00:00
}
2013-01-23 14:18:20 +00:00
2013-01-31 09:37:27 +00:00
$loader -> load ( 'fragment_listener.xml' );
$container -> setParameter ( 'fragment.path' , $config [ 'path' ]);
2013-01-22 09:24:26 +00:00
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerProfilerConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2010-09-27 08:46:15 +01:00
{
2013-04-26 14:53:58 +01:00
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2013-04-26 15:27:29 +01:00
// this is needed for the WebProfiler to work even if the profiler is disabled
$container -> setParameter ( 'data_collector.templates' , array ());
2013-04-26 14:53:58 +01:00
return ;
}
2015-02-06 10:24:56 +00:00
$loader -> load ( 'profiling.xml' );
$loader -> load ( 'collectors.xml' );
2016-12-27 15:06:31 +00:00
$loader -> load ( 'cache_debug.xml' );
2015-02-06 10:24:56 +00:00
2015-03-20 23:12:36 +00:00
if ( $this -> formConfigEnabled ) {
2013-09-26 14:56:56 +01:00
$loader -> load ( 'form_debug.xml' );
}
2013-10-30 08:33:58 +00:00
2017-04-27 16:08:18 +01:00
if ( $this -> validatorConfigEnabled ) {
$loader -> load ( 'validator_debug.xml' );
}
2015-03-20 23:12:36 +00:00
if ( $this -> translationConfigEnabled ) {
$loader -> load ( 'translation_debug.xml' );
2017-09-05 12:45:10 +01:00
2015-03-20 23:12:36 +00:00
$container -> getDefinition ( 'translator.data_collector' ) -> setDecoratedService ( 'translator' );
}
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'profiler_listener.only_exceptions' , $config [ 'only_exceptions' ]);
$container -> setParameter ( 'profiler_listener.only_master_requests' , $config [ 'only_master_requests' ]);
2011-03-16 14:50:48 +00:00
// Choose storage class based on the DSN
2015-02-18 07:05:44 +00:00
list ( $class ) = explode ( ':' , $config [ 'dsn' ], 2 );
2015-09-30 13:35:12 +01:00
if ( 'file' !== $class ) {
2011-03-16 14:50:48 +00:00
throw new \LogicException ( sprintf ( 'Driver "%s" is not supported for the profiler.' , $class ));
2011-02-05 21:19:14 +00:00
}
2010-09-27 15:53:23 +01:00
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'profiler.storage.dsn' , $config [ 'dsn' ]);
2010-09-27 15:53:23 +01:00
2017-10-05 10:48:08 +01:00
$container -> getDefinition ( 'profiler' )
-> addArgument ( $config [ 'collect' ])
-> addTag ( 'kernel.reset' , array ( 'method' => 'reset' ));
2010-09-27 08:46:15 +01:00
}
2017-09-03 11:36:19 +01:00
private function registerWorkflowConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2016-03-25 15:43:30 +00:00
{
2017-09-03 11:36:19 +01:00
if ( ! $config [ 'enabled' ]) {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.workflow_dump' );
2017-07-22 10:58:19 +01:00
2016-03-25 15:43:30 +00:00
return ;
}
2017-03-17 14:04:44 +00:00
if ( ! class_exists ( Workflow\Workflow :: class )) {
throw new LogicException ( 'Workflow support cannot be enabled as the Workflow component is not installed.' );
}
2016-03-25 15:43:30 +00:00
$loader -> load ( 'workflow.xml' );
$registryDefinition = $container -> getDefinition ( 'workflow.registry' );
2017-09-03 11:36:19 +01:00
foreach ( $config [ 'workflows' ] as $name => $workflow ) {
2016-08-16 12:13:16 +01:00
$type = $workflow [ 'type' ];
2016-11-10 14:52:21 +00:00
$transitions = array ();
2016-12-06 19:04:08 +00:00
foreach ( $workflow [ 'transitions' ] as $transition ) {
2017-09-15 04:37:43 +01:00
if ( 'workflow' === $type ) {
2016-12-06 19:04:08 +00:00
$transitions [] = new Definition ( Workflow\Transition :: class , array ( $transition [ 'name' ], $transition [ 'from' ], $transition [ 'to' ]));
2017-09-15 04:37:43 +01:00
} elseif ( 'state_machine' === $type ) {
2016-08-16 12:13:16 +01:00
foreach ( $transition [ 'from' ] as $from ) {
foreach ( $transition [ 'to' ] as $to ) {
2016-12-06 19:04:08 +00:00
$transitions [] = new Definition ( Workflow\Transition :: class , array ( $transition [ 'name' ], $from , $to ));
2016-08-16 12:13:16 +01:00
}
}
}
2016-03-25 15:43:30 +00:00
}
2016-11-08 19:01:05 +00:00
// Create a Definition
$definitionDefinition = new Definition ( Workflow\Definition :: class );
$definitionDefinition -> setPublic ( false );
2016-11-10 14:52:21 +00:00
$definitionDefinition -> addArgument ( $workflow [ 'places' ]);
$definitionDefinition -> addArgument ( $transitions );
2016-11-08 19:01:05 +00:00
$definitionDefinition -> addTag ( 'workflow.definition' , array (
'name' => $name ,
'type' => $type ,
'marking_store' => isset ( $workflow [ 'marking_store' ][ 'type' ]) ? $workflow [ 'marking_store' ][ 'type' ] : null ,
));
2016-11-11 15:26:22 +00:00
if ( isset ( $workflow [ 'initial_place' ])) {
$definitionDefinition -> addArgument ( $workflow [ 'initial_place' ]);
}
2016-11-08 19:01:05 +00:00
// Create MarkingStore
2016-03-25 15:43:30 +00:00
if ( isset ( $workflow [ 'marking_store' ][ 'type' ])) {
2016-11-28 07:50:06 +00:00
$markingStoreDefinition = new ChildDefinition ( 'workflow.marking_store.' . $workflow [ 'marking_store' ][ 'type' ]);
2016-03-25 15:43:30 +00:00
foreach ( $workflow [ 'marking_store' ][ 'arguments' ] as $argument ) {
$markingStoreDefinition -> addArgument ( $argument );
}
2016-11-07 17:57:54 +00:00
} elseif ( isset ( $workflow [ 'marking_store' ][ 'service' ])) {
2016-03-25 15:43:30 +00:00
$markingStoreDefinition = new Reference ( $workflow [ 'marking_store' ][ 'service' ]);
}
2016-11-08 19:01:05 +00:00
// Create Workflow
2017-09-05 16:39:41 +01:00
$workflowId = sprintf ( '%s.%s' , $type , $name );
2016-11-28 07:50:06 +00:00
$workflowDefinition = new ChildDefinition ( sprintf ( '%s.abstract' , $type ));
2017-09-05 16:39:41 +01:00
$workflowDefinition -> replaceArgument ( 0 , new Reference ( sprintf ( '%s.definition' , $workflowId )));
2016-11-07 17:57:54 +00:00
if ( isset ( $markingStoreDefinition )) {
$workflowDefinition -> replaceArgument ( 1 , $markingStoreDefinition );
}
2016-03-25 15:43:30 +00:00
$workflowDefinition -> replaceArgument ( 3 , $name );
2016-11-08 19:01:05 +00:00
// Store to container
2016-03-25 15:43:30 +00:00
$container -> setDefinition ( $workflowId , $workflowDefinition );
2016-11-08 19:01:05 +00:00
$container -> setDefinition ( sprintf ( '%s.definition' , $workflowId ), $definitionDefinition );
2016-03-25 15:43:30 +00:00
2016-11-08 19:01:05 +00:00
// Add workflow to Registry
2017-01-18 14:08:35 +00:00
if ( $workflow [ 'supports' ]) {
2016-12-04 22:08:15 +00:00
foreach ( $workflow [ 'supports' ] as $supportedClassName ) {
2017-10-30 06:24:47 +00:00
$strategyDefinition = new Definition ( Workflow\SupportStrategy\InstanceOfSupportStrategy :: class , array ( $supportedClassName ));
2016-12-04 22:08:15 +00:00
$strategyDefinition -> setPublic ( false );
$registryDefinition -> addMethodCall ( 'add' , array ( new Reference ( $workflowId ), $strategyDefinition ));
}
} elseif ( isset ( $workflow [ 'support_strategy' ])) {
$registryDefinition -> addMethodCall ( 'add' , array ( new Reference ( $workflowId ), new Reference ( $workflow [ 'support_strategy' ])));
2016-03-25 15:43:30 +00:00
}
2017-03-08 16:15:01 +00:00
// Enable the AuditTrail
if ( $workflow [ 'audit_trail' ][ 'enabled' ]) {
$listener = new Definition ( Workflow\EventListener\AuditTrailListener :: class );
2017-09-05 12:45:10 +01:00
$listener -> setPrivate ( true );
2017-03-08 16:15:01 +00:00
$listener -> addTag ( 'monolog.logger' , array ( 'channel' => 'workflow' ));
$listener -> addTag ( 'kernel.event_listener' , array ( 'event' => sprintf ( 'workflow.%s.leave' , $name ), 'method' => 'onLeave' ));
$listener -> addTag ( 'kernel.event_listener' , array ( 'event' => sprintf ( 'workflow.%s.transition' , $name ), 'method' => 'onTransition' ));
$listener -> addTag ( 'kernel.event_listener' , array ( 'event' => sprintf ( 'workflow.%s.enter' , $name ), 'method' => 'onEnter' ));
$listener -> addArgument ( new Reference ( 'logger' ));
$container -> setDefinition ( sprintf ( '%s.listener.audit_trail' , $workflowId ), $listener );
}
2017-03-08 18:39:12 +00:00
// Add Guard Listener
$guard = new Definition ( Workflow\EventListener\GuardListener :: class );
2017-09-05 12:45:10 +01:00
$guard -> setPrivate ( true );
2017-03-08 18:39:12 +00:00
$configuration = array ();
foreach ( $workflow [ 'transitions' ] as $transitionName => $config ) {
if ( ! isset ( $config [ 'guard' ])) {
continue ;
}
2017-03-17 13:38:55 +00:00
if ( ! class_exists ( ExpressionLanguage :: class )) {
throw new LogicException ( 'Cannot guard workflows as the ExpressionLanguage component is not installed.' );
}
2017-07-21 19:01:38 +01:00
if ( ! class_exists ( Security :: class )) {
throw new LogicException ( 'Cannot guard workflows as the Security component is not installed.' );
}
2017-03-08 18:39:12 +00:00
$eventName = sprintf ( 'workflow.%s.guard.%s' , $name , $transitionName );
$guard -> addTag ( 'kernel.event_listener' , array ( 'event' => $eventName , 'method' => 'onTransition' ));
$configuration [ $eventName ] = $config [ 'guard' ];
}
if ( $configuration ) {
$guard -> setArguments ( array (
$configuration ,
new Reference ( 'workflow.security.expression_language' ),
new Reference ( 'security.token_storage' ),
new Reference ( 'security.authorization_checker' ),
new Reference ( 'security.authentication.trust_resolver' ),
new Reference ( 'security.role_hierarchy' ),
2017-07-13 11:20:18 +01:00
new Reference ( 'validator' , ContainerInterface :: NULL_ON_INVALID_REFERENCE ),
2017-03-08 18:39:12 +00:00
));
$container -> setDefinition ( sprintf ( '%s.listener.guard' , $workflowId ), $guard );
2017-07-21 19:01:38 +01:00
$container -> setParameter ( 'workflow.has_guard_listeners' , true );
2017-03-08 18:39:12 +00:00
}
2016-03-25 15:43:30 +00:00
}
}
2016-08-08 14:40:30 +01:00
private function registerDebugConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
$loader -> load ( 'debug_prod.xml' );
2017-06-12 15:27:27 +01:00
if ( class_exists ( Stopwatch :: class )) {
2017-09-13 21:59:37 +01:00
$container -> register ( 'debug.stopwatch' , Stopwatch :: class )
-> addArgument ( true )
-> setPrivate ( true )
-> addTag ( 'kernel.reset' , array ( 'method' => 'reset' ));
2017-09-05 16:39:41 +01:00
$container -> setAlias ( Stopwatch :: class , new Alias ( 'debug.stopwatch' , false ));
2017-06-12 15:27:27 +01:00
}
2016-08-08 14:40:30 +01:00
$debug = $container -> getParameter ( 'kernel.debug' );
2017-06-13 09:29:19 +01:00
if ( $debug ) {
$container -> setParameter ( 'debug.container.dump' , '%kernel.cache_dir%/%kernel.container_class%.xml' );
}
2017-06-12 15:27:27 +01:00
if ( $debug && class_exists ( Stopwatch :: class )) {
2016-08-08 14:40:30 +01:00
$loader -> load ( 'debug.xml' );
}
$definition = $container -> findDefinition ( 'debug.debug_handlers_listener' );
if ( ! $config [ 'log' ]) {
$definition -> replaceArgument ( 1 , null );
}
if ( ! $config [ 'throw' ]) {
$container -> setParameter ( 'debug.error_handler.throw_at' , 0 );
}
$definition -> replaceArgument ( 4 , $debug );
$definition -> replaceArgument ( 6 , $debug );
2016-11-04 20:47:40 +00:00
if ( $debug && class_exists ( DebugProcessor :: class )) {
$definition = new Definition ( DebugProcessor :: class );
$definition -> setPublic ( false );
$container -> setDefinition ( 'debug.log_processor' , $definition );
}
2016-08-08 14:40:30 +01:00
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerRouterConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2010-09-15 19:49:16 +01:00
{
2017-07-22 10:58:19 +01:00
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.router_debug' );
$container -> removeDefinition ( 'console.command.router_match' );
2017-07-22 10:58:19 +01:00
return ;
}
2011-01-24 19:50:31 +00:00
$loader -> load ( 'routing.xml' );
2017-10-29 08:23:24 +00:00
if ( ! interface_exists ( ContainerBagInterface :: class )) {
$container -> getDefinition ( 'router.default' )
-> replaceArgument ( 0 , new Reference ( 'service_container' ))
-> clearTag ( 'container.service_subscriber' )
;
}
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'router.resource' , $config [ 'resource' ]);
2016-10-04 08:25:27 +01:00
$container -> setParameter ( 'router.cache_class_prefix' , $container -> getParameter ( 'kernel.container_class' ));
2011-07-18 09:05:28 +01:00
$router = $container -> findDefinition ( 'router.default' );
2012-06-09 15:43:04 +01:00
$argument = $router -> getArgument ( 2 );
2012-07-30 17:24:12 +01:00
$argument [ 'strict_requirements' ] = $config [ 'strict_requirements' ];
2011-02-10 15:26:13 +00:00
if ( isset ( $config [ 'type' ])) {
2011-04-28 10:26:10 +01:00
$argument [ 'resource_type' ] = $config [ 'type' ];
2011-02-10 15:26:13 +00:00
}
2012-06-09 15:43:04 +01:00
$router -> replaceArgument ( 2 , $argument );
2011-02-10 15:26:13 +00:00
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'request_listener.http_port' , $config [ 'http_port' ]);
$container -> setParameter ( 'request_listener.https_port' , $config [ 'https_port' ]);
2011-04-19 23:25:45 +01:00
2017-06-02 19:02:43 +01:00
if ( $this -> annotationsConfigEnabled ) {
$container -> register ( 'routing.loader.annotation' , AnnotatedRouteControllerLoader :: class )
-> setPublic ( false )
-> addTag ( 'routing.loader' , array ( 'priority' => - 10 ))
-> addArgument ( new Reference ( 'annotation_reader' ));
2017-06-11 10:30:54 +01:00
$container -> register ( 'routing.loader.annotation.directory' , AnnotationDirectoryLoader :: class )
2017-06-02 19:02:43 +01:00
-> setPublic ( false )
-> addTag ( 'routing.loader' , array ( 'priority' => - 10 ))
-> setArguments ( array (
new Reference ( 'file_locator' ),
new Reference ( 'routing.loader.annotation' ),
));
2017-06-11 10:30:54 +01:00
$container -> register ( 'routing.loader.annotation.file' , AnnotationFileLoader :: class )
2017-06-02 19:02:43 +01:00
-> setPublic ( false )
-> addTag ( 'routing.loader' , array ( 'priority' => - 10 ))
-> setArguments ( array (
new Reference ( 'file_locator' ),
new Reference ( 'routing.loader.annotation' ),
));
}
2011-01-24 19:50:31 +00:00
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerSessionConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2011-01-24 19:50:31 +00:00
{
$loader -> load ( 'session.xml' );
2011-01-23 07:36:19 +00:00
2011-04-22 11:35:09 +01:00
// session storage
2017-09-05 12:45:10 +01:00
$container -> setAlias ( 'session.storage' , $config [ 'storage_id' ]) -> setPrivate ( true );
2017-12-22 14:54:40 +00:00
$options = array ( 'cache_limiter' => '0' );
2017-10-19 01:12:27 +01:00
foreach ( array ( 'name' , 'cookie_lifetime' , 'cookie_path' , 'cookie_domain' , 'cookie_secure' , 'cookie_httponly' , 'use_cookies' , 'gc_maxlifetime' , 'gc_probability' , 'gc_divisor' ) as $key ) {
2011-01-24 19:50:31 +00:00
if ( isset ( $config [ $key ])) {
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
$options [ $key ] = $config [ $key ];
2010-12-14 14:51:10 +00:00
}
2010-09-15 19:49:16 +01:00
}
2012-02-29 08:44:47 +00:00
2011-04-22 11:35:09 +01:00
$container -> setParameter ( 'session.storage.options' , $options );
2010-11-25 08:04:24 +00:00
2012-03-03 09:03:04 +00:00
// session handler (the internal callback registered with PHP session management)
2013-11-17 14:05:15 +00:00
if ( null === $config [ 'handler_id' ]) {
2012-08-17 17:38:35 +01:00
// Set the handler class to be null
$container -> getDefinition ( 'session.storage.native' ) -> replaceArgument ( 1 , null );
2013-06-07 23:05:01 +01:00
$container -> getDefinition ( 'session.storage.php_bridge' ) -> replaceArgument ( 0 , null );
2012-08-17 17:38:35 +01:00
} else {
2017-10-10 10:13:08 +01:00
$container -> setAlias ( 'session.handler' , $config [ 'handler_id' ]) -> setPrivate ( true );
2012-08-17 17:38:35 +01:00
}
2012-03-03 09:03:04 +00:00
2012-04-13 09:34:00 +01:00
$container -> setParameter ( 'session.save_path' , $config [ 'save_path' ]);
2013-09-24 23:02:41 +01:00
$container -> setParameter ( 'session.metadata.update_threshold' , $config [ 'metadata_update_threshold' ]);
2010-09-15 19:49:16 +01:00
}
2013-12-25 21:24:54 +00:00
private function registerRequestConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
if ( $config [ 'formats' ]) {
$loader -> load ( 'request.xml' );
2017-09-05 12:45:10 +01:00
2013-12-25 21:24:54 +00:00
$container
-> getDefinition ( 'request.add_request_formats_listener' )
-> replaceArgument ( 0 , $config [ 'formats' ])
;
}
}
2016-08-31 09:43:03 +01:00
private function registerTemplatingConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2010-09-20 20:01:41 +01:00
{
2011-01-24 19:50:31 +00:00
$loader -> load ( 'templating.xml' );
2013-02-19 11:01:40 +00:00
$container -> setParameter ( 'fragment.renderer.hinclude.global_template' , $config [ 'hinclude_default_template' ]);
2011-04-05 07:03:29 +01:00
2015-01-10 10:34:10 +00:00
if ( $container -> getParameter ( 'kernel.debug' )) {
$logger = new Reference ( 'logger' , ContainerInterface :: IGNORE_ON_INVALID_REFERENCE );
$container -> getDefinition ( 'templating.loader.cache' )
-> addTag ( 'monolog.logger' , array ( 'channel' => 'templating' ))
-> addMethodCall ( 'setLogger' , array ( $logger ));
$container -> getDefinition ( 'templating.loader.chain' )
-> addTag ( 'monolog.logger' , array ( 'channel' => 'templating' ))
-> addMethodCall ( 'setLogger' , array ( $logger ));
}
2011-02-10 20:40:00 +00:00
if ( ! empty ( $config [ 'loaders' ])) {
2013-12-28 07:46:05 +00:00
$loaders = array_map ( function ( $loader ) { return new Reference ( $loader ); }, $config [ 'loaders' ]);
2011-01-24 19:50:31 +00:00
2011-02-06 20:39:30 +00:00
// Use a delegation unless only a single loader was registered
2011-01-24 19:50:31 +00:00
if ( 1 === count ( $loaders )) {
2017-09-05 12:45:10 +01:00
$container -> setAlias ( 'templating.loader' , ( string ) reset ( $loaders )) -> setPrivate ( true );
2011-01-24 19:50:31 +00:00
} else {
$container -> getDefinition ( 'templating.loader.chain' ) -> addArgument ( $loaders );
2017-09-05 12:45:10 +01:00
$container -> setAlias ( 'templating.loader' , 'templating.loader.chain' ) -> setPrivate ( true );
2011-01-24 19:50:31 +00:00
}
}
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'templating.loader.cache.path' , null );
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
if ( isset ( $config [ 'cache' ])) {
2011-01-24 19:50:31 +00:00
// Wrap the existing loader with cache (must happen after loaders are registered)
$container -> setDefinition ( 'templating.loader.wrapped' , $container -> findDefinition ( 'templating.loader' ));
2011-04-04 10:56:41 +01:00
$loaderCache = $container -> getDefinition ( 'templating.loader.cache' );
2011-05-13 10:57:05 +01:00
$container -> setParameter ( 'templating.loader.cache.path' , $config [ 'cache' ]);
2011-04-04 10:56:41 +01:00
$container -> setDefinition ( 'templating.loader' , $loaderCache );
2011-01-24 19:50:31 +00:00
}
2011-02-10 21:05:04 +00:00
$container -> setParameter ( 'templating.engines' , $config [ 'engines' ]);
2013-12-28 07:46:05 +00:00
$engines = array_map ( function ( $engine ) { return new Reference ( 'templating.engine.' . $engine ); }, $config [ 'engines' ]);
2011-01-24 19:50:31 +00:00
2011-02-26 17:41:17 +00:00
// Use a delegation unless only a single engine was registered
2011-01-24 19:50:31 +00:00
if ( 1 === count ( $engines )) {
2017-09-17 10:49:41 +01:00
$container -> setAlias ( 'templating' , ( string ) reset ( $engines )) -> setPublic ( true );
2011-01-24 19:50:31 +00:00
} else {
2018-01-23 11:06:14 +00:00
$templateEngineDefinition = $container -> getDefinition ( 'templating.engine.delegating' );
2013-01-18 14:46:50 +00:00
foreach ( $engines as $engine ) {
2018-01-23 11:06:14 +00:00
$templateEngineDefinition -> addMethodCall ( 'addEngine' , array ( $engine ));
2013-01-18 14:46:50 +00:00
}
2017-09-17 10:49:41 +01:00
$container -> setAlias ( 'templating' , 'templating.engine.delegating' ) -> setPublic ( true );
2011-01-24 19:50:31 +00:00
}
2015-01-10 10:34:10 +00:00
2015-01-12 13:49:09 +00:00
$container -> getDefinition ( 'fragment.renderer.hinclude' )
-> addTag ( 'kernel.fragment_renderer' , array ( 'alias' => 'hinclude' ))
-> replaceArgument ( 0 , new Reference ( 'templating' ))
;
2015-01-10 10:34:10 +00:00
// configure the PHP engine if needed
if ( in_array ( 'php' , $config [ 'engines' ], true )) {
$loader -> load ( 'templating_php.xml' );
$container -> setParameter ( 'templating.helper.form.resources' , $config [ 'form' ][ 'resources' ]);
2017-06-12 15:27:27 +01:00
if ( $container -> getParameter ( 'kernel.debug' ) && class_exists ( Stopwatch :: class )) {
2015-01-10 10:34:10 +00:00
$loader -> load ( 'templating_debug.xml' );
$container -> setDefinition ( 'templating.engine.php' , $container -> findDefinition ( 'debug.templating.engine.php' ));
2017-09-05 12:45:10 +01:00
$container -> setAlias ( 'debug.templating.engine.php' , 'templating.engine.php' ) -> setPrivate ( true );
2015-01-10 10:34:10 +00:00
}
2016-02-20 16:27:18 +00:00
if ( $container -> has ( 'assets.packages' )) {
$container -> getDefinition ( 'templating.helper.assets' ) -> replaceArgument ( 0 , new Reference ( 'assets.packages' ));
} else {
$container -> removeDefinition ( 'templating.helper.assets' );
}
2017-03-15 10:56:07 +00:00
if ( ! $this -> translationConfigEnabled ) {
$container -> removeDefinition ( 'templating.helper.translator' );
}
2015-04-20 17:28:31 +01:00
}
2010-09-20 20:01:41 +01:00
}
2014-12-28 18:57:17 +00:00
private function registerAssetsConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
2015-02-12 12:06:55 +00:00
$loader -> load ( 'assets.xml' );
2016-01-25 21:22:29 +00:00
$defaultVersion = null ;
if ( $config [ 'version_strategy' ]) {
$defaultVersion = new Reference ( $config [ 'version_strategy' ]);
} else {
2017-03-17 19:10:06 +00:00
$defaultVersion = $this -> createVersion ( $container , $config [ 'version' ], $config [ 'version_format' ], $config [ 'json_manifest_path' ], '_default' );
2016-01-25 21:22:29 +00:00
}
2014-12-28 18:57:17 +00:00
$defaultPackage = $this -> createPackageDefinition ( $config [ 'base_path' ], $config [ 'base_urls' ], $defaultVersion );
$container -> setDefinition ( 'assets._default_package' , $defaultPackage );
$namedPackages = array ();
foreach ( $config [ 'packages' ] as $name => $package ) {
2016-01-25 21:22:29 +00:00
if ( null !== $package [ 'version_strategy' ]) {
$version = new Reference ( $package [ 'version_strategy' ]);
2017-03-17 19:10:06 +00:00
} elseif ( ! array_key_exists ( 'version' , $package ) && null === $package [ 'json_manifest_path' ]) {
// if neither version nor json_manifest_path are specified, use the default
2014-12-28 18:57:17 +00:00
$version = $defaultVersion ;
} else {
2017-03-17 19:10:06 +00:00
// let format fallback to main version_format
2014-12-28 18:57:17 +00:00
$format = $package [ 'version_format' ] ? : $config [ 'version_format' ];
2017-03-17 19:10:06 +00:00
$version = isset ( $package [ 'version' ]) ? $package [ 'version' ] : null ;
$version = $this -> createVersion ( $container , $version , $format , $package [ 'json_manifest_path' ], $name );
2014-12-28 18:57:17 +00:00
}
$container -> setDefinition ( 'assets._package_' . $name , $this -> createPackageDefinition ( $package [ 'base_path' ], $package [ 'base_urls' ], $version ));
$namedPackages [ $name ] = new Reference ( 'assets._package_' . $name );
}
$container -> getDefinition ( 'assets.packages' )
-> replaceArgument ( 0 , new Reference ( 'assets._default_package' ))
-> replaceArgument ( 1 , $namedPackages )
;
}
/**
* Returns a definition for an asset package .
*/
private function createPackageDefinition ( $basePath , array $baseUrls , Reference $version )
{
if ( $basePath && $baseUrls ) {
throw new \LogicException ( 'An asset package cannot have base URLs and base paths.' );
}
2017-02-14 16:35:24 +00:00
$package = new ChildDefinition ( $baseUrls ? 'assets.url_package' : 'assets.path_package' );
2017-02-04 10:29:24 +00:00
$package
2014-12-28 18:57:17 +00:00
-> setPublic ( false )
2017-02-04 10:29:24 +00:00
-> replaceArgument ( 0 , $baseUrls ? : $basePath )
2014-12-28 18:57:17 +00:00
-> replaceArgument ( 1 , $version )
;
2017-02-04 10:29:24 +00:00
return $package ;
2014-12-28 18:57:17 +00:00
}
2017-03-17 19:10:06 +00:00
private function createVersion ( ContainerBuilder $container , $version , $format , $jsonManifestPath , $name )
2014-12-28 18:57:17 +00:00
{
2017-03-17 19:10:06 +00:00
// Configuration prevents $version and $jsonManifestPath from being set
if ( null !== $version ) {
$def = new ChildDefinition ( 'assets.static_version_strategy' );
$def
-> replaceArgument ( 0 , $version )
-> replaceArgument ( 1 , $format )
;
$container -> setDefinition ( 'assets._version_' . $name , $def );
return new Reference ( 'assets._version_' . $name );
2014-12-28 18:57:17 +00:00
}
2017-03-17 19:10:06 +00:00
if ( null !== $jsonManifestPath ) {
$def = new ChildDefinition ( 'assets.json_manifest_version_strategy' );
$def -> replaceArgument ( 0 , $jsonManifestPath );
$container -> setDefinition ( 'assets._version_' . $name , $def );
return new Reference ( 'assets._version_' . $name );
}
2014-12-28 18:57:17 +00:00
2017-03-17 19:10:06 +00:00
return new Reference ( 'assets.empty_version_strategy' );
2014-12-28 18:57:17 +00:00
}
2016-12-14 21:05:29 +00:00
private function registerTranslatorConfiguration ( array $config , ContainerBuilder $container , LoaderInterface $loader )
2010-09-02 12:54:32 +01:00
{
2013-01-23 14:18:20 +00:00
if ( ! $this -> isConfigEnabled ( $container , $config )) {
2017-11-18 08:20:00 +00:00
$container -> removeDefinition ( 'console.command.translation_debug' );
$container -> removeDefinition ( 'console.command.translation_update' );
2017-07-22 10:58:19 +01:00
2013-01-23 14:18:20 +00:00
return ;
}
2016-09-28 05:49:39 +01:00
2016-12-14 21:05:29 +00:00
$loader -> load ( 'translation.xml' );
2016-09-28 05:49:39 +01:00
2013-01-23 14:18:20 +00:00
// Use the "real" translator instead of the identity default
2017-09-17 10:49:41 +01:00
$container -> setAlias ( 'translator' , 'translator.default' ) -> setPublic ( true );
2016-09-18 09:17:44 +01:00
$container -> setAlias ( 'translator.formatter' , new Alias ( $config [ 'formatter' ], false ));
2013-01-23 14:18:20 +00:00
$translator = $container -> findDefinition ( 'translator.default' );
2015-01-12 11:17:42 +00:00
$translator -> addMethodCall ( 'setFallbackLocales' , array ( $config [ 'fallbacks' ]));
2012-07-15 14:56:45 +01:00
2014-05-10 23:14:12 +01:00
$container -> setParameter ( 'translator.logging' , $config [ 'logging' ]);
2017-11-07 14:35:08 +00:00
$container -> setParameter ( 'translator.default_path' , $config [ 'default_path' ]);
2014-05-10 23:14:12 +01:00
2013-01-23 14:18:20 +00:00
// Discover translation directories
$dirs = array ();
2015-01-08 16:22:13 +00:00
if ( class_exists ( 'Symfony\Component\Validator\Validation' )) {
$r = new \ReflectionClass ( 'Symfony\Component\Validator\Validation' );
2013-01-23 14:18:20 +00:00
2015-07-07 20:01:23 +01:00
$dirs [] = dirname ( $r -> getFileName ()) . '/Resources/translations' ;
2013-01-23 14:18:20 +00:00
}
if ( class_exists ( 'Symfony\Component\Form\Form' )) {
$r = new \ReflectionClass ( 'Symfony\Component\Form\Form' );
2015-07-07 20:01:23 +01:00
$dirs [] = dirname ( $r -> getFileName ()) . '/Resources/translations' ;
2013-01-23 14:18:20 +00:00
}
if ( class_exists ( 'Symfony\Component\Security\Core\Exception\AuthenticationException' )) {
$r = new \ReflectionClass ( 'Symfony\Component\Security\Core\Exception\AuthenticationException' );
2016-10-25 09:15:38 +01:00
$dirs [] = dirname ( dirname ( $r -> getFileName ())) . '/Resources/translations' ;
2013-01-23 14:18:20 +00:00
}
2017-11-07 14:35:08 +00:00
$defaultDir = $container -> getParameterBag () -> resolveValue ( $config [ 'default_path' ]);
2016-01-09 06:10:09 +00:00
$rootDir = $container -> getParameter ( 'kernel.root_dir' );
2016-12-31 11:06:43 +00:00
foreach ( $container -> getParameter ( 'kernel.bundles_metadata' ) as $name => $bundle ) {
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $dir = $bundle [ 'path' ] . '/Resources/translations' )) {
2013-01-23 14:18:20 +00:00
$dirs [] = $dir ;
2017-11-07 14:35:08 +00:00
}
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $dir = $rootDir . sprintf ( '/Resources/%s/translations' , $name ))) {
2011-01-24 19:50:31 +00:00
$dirs [] = $dir ;
}
2013-01-23 14:18:20 +00:00
}
2016-01-12 17:46:01 +00:00
2015-05-05 20:36:55 +01:00
foreach ( $config [ 'paths' ] as $dir ) {
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $dir )) {
2015-05-05 20:36:55 +01:00
$dirs [] = $dir ;
} else {
throw new \UnexpectedValueException ( sprintf ( '%s defined in translator.paths does not exist or is not a directory' , $dir ));
}
}
2016-01-12 17:46:01 +00:00
2017-11-07 14:35:08 +00:00
if ( $container -> fileExists ( $defaultDir )) {
$dirs [] = $defaultDir ;
}
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $dir = $rootDir . '/Resources/translations' )) {
2013-01-23 14:18:20 +00:00
$dirs [] = $dir ;
}
2010-09-02 12:54:32 +01:00
2013-01-23 14:18:20 +00:00
// Register translation resources
if ( $dirs ) {
2015-03-10 21:45:35 +00:00
$files = array ();
2013-01-23 14:18:20 +00:00
$finder = Finder :: create ()
2016-11-17 09:41:17 +00:00
-> followLinks ()
2013-01-23 14:18:20 +00:00
-> files ()
-> filter ( function ( \SplFileInfo $file ) {
return 2 === substr_count ( $file -> getBasename (), '.' ) && preg_match ( '/\.\w+$/' , $file -> getBasename ());
})
-> in ( $dirs )
2017-11-22 10:17:59 +00:00
-> sortByName ()
2013-01-23 14:18:20 +00:00
;
foreach ( $finder as $file ) {
2016-03-24 11:33:34 +00:00
list (, $locale ) = explode ( '.' , $file -> getBasename (), 3 );
2015-03-24 13:45:14 +00:00
if ( ! isset ( $files [ $locale ])) {
$files [ $locale ] = array ();
}
$files [ $locale ][] = ( string ) $file ;
2010-09-02 12:54:32 +01:00
}
2015-03-10 21:45:35 +00:00
2015-03-24 13:45:14 +00:00
$options = array_merge (
2017-03-15 15:59:02 +00:00
$translator -> getArgument ( 4 ),
2015-03-24 13:45:14 +00:00
array ( 'resource_files' => $files )
);
2017-03-15 15:59:02 +00:00
$translator -> replaceArgument ( 4 , $options );
2011-01-24 19:50:31 +00:00
}
2010-09-02 12:54:32 +01:00
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerValidationConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2010-08-18 13:44:35 +01:00
{
2017-04-27 16:08:18 +01:00
if ( ! $this -> validatorConfigEnabled = $this -> isConfigEnabled ( $container , $config )) {
2013-01-23 14:18:20 +00:00
return ;
}
2016-12-16 12:58:05 +00:00
if ( ! class_exists ( 'Symfony\Component\Validator\Validation' )) {
throw new LogicException ( 'Validation support cannot be enabled as the Validator component is not installed.' );
}
2017-12-12 19:30:26 +00:00
if ( ! isset ( $config [ 'email_validation_mode' ])) {
$config [ 'email_validation_mode' ] = 'loose' ;
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization
This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()).
Major changes:
* Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map.
* Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user).
* Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled.
* Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless.
Additional small changes:
* Added isset()'s, since config options may be unset
* Wrap registerXxxConfiguration() calls in isset() checks
* Load translation.xml in configLoad(), since it's always required
* Default cache_warmer value (!kernel.debug) is determined via Configuration class
Things to be fixed:
* Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs
* The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix.
* Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does.
* Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
$loader -> load ( 'validator.xml' );
2010-08-18 13:44:35 +01:00
2014-03-18 16:36:12 +00:00
$validatorBuilder = $container -> getDefinition ( 'validator.builder' );
2012-11-27 22:18:12 +00:00
$container -> setParameter ( 'validator.translation_domain' , $config [ 'translation_domain' ]);
2014-03-18 16:36:12 +00:00
2017-01-23 14:03:11 +00:00
$files = array ( 'xml' => array (), 'yml' => array ());
2017-03-08 00:16:09 +00:00
$this -> registerValidatorMapping ( $container , $config , $files );
2017-01-23 14:03:11 +00:00
if ( ! empty ( $files [ 'xml' ])) {
$validatorBuilder -> addMethodCall ( 'addXmlMappings' , array ( $files [ 'xml' ]));
2014-03-18 16:36:12 +00:00
}
2017-01-23 14:03:11 +00:00
if ( ! empty ( $files [ 'yml' ])) {
$validatorBuilder -> addMethodCall ( 'addYamlMappings' , array ( $files [ 'yml' ]));
2014-03-18 16:36:12 +00:00
}
2010-08-18 13:44:35 +01:00
2013-09-19 17:03:48 +01:00
$definition = $container -> findDefinition ( 'validator.email' );
2017-12-12 19:30:26 +00:00
$definition -> replaceArgument ( 0 , $config [ 'email_validation_mode' ]);
2013-09-19 17:03:48 +01:00
2011-08-04 11:56:01 +01:00
if ( array_key_exists ( 'enable_annotations' , $config ) && $config [ 'enable_annotations' ]) {
2016-09-30 00:48:22 +01:00
if ( ! $this -> annotationsConfigEnabled ) {
throw new \LogicException ( '"enable_annotations" on the validator cannot be set as Annotations support is disabled.' );
}
2014-03-30 17:56:20 +01:00
$validatorBuilder -> addMethodCall ( 'enableAnnotationMapping' , array ( new Reference ( 'annotation_reader' )));
2014-03-18 16:36:12 +00:00
}
if ( array_key_exists ( 'static_method' , $config ) && $config [ 'static_method' ]) {
foreach ( $config [ 'static_method' ] as $methodName ) {
$validatorBuilder -> addMethodCall ( 'addMethodMapping' , array ( $methodName ));
}
2010-08-18 13:44:35 +01:00
}
2011-03-29 22:07:50 +01:00
2017-07-12 11:01:37 +01:00
if ( ! $container -> getParameter ( 'kernel.debug' )) {
2016-07-29 17:51:44 +01:00
$validatorBuilder -> addMethodCall ( 'setMetadataCache' , array ( new Reference ( 'validator.mapping.cache.symfony' )));
2014-03-18 16:36:12 +00:00
}
2010-08-18 13:44:35 +01:00
}
2017-03-08 00:16:09 +00:00
private function registerValidatorMapping ( ContainerBuilder $container , array $config , array & $files )
2011-04-01 07:26:19 +01:00
{
2017-03-08 00:16:09 +00:00
$fileRecorder = function ( $extension , $path ) use ( & $files ) {
$files [ 'yaml' === $extension ? 'yml' : $extension ][] = $path ;
};
2013-11-05 10:46:57 +00:00
if ( interface_exists ( 'Symfony\Component\Form\FormInterface' )) {
$reflClass = new \ReflectionClass ( 'Symfony\Component\Form\FormInterface' );
2017-03-08 00:16:09 +00:00
$fileRecorder ( 'xml' , dirname ( $reflClass -> getFileName ()) . '/Resources/config/validation.xml' );
2013-11-05 10:46:57 +00:00
}
2011-04-01 07:26:19 +01:00
2016-12-31 11:06:43 +00:00
foreach ( $container -> getParameter ( 'kernel.bundles_metadata' ) as $bundle ) {
$dirname = $bundle [ 'path' ];
2017-01-23 14:03:11 +00:00
2017-06-16 10:22:14 +01:00
if (
$container -> fileExists ( $file = $dirname . '/Resources/config/validation.yaml' , false ) ||
$container -> fileExists ( $file = $dirname . '/Resources/config/validation.yml' , false )
) {
2017-03-08 00:16:09 +00:00
$fileRecorder ( 'yml' , $file );
2011-04-01 07:26:19 +01:00
}
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $file = $dirname . '/Resources/config/validation.xml' , false )) {
2017-03-08 00:16:09 +00:00
$fileRecorder ( 'xml' , $file );
2011-04-01 07:26:19 +01:00
}
2015-03-04 23:15:43 +00:00
2017-03-08 10:59:12 +00:00
if ( $container -> fileExists ( $dir = $dirname . '/Resources/config/validation' , '/^$/' )) {
2017-03-08 00:16:09 +00:00
$this -> registerMappingFilesFromDir ( $dir , $fileRecorder );
2015-03-04 23:15:43 +00:00
}
2011-04-01 07:26:19 +01:00
}
2017-03-08 00:16:09 +00:00
2017-11-07 12:03:09 +00:00
$projectDir = $container -> getParameter ( 'kernel.project_dir' );
if ( $container -> fileExists ( $dir = $projectDir . '/config/validator' , '/^$/' )) {
$this -> registerMappingFilesFromDir ( $dir , $fileRecorder );
}
2017-03-08 00:16:09 +00:00
$this -> registerMappingFilesFromConfig ( $container , $config , $fileRecorder );
2017-01-23 14:03:11 +00:00
}
2017-03-08 00:16:09 +00:00
private function registerMappingFilesFromDir ( $dir , callable $fileRecorder )
2017-01-23 14:03:11 +00:00
{
2017-11-22 10:17:59 +00:00
foreach ( Finder :: create () -> followLinks () -> files () -> in ( $dir ) -> name ( '/\.(xml|ya?ml)$/' ) -> sortByName () as $file ) {
2017-03-08 00:16:09 +00:00
$fileRecorder ( $file -> getExtension (), $file -> getRealPath ());
2017-01-23 14:03:11 +00:00
}
}
2011-04-01 07:26:19 +01:00
2017-03-08 00:16:09 +00:00
private function registerMappingFilesFromConfig ( ContainerBuilder $container , array $config , callable $fileRecorder )
2017-01-23 14:03:11 +00:00
{
foreach ( $config [ 'mapping' ][ 'paths' ] as $path ) {
if ( is_dir ( $path )) {
2017-03-08 00:16:09 +00:00
$this -> registerMappingFilesFromDir ( $path , $fileRecorder );
2017-03-08 10:59:12 +00:00
$container -> addResource ( new DirectoryResource ( $path , '/^$/' ));
} elseif ( $container -> fileExists ( $path , false )) {
2017-03-08 00:16:09 +00:00
if ( ! preg_match ( '/\.(xml|ya?ml)$/' , $path , $matches )) {
2017-01-23 14:03:11 +00:00
throw new \RuntimeException ( sprintf ( 'Unsupported mapping type in "%s", supported types are XML & Yaml.' , $path ));
}
2017-03-08 00:16:09 +00:00
$fileRecorder ( $matches [ 1 ], $path );
2017-01-23 14:03:11 +00:00
} else {
throw new \RuntimeException ( sprintf ( 'Could not open file or directory "%s".' , $path ));
}
}
2011-04-01 07:26:19 +01:00
}
2013-10-09 09:42:58 +01:00
private function registerAnnotationsConfiguration ( array $config , ContainerBuilder $container , $loader )
2011-05-03 13:36:42 +01:00
{
2016-09-30 00:48:22 +01:00
if ( ! $this -> annotationsConfigEnabled ) {
return ;
}
if ( ! class_exists ( 'Doctrine\Common\Annotations\Annotation' )) {
throw new LogicException ( 'Annotations cannot be enabled as the Doctrine Annotation library is not installed.' );
}
2011-05-03 13:36:42 +01:00
$loader -> load ( 'annotations.xml' );
2017-12-10 21:39:54 +00:00
if ( ! method_exists ( AnnotationRegistry :: class , 'registerUniqueLoader' )) {
$container -> getDefinition ( 'annotations.dummy_registry' )
-> setMethodCalls ( array ( array ( 'registerLoader' , array ( 'class_exists' ))));
}
2017-09-05 12:45:10 +01:00
2015-09-29 14:40:49 +01:00
if ( 'none' !== $config [ 'cache' ]) {
2017-06-11 01:55:29 +01:00
if ( ! class_exists ( 'Doctrine\Common\Cache\CacheProvider' )) {
throw new LogicException ( 'Annotations cannot be enabled as the Doctrine Cache library is not installed.' );
}
2016-06-28 13:49:00 +01:00
$cacheService = $config [ 'cache' ];
if ( 'php_array' === $config [ 'cache' ]) {
$cacheService = 'annotations.cache' ;
// Enable warmer only if PHP array is used for cache
$definition = $container -> findDefinition ( 'annotations.cache_warmer' );
$definition -> addTag ( 'kernel.cache_warmer' );
} elseif ( 'file' === $config [ 'cache' ]) {
2015-09-29 14:40:49 +01:00
$cacheDir = $container -> getParameterBag () -> resolveValue ( $config [ 'file_cache_dir' ]);
2016-06-28 13:49:00 +01:00
2015-09-29 14:40:49 +01:00
if ( ! is_dir ( $cacheDir ) && false === @ mkdir ( $cacheDir , 0777 , true ) && ! is_dir ( $cacheDir )) {
throw new \RuntimeException ( sprintf ( 'Could not create cache directory "%s".' , $cacheDir ));
}
$container
2015-10-08 10:44:44 +01:00
-> getDefinition ( 'annotations.filesystem_cache' )
2015-09-29 14:40:49 +01:00
-> replaceArgument ( 0 , $cacheDir )
;
2016-06-28 13:49:00 +01:00
$cacheService = 'annotations.filesystem_cache' ;
2011-05-03 13:36:42 +01:00
}
$container
-> getDefinition ( 'annotations.cached_reader' )
2011-05-24 12:29:44 +01:00
-> replaceArgument ( 2 , $config [ 'debug' ])
2018-01-05 12:03:30 +00:00
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
-> setProperty ( 'cacheProviderBackup' , new ServiceClosureArgument ( new Reference ( $cacheService )))
2011-05-03 13:36:42 +01:00
;
2017-09-13 12:10:11 +01:00
$container -> setAlias ( 'annotation_reader' , 'annotations.cached_reader' ) -> setPrivate ( true );
2017-02-01 11:51:46 +00:00
$container -> setAlias ( Reader :: class , new Alias ( 'annotations.cached_reader' , false ));
2017-01-23 20:50:14 +00:00
} else {
$container -> removeDefinition ( 'annotations.cached_reader' );
2011-05-03 13:36:42 +01:00
}
}
2017-10-18 15:30:35 +01:00
private function registerPropertyAccessConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
2014-08-21 18:05:54 +01:00
{
2017-10-18 15:30:35 +01:00
if ( ! class_exists ( 'Symfony\Component\PropertyAccess\PropertyAccessor' )) {
return ;
}
$loader -> load ( 'property_access.xml' );
2014-08-21 18:05:54 +01:00
$container
-> getDefinition ( 'property_accessor' )
-> replaceArgument ( 0 , $config [ 'magic_call' ])
-> replaceArgument ( 1 , $config [ 'throw_exception_on_invalid_index' ])
;
}
2013-10-09 09:42:58 +01:00
private function registerSecurityCsrfConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
if ( ! $this -> isConfigEnabled ( $container , $config )) {
return ;
}
2016-09-28 18:11:47 +01:00
if ( ! class_exists ( 'Symfony\Component\Security\Csrf\CsrfToken' )) {
2018-01-04 12:01:31 +00:00
throw new LogicException ( 'CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require symfony/security-csrf".' );
2016-09-28 18:11:47 +01:00
}
2013-10-09 09:42:58 +01:00
if ( ! $this -> sessionConfigEnabled ) {
throw new \LogicException ( 'CSRF protection needs sessions to be enabled.' );
}
// Enable services for CSRF protection (even without forms)
$loader -> load ( 'security_csrf.xml' );
}
2014-12-25 03:17:33 +00:00
private function registerSerializerConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
$loader -> load ( 'serializer.xml' );
2016-01-29 15:26:46 +00:00
2017-10-20 08:39:07 +01:00
if ( ! class_exists ( DateIntervalNormalizer :: class )) {
$container -> removeDefinition ( 'serializer.normalizer.dateinterval' );
2016-07-10 10:41:46 +01:00
}
2017-04-15 17:59:12 +01:00
if ( ! class_exists ( ClassDiscriminatorFromClassMetadata :: class )) {
$container -> removeAlias ( 'Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface' );
$container -> removeDefinition ( 'serializer.mapping.class_discriminator_resolver' );
}
2014-12-25 03:17:33 +00:00
$chainLoader = $container -> getDefinition ( 'serializer.mapping.chain_loader' );
2017-10-18 15:30:35 +01:00
if ( ! class_exists ( 'Symfony\Component\PropertyAccess\PropertyAccessor' )) {
$container -> removeAlias ( 'serializer.property_accessor' );
$container -> removeDefinition ( 'serializer.normalizer.object' );
}
2017-11-27 17:35:30 +00:00
if ( ! class_exists ( Yaml :: class )) {
$container -> removeDefinition ( 'serializer.encoder.yaml' );
}
2014-12-25 03:17:33 +00:00
$serializerLoaders = array ();
if ( isset ( $config [ 'enable_annotations' ]) && $config [ 'enable_annotations' ]) {
2016-09-30 00:48:22 +01:00
if ( ! $this -> annotationsConfigEnabled ) {
throw new \LogicException ( '"enable_annotations" on the serializer cannot be set as Annotations support is disabled.' );
}
2014-12-25 03:17:33 +00:00
$annotationLoader = new Definition (
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader' ,
array ( new Reference ( 'annotation_reader' ))
);
$annotationLoader -> setPublic ( false );
$serializerLoaders [] = $annotationLoader ;
}
2017-03-08 00:16:09 +00:00
$fileRecorder = function ( $extension , $path ) use ( & $serializerLoaders ) {
$definition = new Definition ( in_array ( $extension , array ( 'yaml' , 'yml' )) ? 'Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader' : 'Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader' , array ( $path ));
$definition -> setPublic ( false );
$serializerLoaders [] = $definition ;
};
2016-12-31 11:06:43 +00:00
foreach ( $container -> getParameter ( 'kernel.bundles_metadata' ) as $bundle ) {
$dirname = $bundle [ 'path' ];
2014-12-25 03:17:33 +00:00
2017-01-30 09:47:16 +00:00
if ( $container -> fileExists ( $file = $dirname . '/Resources/config/serialization.xml' , false )) {
2017-03-08 00:16:09 +00:00
$fileRecorder ( 'xml' , $file );
2014-12-25 03:17:33 +00:00
}
2017-06-16 10:22:14 +01:00
if (
$container -> fileExists ( $file = $dirname . '/Resources/config/serialization.yaml' , false ) ||
$container -> fileExists ( $file = $dirname . '/Resources/config/serialization.yml' , false )
) {
2017-03-08 00:16:09 +00:00
$fileRecorder ( 'yml' , $file );
2014-12-25 03:17:33 +00:00
}
2017-08-11 20:45:37 +01:00
if ( $container -> fileExists ( $dir = $dirname . '/Resources/config/serialization' , '/^$/' )) {
2017-03-08 00:16:09 +00:00
$this -> registerMappingFilesFromDir ( $dir , $fileRecorder );
2014-12-25 03:17:33 +00:00
}
}
2017-11-06 02:41:09 +00:00
$projectDir = $container -> getParameter ( 'kernel.project_dir' );
if ( $container -> fileExists ( $dir = $projectDir . '/config/serializer' , '/^$/' )) {
$this -> registerMappingFilesFromDir ( $dir , $fileRecorder );
}
2017-03-08 00:16:09 +00:00
$this -> registerMappingFilesFromConfig ( $container , $config , $fileRecorder );
2014-12-25 03:17:33 +00:00
$chainLoader -> replaceArgument ( 0 , $serializerLoaders );
2016-08-02 10:38:04 +01:00
$container -> getDefinition ( 'serializer.mapping.cache_warmer' ) -> replaceArgument ( 0 , $serializerLoaders );
2014-12-25 03:17:33 +00:00
2017-10-20 20:28:39 +01:00
if ( ! $container -> getParameter ( 'kernel.debug' )) {
2016-04-25 18:10:03 +01:00
$cacheMetadataFactory = new Definition (
CacheClassMetadataFactory :: class ,
array (
2016-04-27 18:29:41 +01:00
new Reference ( 'serializer.mapping.cache_class_metadata_factory.inner' ),
2016-08-02 10:38:04 +01:00
new Reference ( 'serializer.mapping.cache.symfony' ),
2016-04-25 18:10:03 +01:00
)
);
$cacheMetadataFactory -> setPublic ( false );
$cacheMetadataFactory -> setDecoratedService ( 'serializer.mapping.class_metadata_factory' );
$container -> setDefinition ( 'serializer.mapping.cache_class_metadata_factory' , $cacheMetadataFactory );
2014-12-25 03:17:33 +00:00
}
2015-06-15 08:35:28 +01:00
2015-08-05 20:44:23 +01:00
if ( isset ( $config [ 'name_converter' ]) && $config [ 'name_converter' ]) {
2015-06-15 08:35:28 +01:00
$container -> getDefinition ( 'serializer.normalizer.object' ) -> replaceArgument ( 1 , new Reference ( $config [ 'name_converter' ]));
}
2017-03-15 16:25:41 +00:00
if ( isset ( $config [ 'circular_reference_handler' ]) && $config [ 'circular_reference_handler' ]) {
$container -> getDefinition ( 'serializer.normalizer.object' ) -> addMethodCall ( 'setCircularReferenceHandler' , array ( new Reference ( $config [ 'circular_reference_handler' ])));
}
2014-12-25 03:17:33 +00:00
}
2015-09-28 12:22:50 +01:00
private function registerPropertyInfoConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
$loader -> load ( 'property_info.xml' );
2016-02-29 21:59:13 +00:00
if ( interface_exists ( 'phpDocumentor\Reflection\DocBlockFactoryInterface' )) {
2015-09-28 12:22:50 +01:00
$definition = $container -> register ( 'property_info.php_doc_extractor' , 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor' );
2017-09-05 12:45:10 +01:00
$definition -> setPrivate ( true );
2015-09-28 12:22:50 +01:00
$definition -> addTag ( 'property_info.description_extractor' , array ( 'priority' => - 1000 ));
$definition -> addTag ( 'property_info.type_extractor' , array ( 'priority' => - 1001 ));
}
}
2017-01-29 19:47:50 +00:00
private function registerLockConfiguration ( array $config , ContainerBuilder $container , XmlFileLoader $loader )
{
$loader -> load ( 'lock.xml' );
foreach ( $config [ 'resources' ] as $resourceName => $resourceStores ) {
if ( 0 === count ( $resourceStores )) {
continue ;
}
// Generate stores
$storeDefinitions = array ();
foreach ( $resourceStores as $storeDsn ) {
$storeDsn = $container -> resolveEnvPlaceholders ( $storeDsn , null , $usedEnvs );
switch ( true ) {
case 'flock' === $storeDsn :
$storeDefinition = new Reference ( 'lock.store.flock' );
break ;
case 'semaphore' === $storeDsn :
$storeDefinition = new Reference ( 'lock.store.semaphore' );
break ;
case $usedEnvs || preg_match ( '#^[a-z]++://#' , $storeDsn ) :
if ( ! $container -> hasDefinition ( $connectionDefinitionId = $container -> hash ( $storeDsn ))) {
$connectionDefinition = new Definition ( \stdClass :: class );
$connectionDefinition -> setPublic ( false );
2017-09-28 18:35:07 +01:00
$connectionDefinition -> setFactory ( array ( AbstractAdapter :: class , 'createConnection' ));
2017-11-09 16:55:39 +00:00
$connectionDefinition -> setArguments ( array ( $storeDsn , array ( 'lazy' => true )));
2017-01-29 19:47:50 +00:00
$container -> setDefinition ( $connectionDefinitionId , $connectionDefinition );
}
$storeDefinition = new Definition ( StoreInterface :: class );
$storeDefinition -> setPublic ( false );
$storeDefinition -> setFactory ( array ( StoreFactory :: class , 'createStore' ));
$storeDefinition -> setArguments ( array ( new Reference ( $connectionDefinitionId )));
$container -> setDefinition ( $storeDefinitionId = 'lock.' . $resourceName . '.store.' . $container -> hash ( $storeDsn ), $storeDefinition );
$storeDefinition = new Reference ( $storeDefinitionId );
break ;
default :
throw new InvalidArgumentException ( sprintf ( 'Lock store DSN "%s" is not valid in resource "%s"' , $storeDsn , $resourceName ));
}
$storeDefinitions [] = $storeDefinition ;
}
// Wrap array of stores with CombinedStore
if ( count ( $storeDefinitions ) > 1 ) {
$combinedDefinition = new ChildDefinition ( 'lock.store.combined.abstract' );
$combinedDefinition -> replaceArgument ( 0 , $storeDefinitions );
$container -> setDefinition ( 'lock.' . $resourceName . '.store' , $combinedDefinition );
} else {
$container -> setAlias ( 'lock.' . $resourceName . '.store' , new Alias (( string ) $storeDefinitions [ 0 ], false ));
}
// Generate factories for each resource
$factoryDefinition = new ChildDefinition ( 'lock.factory.abstract' );
$factoryDefinition -> replaceArgument ( 0 , new Reference ( 'lock.' . $resourceName . '.store' ));
$container -> setDefinition ( 'lock.' . $resourceName . '.factory' , $factoryDefinition );
// Generate services for lock instances
$lockDefinition = new Definition ( Lock :: class );
$lockDefinition -> setPublic ( false );
$lockDefinition -> setFactory ( array ( new Reference ( 'lock.' . $resourceName . '.factory' ), 'createLock' ));
$lockDefinition -> setArguments ( array ( $resourceName ));
$container -> setDefinition ( 'lock.' . $resourceName , $lockDefinition );
// provide alias for default resource
if ( 'default' === $resourceName ) {
$container -> setAlias ( 'lock.store' , new Alias ( 'lock.' . $resourceName . '.store' , false ));
$container -> setAlias ( 'lock.factory' , new Alias ( 'lock.' . $resourceName . '.factory' , false ));
$container -> setAlias ( 'lock' , new Alias ( 'lock.' . $resourceName , false ));
$container -> setAlias ( StoreInterface :: class , new Alias ( 'lock.store' , false ));
$container -> setAlias ( Factory :: class , new Alias ( 'lock.factory' , false ));
$container -> setAlias ( LockInterface :: class , new Alias ( 'lock' , false ));
}
}
}
2016-06-07 15:56:06 +01:00
private function registerCacheConfiguration ( array $config , ContainerBuilder $container )
2016-02-20 23:25:19 +00:00
{
2018-01-03 11:52:04 +00:00
$version = new Parameter ( 'container.build_id' );
2016-05-16 10:02:32 +01:00
$container -> getDefinition ( 'cache.adapter.apcu' ) -> replaceArgument ( 2 , $version );
$container -> getDefinition ( 'cache.adapter.system' ) -> replaceArgument ( 2 , $version );
2016-04-28 17:07:16 +01:00
$container -> getDefinition ( 'cache.adapter.filesystem' ) -> replaceArgument ( 2 , $config [ 'directory' ]);
2016-04-23 19:46:00 +01:00
2016-11-23 18:16:07 +00:00
if ( isset ( $config [ 'prefix_seed' ])) {
$container -> setParameter ( 'cache.prefix.seed' , $config [ 'prefix_seed' ]);
}
2016-11-24 09:31:58 +00:00
if ( $container -> hasParameter ( 'cache.prefix.seed' )) {
// Inline any env vars referenced in the parameter
$container -> setParameter ( 'cache.prefix.seed' , $container -> resolveEnvPlaceholders ( $container -> getParameter ( 'cache.prefix.seed' ), true ));
}
2016-12-30 14:39:05 +00:00
foreach ( array ( 'doctrine' , 'psr6' , 'redis' , 'memcached' ) as $name ) {
2016-04-28 17:07:16 +01:00
if ( isset ( $config [ $name = 'default_' . $name . '_provider' ])) {
2016-11-28 06:44:11 +00:00
$container -> setAlias ( 'cache.' . $name , new Alias ( Compiler\CachePoolPass :: getServiceProvider ( $container , $config [ $name ]), false ));
2016-04-28 17:07:16 +01:00
}
2016-04-23 19:46:00 +01:00
}
2016-04-28 17:07:16 +01:00
foreach ( array ( 'app' , 'system' ) as $name ) {
$config [ 'pools' ][ 'cache.' . $name ] = array (
'adapter' => $config [ $name ],
'public' => true ,
);
}
foreach ( $config [ 'pools' ] as $name => $pool ) {
2016-11-28 07:50:06 +00:00
$definition = new ChildDefinition ( $pool [ 'adapter' ]);
2016-04-28 17:07:16 +01:00
$definition -> setPublic ( $pool [ 'public' ]);
unset ( $pool [ 'adapter' ], $pool [ 'public' ]);
2016-04-23 19:46:00 +01:00
2016-04-28 17:07:16 +01:00
$definition -> addTag ( 'cache.pool' , $pool );
$container -> setDefinition ( $name , $definition );
2016-02-20 23:25:19 +00:00
}
2016-04-06 18:53:33 +01:00
2015-12-04 22:03:03 +00:00
if ( method_exists ( PropertyAccessor :: class , 'createCache' )) {
$propertyAccessDefinition = $container -> register ( 'cache.property_access' , AdapterInterface :: class );
$propertyAccessDefinition -> setPublic ( false );
2017-03-08 19:24:49 +00:00
if ( ! $container -> getParameter ( 'kernel.debug' )) {
$propertyAccessDefinition -> setFactory ( array ( PropertyAccessor :: class , 'createCache' ));
$propertyAccessDefinition -> setArguments ( array ( null , null , $version , new Reference ( 'logger' , ContainerInterface :: IGNORE_ON_INVALID_REFERENCE )));
2017-09-26 10:37:36 +01:00
$propertyAccessDefinition -> addTag ( 'cache.pool' , array ( 'clearer' => 'cache.system_clearer' ));
2017-03-08 19:24:49 +00:00
$propertyAccessDefinition -> addTag ( 'monolog.logger' , array ( 'channel' => 'cache' ));
} else {
$propertyAccessDefinition -> setClass ( ArrayAdapter :: class );
$propertyAccessDefinition -> setArguments ( array ( 0 , false ));
}
2015-12-04 22:03:03 +00:00
}
2016-02-20 23:25:19 +00:00
}
2015-12-10 10:46:31 +00:00
/**
* Gets a hash of the kernel root directory .
*
* @ return string
*/
private function getKernelRootHash ( ContainerBuilder $container )
{
if ( ! $this -> kernelRootHash ) {
$this -> kernelRootHash = hash ( 'sha256' , $container -> getParameter ( 'kernel.root_dir' ));
}
return $this -> kernelRootHash ;
}
2010-05-06 12:25:53 +01:00
/**
* Returns the base path for the XSD files .
*
* @ return string The XSD base path
*/
public function getXsdValidationBasePath ()
2010-02-17 13:55:05 +00:00
{
2016-10-25 09:15:38 +01:00
return dirname ( __DIR__ ) . '/Resources/config/schema' ;
2010-02-17 13:55:05 +00:00
}
2010-05-06 12:25:53 +01:00
public function getNamespace ()
2010-02-17 13:55:05 +00:00
{
2011-03-06 11:40:06 +00:00
return 'http://symfony.com/schema/dic/symfony' ;
2010-02-17 13:55:05 +00:00
}
}