merged BuilderConfiguration and Builder classes into a new ContainerBuilder class
This commit is contained in:
parent
f26abdfadd
commit
7796eb213c
@ -4,7 +4,7 @@ namespace Symfony\Bundle\DoctrineBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
|
|
||||||
@ -54,13 +54,13 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
* <doctrine:dbal dbname="sfweb" user="root" />
|
* <doctrine:dbal dbname="sfweb" user="root" />
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function dbalLoad($config, BuilderConfiguration $configuration)
|
public function dbalLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('doctrine.dbal.logger')) {
|
if (!$container->hasDefinition('doctrine.dbal.logger')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['dbal']));
|
$container->merge($loader->load($this->resources['dbal']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultConnection = array(
|
$defaultConnection = array(
|
||||||
@ -75,9 +75,9 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
'options' => array()
|
'options' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $configuration->getParameter('doctrine.dbal.default_connection');
|
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $container->getParameter('doctrine.dbal.default_connection');
|
||||||
$configuration->setAlias('database_connection', null !== $this->alias ? $this->alias : sprintf('doctrine.dbal.%s_connection', $defaultConnectionName));
|
$container->setAlias('database_connection', null !== $this->alias ? $this->alias : sprintf('doctrine.dbal.%s_connection', $defaultConnectionName));
|
||||||
$configuration->setParameter('doctrine.dbal.default_connection', $defaultConnectionName);
|
$container->setParameter('doctrine.dbal.default_connection', $defaultConnectionName);
|
||||||
|
|
||||||
$connections = array();
|
$connections = array();
|
||||||
if (isset($config['connections'])) {
|
if (isset($config['connections'])) {
|
||||||
@ -90,25 +90,25 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
|
|
||||||
foreach ($connections as $name => $connection) {
|
foreach ($connections as $name => $connection) {
|
||||||
// previously registered?
|
// previously registered?
|
||||||
if ($configuration->hasDefinition(sprintf('doctrine.dbal.%s_connection', $name))) {
|
if ($container->hasDefinition(sprintf('doctrine.dbal.%s_connection', $name))) {
|
||||||
$driverDef = $configuration->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));
|
$driverDef = $container->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));
|
||||||
$arguments = $driverDef->getArguments();
|
$arguments = $driverDef->getArguments();
|
||||||
$driverOptions = $arguments[0];
|
$driverOptions = $arguments[0];
|
||||||
} else {
|
} else {
|
||||||
$connection = array_merge($defaultConnection, $connection);
|
$connection = array_merge($defaultConnection, $connection);
|
||||||
|
|
||||||
$configurationClass = isset($connection['configuration_class']) ? $connection['configuration_class'] : 'Doctrine\DBAL\Configuration';
|
$containerClass = isset($connection['configuration_class']) ? $connection['configuration_class'] : 'Doctrine\DBAL\Configuration';
|
||||||
$configurationDef = new Definition($configurationClass);
|
$containerDef = new Definition($containerClass);
|
||||||
$configurationDef->addMethodCall('setSqlLogger', array(new Reference('doctrine.dbal.logger')));
|
$containerDef->addMethodCall('setSqlLogger', array(new Reference('doctrine.dbal.logger')));
|
||||||
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), $configurationDef);
|
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), $containerDef);
|
||||||
|
|
||||||
$eventManagerDef = new Definition($connection['event_manager_class']);
|
$eventManagerDef = new Definition($connection['event_manager_class']);
|
||||||
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), $eventManagerDef);
|
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), $eventManagerDef);
|
||||||
|
|
||||||
$driverOptions = array();
|
$driverOptions = array();
|
||||||
$driverDef = new Definition('Doctrine\DBAL\DriverManager');
|
$driverDef = new Definition('Doctrine\DBAL\DriverManager');
|
||||||
$driverDef->setFactoryMethod('getConnection');
|
$driverDef->setFactoryMethod('getConnection');
|
||||||
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), $driverDef);
|
$container->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), $driverDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($connection['driver'])) {
|
if (isset($connection['driver'])) {
|
||||||
@ -138,35 +138,35 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
* Loads the Doctrine ORM configuration.
|
* Loads the Doctrine ORM configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function ormLoad($config, BuilderConfiguration $configuration)
|
public function ormLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['orm']));
|
$container->merge($loader->load($this->resources['orm']));
|
||||||
|
|
||||||
if (isset($config['default_entity_manager'])) {
|
if (isset($config['default_entity_manager'])) {
|
||||||
$configuration->getParameter('doctrine.orm.default_entity_manager', $config['default_entity_manager']);
|
$container->getParameter('doctrine.orm.default_entity_manager', $config['default_entity_manager']);
|
||||||
}
|
}
|
||||||
$defaultEntityManager = $configuration->getParameter('doctrine.orm.default_entity_manager');
|
$defaultEntityManager = $container->getParameter('doctrine.orm.default_entity_manager');
|
||||||
|
|
||||||
foreach (array('metadata_driver', 'cache_driver') as $key) {
|
foreach (array('metadata_driver', 'cache_driver') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$configuration->setParameter('doctrine.orm.'.$key, $config[$key]);
|
$container->setParameter('doctrine.orm.'.$key, $config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config['entity_managers'] = isset($config['entity_managers']) ? $config['entity_managers'] : array($defaultEntityManager => array());
|
$config['entity_managers'] = isset($config['entity_managers']) ? $config['entity_managers'] : array($defaultEntityManager => array());
|
||||||
foreach ($config['entity_managers'] as $name => $connection) {
|
foreach ($config['entity_managers'] as $name => $connection) {
|
||||||
$ormConfigDef = new Definition('Doctrine\ORM\Configuration');
|
$ormConfigDef = new Definition('Doctrine\ORM\Configuration');
|
||||||
$configuration->setDefinition(sprintf('doctrine.orm.%s_configuration', $name), $ormConfigDef);
|
$container->setDefinition(sprintf('doctrine.orm.%s_configuration', $name), $ormConfigDef);
|
||||||
|
|
||||||
$drivers = array('metadata', 'query', 'result');
|
$drivers = array('metadata', 'query', 'result');
|
||||||
foreach ($drivers as $driver) {
|
foreach ($drivers as $driver) {
|
||||||
$definition = $configuration->getDefinition(sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver')));
|
$definition = $container->getDefinition(sprintf('doctrine.orm.cache.%s', $container->getParameter('doctrine.orm.cache_driver')));
|
||||||
$clone = clone $definition;
|
$clone = clone $definition;
|
||||||
$clone->addMethodCall('setNamespace', array(sprintf('doctrine_%s_', $driver)));
|
$clone->addMethodCall('setNamespace', array(sprintf('doctrine_%s_', $driver)));
|
||||||
$configuration->setDefinition(sprintf('doctrine.orm.%s_cache', $driver), $clone);
|
$container->setDefinition(sprintf('doctrine.orm.%s_cache', $driver), $clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure metadata driver for each bundle based on the type of mapping files found
|
// configure metadata driver for each bundle based on the type of mapping files found
|
||||||
@ -205,7 +205,7 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
$ormConfigDef->addMethodCall('setEntityNamespaces', array($aliasMap));
|
$ormConfigDef->addMethodCall('setEntityNamespaces', array($aliasMap));
|
||||||
|
|
||||||
$configuration->setDefinition('doctrine.orm.metadata_driver', $mappingDriverDef);
|
$container->setDefinition('doctrine.orm.metadata_driver', $mappingDriverDef);
|
||||||
|
|
||||||
$methods = array(
|
$methods = array(
|
||||||
'setMetadataCacheImpl' => new Reference('doctrine.orm.metadata_cache'),
|
'setMetadataCacheImpl' => new Reference('doctrine.orm.metadata_cache'),
|
||||||
@ -231,24 +231,24 @@ class DoctrineExtension extends LoaderExtension
|
|||||||
$ormEmDef = new Definition('Doctrine\ORM\EntityManager', $ormEmArgs);
|
$ormEmDef = new Definition('Doctrine\ORM\EntityManager', $ormEmArgs);
|
||||||
$ormEmDef->setFactoryMethod('create');
|
$ormEmDef->setFactoryMethod('create');
|
||||||
|
|
||||||
$configuration->setDefinition(
|
$container->setDefinition(
|
||||||
sprintf('doctrine.orm.%s_entity_manager', $name),
|
sprintf('doctrine.orm.%s_entity_manager', $name),
|
||||||
$ormEmDef
|
$ormEmDef
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($name == $defaultEntityManager) {
|
if ($name == $defaultEntityManager) {
|
||||||
$configuration->setAlias(
|
$container->setAlias(
|
||||||
'doctrine.orm.entity_manager',
|
'doctrine.orm.entity_manager',
|
||||||
sprintf('doctrine.orm.%s_entity_manager', $name)
|
sprintf('doctrine.orm.%s_entity_manager', $name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setAlias(
|
$container->setAlias(
|
||||||
'doctrine.orm.cache',
|
'doctrine.orm.cache',
|
||||||
sprintf(
|
sprintf(
|
||||||
'doctrine.orm.cache.%s',
|
'doctrine.orm.cache.%s',
|
||||||
$configuration->getParameter('doctrine.orm.cache_driver')
|
$container->getParameter('doctrine.orm.cache_driver')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class DoctrineBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
@ -34,36 +34,36 @@ class MongoDBExtension extends LoaderExtension
|
|||||||
* Loads the MongoDB configuration.
|
* Loads the MongoDB configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function mongodbLoad($config, BuilderConfiguration $configuration)
|
public function mongodbLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['mongodb']));
|
$container->merge($loader->load($this->resources['mongodb']));
|
||||||
|
|
||||||
if (!$configuration->hasDefinition('doctrine.odm.mongodb.document_manager')) {
|
if (!$container->hasDefinition('doctrine.odm.mongodb.document_manager')) {
|
||||||
|
|
||||||
$configuration->setParameter('doctrine.odm.mongodb.mapping_dirs', $this->findBundleSubpaths('Resources/config/doctrine/metadata', $configuration));
|
$container->setParameter('doctrine.odm.mongodb.mapping_dirs', $this->findBundleSubpaths('Resources/config/doctrine/metadata', $container));
|
||||||
$configuration->setParameter('doctrine.odm.mongodb.document_dirs', $this->findBundleSubpaths('Document', $configuration));
|
$container->setParameter('doctrine.odm.mongodb.document_dirs', $this->findBundleSubpaths('Document', $container));
|
||||||
|
|
||||||
$configuration->setDefinition('doctrine.odm.mongodb.metadata', $this->buildMetadataDefinition($configuration));
|
$container->setDefinition('doctrine.odm.mongodb.metadata', $this->buildMetadataDefinition($container));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('host', 'port', 'database') as $key) {
|
foreach (array('host', 'port', 'database') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$configuration->setParameter('doctrine.odm.mongodb.default_'.$key, $config[$key]);
|
$container->setParameter('doctrine.odm.mongodb.default_'.$key, $config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('proxy_dir', 'auto_generate_proxy_classes') as $key) {
|
foreach (array('proxy_dir', 'auto_generate_proxy_classes') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$configuration->setParameter('doctrine.odm.mongodb.'.$key, $config[$key]);
|
$container->setParameter('doctrine.odm.mongodb.'.$key, $config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('cache', 'metadata') as $key) {
|
foreach (array('cache', 'metadata') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$configuration->setAlias('doctrine.odm.mongodb.'.$key, 'doctrine.odm.mongodb.'.$key.'.'.$config[$key]);
|
$container->setAlias('doctrine.odm.mongodb.'.$key, 'doctrine.odm.mongodb.'.$key.'.'.$config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,24 +72,24 @@ class MongoDBExtension extends LoaderExtension
|
|||||||
* Finds existing bundle subpaths.
|
* Finds existing bundle subpaths.
|
||||||
*
|
*
|
||||||
* @param string $path A subpath to check for
|
* @param string $path A subpath to check for
|
||||||
* @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A builder configuration
|
* @param Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder configuration
|
||||||
*
|
*
|
||||||
* @return array An array of absolute directory paths
|
* @return array An array of absolute directory paths
|
||||||
*/
|
*/
|
||||||
protected function findBundleSubpaths($path, BuilderConfiguration $configuration)
|
protected function findBundleSubpaths($path, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$dirs = array();
|
$dirs = array();
|
||||||
foreach ($this->bundles as $bundle) {
|
foreach ($this->bundles as $bundle) {
|
||||||
$reflection = new \ReflectionClass($bundle);
|
$reflection = new \ReflectionClass($bundle);
|
||||||
if (is_dir($dir = dirname($reflection->getFilename()).'/'.$path)) {
|
if (is_dir($dir = dirname($reflection->getFilename()).'/'.$path)) {
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
$configuration->addResource(new FileResource($dir));
|
$container->addResource(new FileResource($dir));
|
||||||
} else {
|
} else {
|
||||||
// add the closest existing parent directory as a file resource
|
// add the closest existing parent directory as a file resource
|
||||||
do {
|
do {
|
||||||
$dir = dirname($dir);
|
$dir = dirname($dir);
|
||||||
} while (!is_dir($dir));
|
} while (!is_dir($dir));
|
||||||
$configuration->addResource(new FileResource($dir));
|
$container->addResource(new FileResource($dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,17 +99,17 @@ class MongoDBExtension extends LoaderExtension
|
|||||||
/**
|
/**
|
||||||
* Detects and builds the appropriate metadata driver for each bundle.
|
* Detects and builds the appropriate metadata driver for each bundle.
|
||||||
*
|
*
|
||||||
* @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A builder configuration
|
* @param Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder configuration
|
||||||
*
|
*
|
||||||
* @return Symfony\Components\DependencyInjection\Definition A definition for the metadata service
|
* @return Symfony\Components\DependencyInjection\Definition A definition for the metadata service
|
||||||
*/
|
*/
|
||||||
protected function buildMetadataDefinition(BuilderConfiguration $configuration)
|
protected function buildMetadataDefinition(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$definition = new Definition('%doctrine.odm.mongodb.metadata.chain_class%');
|
$definition = new Definition('%doctrine.odm.mongodb.metadata.chain_class%');
|
||||||
|
|
||||||
foreach ($this->bundles as $bundle) {
|
foreach ($this->bundles as $bundle) {
|
||||||
$reflection = new \ReflectionClass($bundle);
|
$reflection = new \ReflectionClass($bundle);
|
||||||
if ($driver = static::detectMetadataDriver(dirname($reflection->getFilename()), $configuration)) {
|
if ($driver = static::detectMetadataDriver(dirname($reflection->getFilename()), $container)) {
|
||||||
$definition->addMethodCall('addDriver', array(
|
$definition->addMethodCall('addDriver', array(
|
||||||
new Reference('doctrine.odm.mongodb.metadata.'.$driver),
|
new Reference('doctrine.odm.mongodb.metadata.'.$driver),
|
||||||
$reflection->getNamespaceName().'\\Document',
|
$reflection->getNamespaceName().'\\Document',
|
||||||
@ -124,18 +124,18 @@ class MongoDBExtension extends LoaderExtension
|
|||||||
* Detects what metadata driver to use for the supplied directory.
|
* Detects what metadata driver to use for the supplied directory.
|
||||||
*
|
*
|
||||||
* @param string $dir A directory path
|
* @param string $dir A directory path
|
||||||
* @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A builder configuration
|
* @param Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder configuration
|
||||||
*
|
*
|
||||||
* @return string|null A metadata driver short name, if one can be detected
|
* @return string|null A metadata driver short name, if one can be detected
|
||||||
*/
|
*/
|
||||||
static protected function detectMetadataDriver($dir, BuilderConfiguration $configuration)
|
static protected function detectMetadataDriver($dir, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
// add the closest existing directory as a resource
|
// add the closest existing directory as a resource
|
||||||
$resource = $dir.'/Resources/config/doctrine/metadata';
|
$resource = $dir.'/Resources/config/doctrine/metadata';
|
||||||
while (!is_dir($resource)) {
|
while (!is_dir($resource)) {
|
||||||
$resource = dirname($resource);
|
$resource = dirname($resource);
|
||||||
}
|
}
|
||||||
$configuration->addResource(new FileResource($resource));
|
$container->addResource(new FileResource($resource));
|
||||||
|
|
||||||
if (count(glob($dir.'/Resources/config/doctrine/metadata/*.xml'))) {
|
if (count(glob($dir.'/Resources/config/doctrine/metadata/*.xml'))) {
|
||||||
return 'xml';
|
return 'xml';
|
||||||
@ -144,7 +144,7 @@ class MongoDBExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add the directory itself as a resource
|
// add the directory itself as a resource
|
||||||
$configuration->addResource(new FileResource($dir));
|
$container->addResource(new FileResource($dir));
|
||||||
|
|
||||||
if (is_dir($dir.'/Document')) {
|
if (is_dir($dir.'/Document')) {
|
||||||
return 'annotation';
|
return 'annotation';
|
||||||
|
@ -21,7 +21,7 @@ class DoctrineMongoDBBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
|
|||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
|
|
||||||
@ -48,17 +48,17 @@ class WebExtension extends LoaderExtension
|
|||||||
* Loads the web configuration.
|
* Loads the web configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function configLoad($config, BuilderConfiguration $configuration)
|
public function configLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('controller_manager')) {
|
if (!$container->hasDefinition('controller_manager')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['web']));
|
$container->merge($loader->load($this->resources['web']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['ide']) && 'textmate' === $config['ide']) {
|
if (isset($config['ide']) && 'textmate' === $config['ide']) {
|
||||||
$configuration->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
|
$container->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['toolbar']) && $config['toolbar']) {
|
if (isset($config['toolbar']) && $config['toolbar']) {
|
||||||
@ -67,33 +67,33 @@ class WebExtension extends LoaderExtension
|
|||||||
|
|
||||||
if (isset($config['profiler'])) {
|
if (isset($config['profiler'])) {
|
||||||
if ($config['profiler']) {
|
if ($config['profiler']) {
|
||||||
if (!$configuration->hasDefinition('profiler')) {
|
if (!$container->hasDefinition('profiler')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load('profiling.xml'));
|
$container->merge($loader->load('profiling.xml'));
|
||||||
$configuration->merge($loader->load('collectors.xml'));
|
$container->merge($loader->load('collectors.xml'));
|
||||||
}
|
}
|
||||||
} elseif ($configuration->hasDefinition('profiler')) {
|
} elseif ($container->hasDefinition('profiler')) {
|
||||||
$configuration->getDefinition('profiling')->clearAnnotations();
|
$container->getDefinition('profiling')->clearAnnotations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// toolbar need to be registered after the profiler
|
// toolbar need to be registered after the profiler
|
||||||
if (isset($config['toolbar'])) {
|
if (isset($config['toolbar'])) {
|
||||||
if ($config['toolbar']) {
|
if ($config['toolbar']) {
|
||||||
if (!$configuration->hasDefinition('debug.toolbar')) {
|
if (!$container->hasDefinition('debug.toolbar')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load('toolbar.xml'));
|
$container->merge($loader->load('toolbar.xml'));
|
||||||
}
|
}
|
||||||
} elseif ($configuration->hasDefinition('debug.toolbar')) {
|
} elseif ($container->hasDefinition('debug.toolbar')) {
|
||||||
$configuration->getDefinition('debug.toolbar')->clearAnnotations();
|
$container->getDefinition('debug.toolbar')->clearAnnotations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['validation']['enabled'])) {
|
if (isset($config['validation']['enabled'])) {
|
||||||
if ($config['validation']['enabled']) {
|
if ($config['validation']['enabled']) {
|
||||||
if (!$configuration->hasDefinition('validator')) {
|
if (!$container->hasDefinition('validator')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['validation']));
|
$container->merge($loader->load($this->resources['validation']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$xmlMappingFiles = array();
|
$xmlMappingFiles = array();
|
||||||
@ -126,42 +126,42 @@ class WebExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
$xmlFilesLoader = new Definition(
|
$xmlFilesLoader = new Definition(
|
||||||
$configuration->getParameter('validator.mapping.loader.xml_files_loader.class'),
|
$container->getParameter('validator.mapping.loader.xml_files_loader.class'),
|
||||||
array($xmlMappingFiles)
|
array($xmlMappingFiles)
|
||||||
);
|
);
|
||||||
|
|
||||||
$yamlFilesLoader = new Definition(
|
$yamlFilesLoader = new Definition(
|
||||||
$configuration->getParameter('validator.mapping.loader.yaml_files_loader.class'),
|
$container->getParameter('validator.mapping.loader.yaml_files_loader.class'),
|
||||||
array($yamlMappingFiles)
|
array($yamlMappingFiles)
|
||||||
);
|
);
|
||||||
|
|
||||||
$configuration->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
|
$container->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
|
||||||
$configuration->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
|
$container->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
|
||||||
$configuration->setParameter('validator.message_interpolator.files', $messageFiles);
|
$container->setParameter('validator.message_interpolator.files', $messageFiles);
|
||||||
|
|
||||||
foreach ($xmlMappingFiles as $file) {
|
foreach ($xmlMappingFiles as $file) {
|
||||||
$configuration->addResource(new FileResource($file));
|
$container->addResource(new FileResource($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($yamlMappingFiles as $file) {
|
foreach ($yamlMappingFiles as $file) {
|
||||||
$configuration->addResource(new FileResource($file));
|
$container->addResource(new FileResource($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($messageFiles as $file) {
|
foreach ($messageFiles as $file) {
|
||||||
$configuration->addResource(new FileResource($file));
|
$container->addResource(new FileResource($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['validation']['annotations']) && $config['validation']['annotations'] === true) {
|
if (isset($config['validation']['annotations']) && $config['validation']['annotations'] === true) {
|
||||||
$annotationLoader = new Definition($configuration->getParameter('validator.mapping.loader.annotation_loader.class'));
|
$annotationLoader = new Definition($container->getParameter('validator.mapping.loader.annotation_loader.class'));
|
||||||
$configuration->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
|
$container->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
|
||||||
|
|
||||||
$loader = $configuration->getDefinition('validator.mapping.loader.loader_chain');
|
$loader = $container->getDefinition('validator.mapping.loader.loader_chain');
|
||||||
$arguments = $loader->getArguments();
|
$arguments = $loader->getArguments();
|
||||||
array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader'));
|
array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader'));
|
||||||
$loader->setArguments($arguments);
|
$loader->setArguments($arguments);
|
||||||
}
|
}
|
||||||
} elseif ($configuration->hasDefinition('validator')) {
|
} elseif ($container->hasDefinition('validator')) {
|
||||||
$configuration->getDefinition('validator')->clearAnnotations();
|
$container->getDefinition('validator')->clearAnnotations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,26 +170,26 @@ class WebExtension extends LoaderExtension
|
|||||||
* Loads the templating configuration.
|
* Loads the templating configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function templatingLoad($config, BuilderConfiguration $configuration)
|
public function templatingLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('templating')) {
|
if (!$container->hasDefinition('templating')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['templating']));
|
$container->merge($loader->load($this->resources['templating']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('escaping', $config)) {
|
if (array_key_exists('escaping', $config)) {
|
||||||
$configuration->setParameter('templating.output_escaper', $config['escaping']);
|
$container->setParameter('templating.output_escaper', $config['escaping']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('assets_version', $config)) {
|
if (array_key_exists('assets_version', $config)) {
|
||||||
$configuration->setParameter('templating.assets.version', $config['assets_version']);
|
$container->setParameter('templating.assets.version', $config['assets_version']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// path for the filesystem loader
|
// path for the filesystem loader
|
||||||
if (isset($config['path'])) {
|
if (isset($config['path'])) {
|
||||||
$configuration->setParameter('templating.loader.filesystem.path', $config['path']);
|
$container->setParameter('templating.loader.filesystem.path', $config['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// loaders
|
// loaders
|
||||||
@ -201,20 +201,20 @@ class WebExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (1 === count($loaders)) {
|
if (1 === count($loaders)) {
|
||||||
$configuration->setAlias('templating.loader', (string) $loaders[0]);
|
$container->setAlias('templating.loader', (string) $loaders[0]);
|
||||||
} else {
|
} else {
|
||||||
$configuration->getDefinition('templating.loader.chain')->addArgument($loaders);
|
$container->getDefinition('templating.loader.chain')->addArgument($loaders);
|
||||||
$configuration->setAlias('templating.loader', 'templating.loader.chain');
|
$container->setAlias('templating.loader', 'templating.loader.chain');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache?
|
// cache?
|
||||||
$configuration->setParameter('templating.loader.cache.path', null);
|
$container->setParameter('templating.loader.cache.path', null);
|
||||||
if (isset($config['cache'])) {
|
if (isset($config['cache'])) {
|
||||||
// wrap the loader with some cache
|
// wrap the loader with some cache
|
||||||
$configuration->setDefinition('templating.loader.wrapped', $configuration->findDefinition('templating.loader'));
|
$container->setDefinition('templating.loader.wrapped', $container->findDefinition('templating.loader'));
|
||||||
$configuration->setDefinition('templating.loader', $configuration->getDefinition('templating.loader.cache'));
|
$container->setDefinition('templating.loader', $container->getDefinition('templating.loader.cache'));
|
||||||
$configuration->setParameter('templating.loader.cache.path', $config['cache']);
|
$container->setParameter('templating.loader.cache.path', $config['cache']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use Symfony\Framework\Bundle\Bundle;
|
|||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Components\DependencyInjection\Loader\Loader;
|
use Symfony\Components\DependencyInjection\Loader\Loader;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\WebExtension;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\WebExtension;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -32,7 +32,7 @@ class FrameworkBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
@ -44,12 +44,12 @@ class FrameworkBundle extends Bundle
|
|||||||
}
|
}
|
||||||
$parameterBag->set('templating.loader.filesystem.path', $dirs);
|
$parameterBag->set('templating.loader.filesystem.path', $dirs);
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder();
|
||||||
if ($parameterBag->get('kernel.debug')) {
|
if ($parameterBag->get('kernel.debug')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/Resources/config');
|
||||||
$configuration->merge($loader->load('debug.xml'));
|
$container->merge($loader->load('debug.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Bundle\PropelBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
|
|
||||||
@ -18,29 +18,29 @@ class PropelExtension extends LoaderExtension
|
|||||||
* Loads the Propel configuration.
|
* Loads the Propel configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function configLoad($config, BuilderConfiguration $configuration)
|
public function configLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('propel')) {
|
if (!$container->hasDefinition('propel')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['propel']));
|
$container->merge($loader->load($this->resources['propel']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$configuration->hasParameter('propel.path')) {
|
if (!$container->hasParameter('propel.path')) {
|
||||||
if (!isset($config['path'])) {
|
if (!isset($config['path'])) {
|
||||||
throw new \InvalidArgumentException('The "path" parameter is mandatory.');
|
throw new \InvalidArgumentException('The "path" parameter is mandatory.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setParameter('propel.path', $config['path']);
|
$container->setParameter('propel.path', $config['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['path'])) {
|
if (isset($config['path'])) {
|
||||||
$configuration->setParameter('propel.path', $config['path']);
|
$container->setParameter('propel.path', $config['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['phing_path'])) {
|
if (isset($config['phing_path'])) {
|
||||||
$configuration->setParameter('propel.phing_path', $config['phing_path']);
|
$container->setParameter('propel.phing_path', $config['phing_path']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,13 +48,13 @@ class PropelExtension extends LoaderExtension
|
|||||||
* Loads the DBAL configuration.
|
* Loads the DBAL configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function dbalLoad($config, BuilderConfiguration $configuration)
|
public function dbalLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('propel')) {
|
if (!$container->hasDefinition('propel')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['propel']));
|
$container->merge($loader->load($this->resources['propel']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultConnection = array(
|
$defaultConnection = array(
|
||||||
@ -70,8 +70,8 @@ class PropelExtension extends LoaderExtension
|
|||||||
'settings' => array('charset' => array('value' => 'UTF8')),
|
'settings' => array('charset' => array('value' => 'UTF8')),
|
||||||
);
|
);
|
||||||
|
|
||||||
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $configuration->getParameter('propel.dbal.default_connection');
|
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $container->getParameter('propel.dbal.default_connection');
|
||||||
$configuration->setParameter('propel.dbal.default_connection', $defaultConnectionName);
|
$container->setParameter('propel.dbal.default_connection', $defaultConnectionName);
|
||||||
|
|
||||||
$connections = array();
|
$connections = array();
|
||||||
if (isset($config['connections'])) {
|
if (isset($config['connections'])) {
|
||||||
@ -82,7 +82,7 @@ class PropelExtension extends LoaderExtension
|
|||||||
$connections = array($defaultConnectionName => $config);
|
$connections = array($defaultConnectionName => $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = $configuration->getDefinition('propel.configuration')->getArguments();
|
$arguments = $container->getDefinition('propel.configuration')->getArguments();
|
||||||
if (count($arguments)) {
|
if (count($arguments)) {
|
||||||
$c = $arguments[0];
|
$c = $arguments[0];
|
||||||
} else {
|
} else {
|
||||||
@ -113,7 +113,7 @@ class PropelExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->getDefinition('propel.configuration')->setArguments(array($c));
|
$container->getDefinition('propel.configuration')->setArguments(array($c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@ class PropelBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -41,20 +41,20 @@ class SwiftMailerExtension extends LoaderExtension
|
|||||||
* </swift:mailer>
|
* </swift:mailer>
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function mailerLoad($config, BuilderConfiguration $configuration)
|
public function mailerLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('swiftmailer.mailer')) {
|
if (!$container->hasDefinition('swiftmailer.mailer')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['mailer']));
|
$container->merge($loader->load($this->resources['mailer']));
|
||||||
$configuration->setAlias('mailer', 'swiftmailer.mailer');
|
$container->setAlias('mailer', 'swiftmailer.mailer');
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = new \ReflectionClass('Swift_Message');
|
$r = new \ReflectionClass('Swift_Message');
|
||||||
$configuration->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename()))));
|
$container->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename()))));
|
||||||
|
|
||||||
$transport = $configuration->getParameter('swiftmailer.transport.name');
|
$transport = $container->getParameter('swiftmailer.transport.name');
|
||||||
if (array_key_exists('transport', $config)) {
|
if (array_key_exists('transport', $config)) {
|
||||||
if (null === $config['transport']) {
|
if (null === $config['transport']) {
|
||||||
$transport = 'null';
|
$transport = 'null';
|
||||||
@ -67,10 +67,10 @@ class SwiftMailerExtension extends LoaderExtension
|
|||||||
$transport = $config['transport'];
|
$transport = $config['transport'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setParameter('swiftmailer.transport.name', $transport);
|
$container->setParameter('swiftmailer.transport.name', $transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$transport);
|
$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.'.$transport);
|
||||||
|
|
||||||
if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
|
if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
|
||||||
$config['port'] = 465;
|
$config['port'] = 465;
|
||||||
@ -78,7 +78,7 @@ class SwiftMailerExtension extends LoaderExtension
|
|||||||
|
|
||||||
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
|
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$configuration->setParameter('swiftmailer.transport.'.$transport.'.'.$key, $config[$key]);
|
$container->setParameter('swiftmailer.transport.'.$transport.'.'.$key, $config[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,24 +86,24 @@ class SwiftMailerExtension extends LoaderExtension
|
|||||||
if (isset($config['spool'])) {
|
if (isset($config['spool'])) {
|
||||||
$type = isset($config['type']) ? $config['type'] : 'file';
|
$type = isset($config['type']) ? $config['type'] : 'file';
|
||||||
|
|
||||||
$configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$transport);
|
$container->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.'.$transport);
|
||||||
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
|
$container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
|
||||||
$configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
|
$container->setAlias('swiftmailer.spool', 'swiftmailer.spool.'.$type);
|
||||||
|
|
||||||
foreach (array('path') as $key) {
|
foreach (array('path') as $key) {
|
||||||
if (isset($config['spool'][$key])) {
|
if (isset($config['spool'][$key])) {
|
||||||
$configuration->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]);
|
$container->setParameter('swiftmailer.spool.'.$type.'.'.$key, $config['spool'][$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['delivery_address'])) {
|
if (isset($config['delivery_address'])) {
|
||||||
$configuration->setParameter('swiftmailer.single_address', $config['delivery_address']);
|
$container->setParameter('swiftmailer.single_address', $config['delivery_address']);
|
||||||
$configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
|
$container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['disable_delivery']) && $config['disable_delivery']) {
|
if (isset($config['disable_delivery']) && $config['disable_delivery']) {
|
||||||
$configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
|
$container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class SwiftmailerBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -28,16 +28,16 @@ class TwigExtension extends LoaderExtension
|
|||||||
* Loads the Twig configuration.
|
* Loads the Twig configuration.
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function configLoad($config, BuilderConfiguration $configuration)
|
public function configLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('twig')) {
|
if (!$container->hasDefinition('twig')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load('twig.xml'));
|
$container->merge($loader->load('twig.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setParameter('twig.options', array_replace($configuration->getParameter('twig.options'), $config));
|
$container->setParameter('twig.options', array_replace($container->getParameter('twig.options'), $config));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@ use Symfony\Framework\Bundle\Bundle;
|
|||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Components\DependencyInjection\Loader\Loader;
|
use Symfony\Components\DependencyInjection\Loader\Loader;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -32,7 +32,7 @@ class TwigBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Bundle\ZendBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -36,22 +36,22 @@ class ZendExtension extends LoaderExtension
|
|||||||
* <zend:logger priority="info" path="/path/to/some.log" />
|
* <zend:logger priority="info" path="/path/to/some.log" />
|
||||||
*
|
*
|
||||||
* @param array $config An array of configuration settings
|
* @param array $config An array of configuration settings
|
||||||
* @param \Symfony\Components\DependencyInjection\BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function loggerLoad($config, BuilderConfiguration $configuration)
|
public function loggerLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('zend.logger')) {
|
if (!$container->hasDefinition('zend.logger')) {
|
||||||
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
||||||
$configuration->merge($loader->load($this->resources['logger']));
|
$container->merge($loader->load($this->resources['logger']));
|
||||||
$configuration->setAlias('logger', 'zend.logger');
|
$container->setAlias('logger', 'zend.logger');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['priority'])) {
|
if (isset($config['priority'])) {
|
||||||
$configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority'])));
|
$container->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['path'])) {
|
if (isset($config['path'])) {
|
||||||
$configuration->setParameter('zend.logger.path', $config['path']);
|
$container->setParameter('zend.logger.path', $config['path']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class ZendBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -1,375 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection;
|
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtensionInterface;
|
|
||||||
use Symfony\Components\DependencyInjection\Resource\ResourceInterface;
|
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony framework.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*
|
|
||||||
* This source file is subject to the MIT license that is bundled
|
|
||||||
* with this source code in the file LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A BuilderConfiguration is a consistent set of definitions and parameters.
|
|
||||||
*
|
|
||||||
* @package Symfony
|
|
||||||
* @subpackage Components_DependencyInjection
|
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*/
|
|
||||||
class BuilderConfiguration
|
|
||||||
{
|
|
||||||
protected $definitions;
|
|
||||||
protected $parameterBag;
|
|
||||||
protected $aliases;
|
|
||||||
protected $resources;
|
|
||||||
protected $extensions;
|
|
||||||
|
|
||||||
public function __construct(array $definitions = array(), ParameterBagInterface $parameterBag = null)
|
|
||||||
{
|
|
||||||
$this->aliases = array();
|
|
||||||
$this->resources = array();
|
|
||||||
$this->extensions = array();
|
|
||||||
|
|
||||||
$this->setDefinitions($definitions);
|
|
||||||
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of resources loaded to build this configuration.
|
|
||||||
*
|
|
||||||
* @return ResourceInterface[] An array of resources
|
|
||||||
*/
|
|
||||||
public function getResources()
|
|
||||||
{
|
|
||||||
return array_unique($this->resources);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a resource for this configuration.
|
|
||||||
*
|
|
||||||
* @param ResourceInterface $resource A resource instance
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function addResource(ResourceInterface $resource)
|
|
||||||
{
|
|
||||||
$this->resources[] = $resource;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges a BuilderConfiguration with the current one.
|
|
||||||
*
|
|
||||||
* @param BuilderConfiguration $configuration
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function merge(BuilderConfiguration $configuration = null)
|
|
||||||
{
|
|
||||||
if (null === $configuration) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addDefinitions($configuration->getDefinitions());
|
|
||||||
$this->addAliases($configuration->getAliases());
|
|
||||||
$this->parameterBag->add($configuration->getParameterBag()->all());
|
|
||||||
|
|
||||||
foreach ($configuration->getResources() as $resource) {
|
|
||||||
$this->addResource($resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the configuration for an extension.
|
|
||||||
*
|
|
||||||
* @param LoaderExtensionInterface $extension A LoaderExtensionInterface instance
|
|
||||||
* @param string $tag The extension tag to load (without the namespace - namespace.tag)
|
|
||||||
* @param array $values An array of values that customizes the extension
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function loadFromExtension(LoaderExtensionInterface $extension, $tag, array $values = array())
|
|
||||||
{
|
|
||||||
$namespace = $extension->getAlias();
|
|
||||||
|
|
||||||
$this->addObjectResource($extension);
|
|
||||||
|
|
||||||
if (!isset($this->extensions[$namespace])) {
|
|
||||||
$this->extensions[$namespace] = new self();
|
|
||||||
|
|
||||||
$r = new \ReflectionObject($extension);
|
|
||||||
$this->extensions[$namespace]->addResource(new FileResource($r->getFileName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$extension->load($tag, $values, $this->extensions[$namespace]);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the object class hierarchy as resources.
|
|
||||||
*
|
|
||||||
* @param object $object An object instance
|
|
||||||
*/
|
|
||||||
public function addObjectResource($object)
|
|
||||||
{
|
|
||||||
$parent = new \ReflectionObject($object);
|
|
||||||
$this->addResource(new FileResource($parent->getFileName()));
|
|
||||||
while ($parent = $parent->getParentClass()) {
|
|
||||||
$this->addResource(new FileResource($parent->getFileName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges the extension configuration.
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function mergeExtensionsConfiguration()
|
|
||||||
{
|
|
||||||
foreach ($this->extensions as $name => $configuration) {
|
|
||||||
$this->merge($configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->extensions = array();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the parameter bag.
|
|
||||||
*
|
|
||||||
* @return Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface A ParameterBagInterface instance
|
|
||||||
*/
|
|
||||||
public function getParameterBag()
|
|
||||||
{
|
|
||||||
return $this->parameterBag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a parameter.
|
|
||||||
*
|
|
||||||
* @param string $name The parameter name
|
|
||||||
*
|
|
||||||
* @return mixed The parameter value
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if the parameter is not defined
|
|
||||||
*/
|
|
||||||
public function getParameter($name)
|
|
||||||
{
|
|
||||||
return $this->parameterBag->get($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a parameter.
|
|
||||||
*
|
|
||||||
* @param string $name The parameter name
|
|
||||||
* @param mixed $parameters The parameter value
|
|
||||||
*/
|
|
||||||
public function setParameter($name, $value)
|
|
||||||
{
|
|
||||||
$this->parameterBag->set($name, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a parameter is defined.
|
|
||||||
*
|
|
||||||
* @param string $name The parameter name
|
|
||||||
*/
|
|
||||||
public function hasParameter($name)
|
|
||||||
{
|
|
||||||
return $this->parameterBag->has($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets an alias for an existing service.
|
|
||||||
*
|
|
||||||
* @param string $alias The alias to create
|
|
||||||
* @param string $id The service to alias
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function setAlias($alias, $id)
|
|
||||||
{
|
|
||||||
unset($this->definitions[$alias]);
|
|
||||||
|
|
||||||
$this->aliases[$alias] = $id;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds definition aliases.
|
|
||||||
*
|
|
||||||
* @param array $aliases An array of aliases
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function addAliases(array $aliases)
|
|
||||||
{
|
|
||||||
foreach ($aliases as $alias => $id) {
|
|
||||||
$this->setAlias($alias, $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all defined aliases.
|
|
||||||
*
|
|
||||||
* @return array An array of aliases
|
|
||||||
*/
|
|
||||||
public function getAliases()
|
|
||||||
{
|
|
||||||
return $this->aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a service alias exists.
|
|
||||||
*
|
|
||||||
* @param string $alias The alias
|
|
||||||
*
|
|
||||||
* @return Boolean true if the alias exists, false otherwise
|
|
||||||
*/
|
|
||||||
public function hasAlias($alias)
|
|
||||||
{
|
|
||||||
return array_key_exists($alias, $this->aliases);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the service id for a given alias.
|
|
||||||
*
|
|
||||||
* @param string $alias The alias
|
|
||||||
*
|
|
||||||
* @return string The aliased id
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if the service alias does not exist
|
|
||||||
*/
|
|
||||||
public function getAlias($alias)
|
|
||||||
{
|
|
||||||
if (!$this->hasAlias($alias)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $alias));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->aliases[$alias];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a definition.
|
|
||||||
*
|
|
||||||
* @param string $id The identifier
|
|
||||||
* @param Definition $definition A Definition instance
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function setDefinition($id, Definition $definition)
|
|
||||||
{
|
|
||||||
unset($this->aliases[$id]);
|
|
||||||
|
|
||||||
$this->definitions[$id] = $definition;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the definitions.
|
|
||||||
*
|
|
||||||
* @param Definition[] $definitions An array of definitions
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function addDefinitions(array $definitions)
|
|
||||||
{
|
|
||||||
foreach ($definitions as $id => $definition) {
|
|
||||||
$this->setDefinition($id, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the definitions.
|
|
||||||
*
|
|
||||||
* @param array $definitions An array of definitions
|
|
||||||
*
|
|
||||||
* @return BuilderConfiguration The current instance
|
|
||||||
*/
|
|
||||||
public function setDefinitions(array $definitions)
|
|
||||||
{
|
|
||||||
$this->definitions = array();
|
|
||||||
$this->addDefinitions($definitions);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all definitions.
|
|
||||||
*
|
|
||||||
* @return array An array of Definition instances
|
|
||||||
*/
|
|
||||||
public function getDefinitions()
|
|
||||||
{
|
|
||||||
return $this->definitions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a service definition exists under the given identifier.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
|
||||||
*
|
|
||||||
* @return Boolean true if the service definition exists, false otherwise
|
|
||||||
*/
|
|
||||||
public function hasDefinition($id)
|
|
||||||
{
|
|
||||||
return array_key_exists($id, $this->definitions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a service definition.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
|
||||||
*
|
|
||||||
* @return Definition A Definition instance
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if the service definition does not exist
|
|
||||||
*/
|
|
||||||
public function getDefinition($id)
|
|
||||||
{
|
|
||||||
if (!$this->hasDefinition($id)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->definitions[$id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a service definition by id or alias.
|
|
||||||
*
|
|
||||||
* The method "unaliases" recursively to return a Definition instance.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier or alias
|
|
||||||
*
|
|
||||||
* @return Definition A Definition instance
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if the service definition does not exist
|
|
||||||
*/
|
|
||||||
public function findDefinition($id)
|
|
||||||
{
|
|
||||||
if ($this->hasAlias($id)) {
|
|
||||||
return $this->findDefinition($this->getAlias($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getDefinition($id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection;
|
namespace Symfony\Components\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtensionInterface;
|
||||||
|
use Symfony\Components\DependencyInjection\Resource\ResourceInterface;
|
||||||
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
*
|
*
|
||||||
@ -12,17 +16,84 @@ namespace Symfony\Components\DependencyInjection;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder is a DI container that provides an interface to build the services.
|
* ContainerBuilder is a DI container that provides an API to easily describe services.
|
||||||
*
|
*
|
||||||
* @package Symfony
|
* @package Symfony
|
||||||
* @subpackage Components_DependencyInjection
|
* @subpackage Components_DependencyInjection
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
*/
|
*/
|
||||||
class Builder extends Container implements AnnotatedContainerInterface
|
class ContainerBuilder extends Container implements AnnotatedContainerInterface
|
||||||
{
|
{
|
||||||
protected $definitions = array();
|
protected $definitions = array();
|
||||||
protected $aliases = array();
|
protected $aliases = array();
|
||||||
protected $loading = array();
|
protected $loading = array();
|
||||||
|
protected $resources = array();
|
||||||
|
protected $extensions = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of resources loaded to build this configuration.
|
||||||
|
*
|
||||||
|
* @return ResourceInterface[] An array of resources
|
||||||
|
*/
|
||||||
|
public function getResources()
|
||||||
|
{
|
||||||
|
return array_unique($this->resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a resource for this configuration.
|
||||||
|
*
|
||||||
|
* @param ResourceInterface $resource A resource instance
|
||||||
|
*
|
||||||
|
* @return ContainerBuilder The current instance
|
||||||
|
*/
|
||||||
|
public function addResource(ResourceInterface $resource)
|
||||||
|
{
|
||||||
|
$this->resources[] = $resource;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object class hierarchy as resources.
|
||||||
|
*
|
||||||
|
* @param object $object An object instance
|
||||||
|
*/
|
||||||
|
public function addObjectResource($object)
|
||||||
|
{
|
||||||
|
$parent = new \ReflectionObject($object);
|
||||||
|
$this->addResource(new FileResource($parent->getFileName()));
|
||||||
|
while ($parent = $parent->getParentClass()) {
|
||||||
|
$this->addResource(new FileResource($parent->getFileName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the configuration for an extension.
|
||||||
|
*
|
||||||
|
* @param LoaderExtensionInterface $extension A LoaderExtensionInterface instance
|
||||||
|
* @param string $tag The extension tag to load (without the namespace - namespace.tag)
|
||||||
|
* @param array $values An array of values that customizes the extension
|
||||||
|
*
|
||||||
|
* @return ContainerBuilder The current instance
|
||||||
|
*/
|
||||||
|
public function loadFromExtension(LoaderExtensionInterface $extension, $tag, array $values = array())
|
||||||
|
{
|
||||||
|
$namespace = $extension->getAlias();
|
||||||
|
|
||||||
|
$this->addObjectResource($extension);
|
||||||
|
|
||||||
|
if (!isset($this->extensions[$namespace])) {
|
||||||
|
$this->extensions[$namespace] = new self($this->parameterBag);
|
||||||
|
|
||||||
|
$r = new \ReflectionObject($extension);
|
||||||
|
$this->extensions[$namespace]->addResource(new FileResource($r->getFileName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$extension->load($tag, $values, $this->extensions[$namespace]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a service.
|
* Sets a service.
|
||||||
@ -97,7 +168,7 @@ class Builder extends Container implements AnnotatedContainerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges a BuilderConfiguration with the current Builder configuration.
|
* Merges a ContainerBuilder with the current ContainerBuilder configuration.
|
||||||
*
|
*
|
||||||
* Service definitions overrides the current defined ones.
|
* Service definitions overrides the current defined ones.
|
||||||
*
|
*
|
||||||
@ -105,33 +176,65 @@ class Builder extends Container implements AnnotatedContainerInterface
|
|||||||
* the parameters passed to the container constructor to have precedence
|
* the parameters passed to the container constructor to have precedence
|
||||||
* over the loaded ones.
|
* over the loaded ones.
|
||||||
*
|
*
|
||||||
* $container = new Builder(array('foo' => 'bar'));
|
* $container = new ContainerBuilder(array('foo' => 'bar'));
|
||||||
* $loader = new LoaderXXX($container);
|
* $loader = new LoaderXXX($container);
|
||||||
* $loader->load('resource_name');
|
* $loader->load('resource_name');
|
||||||
* $container->register('foo', new stdClass());
|
* $container->register('foo', new stdClass());
|
||||||
*
|
*
|
||||||
* In the above example, even if the loaded resource defines a foo
|
* In the above example, even if the loaded resource defines a foo
|
||||||
* parameter, the value will still be 'bar' as defined in the builder
|
* parameter, the value will still be 'bar' as defined in the ContainerBuilder
|
||||||
* constructor.
|
* constructor.
|
||||||
*/
|
*/
|
||||||
public function merge(BuilderConfiguration $configuration = null)
|
public function merge(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (null === $configuration) {
|
$this->addDefinitions($container->getDefinitions());
|
||||||
return;
|
$this->addAliases($container->getAliases());
|
||||||
|
$this->parameterBag->add($container->getParameterBag()->all());
|
||||||
|
|
||||||
|
foreach ($container->getResources() as $resource) {
|
||||||
|
$this->addResource($resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addDefinitions($configuration->getDefinitions());
|
foreach ($container->getExtensionContainers() as $name => $container) {
|
||||||
$this->addAliases($configuration->getAliases());
|
if (isset($this->extensions[$name])) {
|
||||||
|
$this->extensions[$name]->merge($container);
|
||||||
$parameterBag = $this->getParameterBag();
|
} else {
|
||||||
$currentParameters = $parameterBag->all();
|
$this->extensions[$name] = $container;
|
||||||
foreach ($configuration->getParameterBag()->all() as $key => $value) {
|
}
|
||||||
$parameterBag->set($key, $value);
|
|
||||||
}
|
}
|
||||||
$parameterBag->add($currentParameters);
|
}
|
||||||
|
|
||||||
foreach ($parameterBag->all() as $key => $value) {
|
/**
|
||||||
$parameterBag->set($key, self::resolveValue($value, $this->getParameterBag()->all()));
|
* Returns the containers for the registered extensions.
|
||||||
|
*
|
||||||
|
* @return LoaderExtensionInterface[] An array of extension containers
|
||||||
|
*/
|
||||||
|
public function getExtensionContainers()
|
||||||
|
{
|
||||||
|
return $this->extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits the extension configuration into the main configuration
|
||||||
|
* and resolves parameter values.
|
||||||
|
*/
|
||||||
|
public function commit()
|
||||||
|
{
|
||||||
|
$parameters = $this->parameterBag->all();
|
||||||
|
$definitions = $this->definitions;
|
||||||
|
$aliases = $this->aliases;
|
||||||
|
|
||||||
|
foreach ($this->extensions as $container) {
|
||||||
|
$this->merge($container);
|
||||||
|
}
|
||||||
|
$this->extensions = array();
|
||||||
|
|
||||||
|
$this->addDefinitions($definitions);
|
||||||
|
$this->addAliases($aliases);
|
||||||
|
$this->parameterBag->add($parameters);
|
||||||
|
|
||||||
|
foreach ($this->parameterBag->all() as $key => $value) {
|
||||||
|
$this->parameterBag->set($key, self::resolveValue($value, $this->getParameterBag()->all()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,6 +416,26 @@ class Builder extends Container implements AnnotatedContainerInterface
|
|||||||
return $this->definitions[$id];
|
return $this->definitions[$id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a service definition by id or alias.
|
||||||
|
*
|
||||||
|
* The method "unaliases" recursively to return a Definition instance.
|
||||||
|
*
|
||||||
|
* @param string $id The service identifier or alias
|
||||||
|
*
|
||||||
|
* @return Definition A Definition instance
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if the service definition does not exist
|
||||||
|
*/
|
||||||
|
public function findDefinition($id)
|
||||||
|
{
|
||||||
|
if ($this->hasAlias($id)) {
|
||||||
|
return $this->findDefinition($this->getAlias($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getDefinition($id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a service for a service definition.
|
* Creates a service for a service definition.
|
||||||
*
|
*
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Dumper;
|
namespace Symfony\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -27,9 +27,9 @@ abstract class Dumper implements DumperInterface
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Builder $container The service container to dump
|
* @param ContainerBuilder $container The service container to dump
|
||||||
*/
|
*/
|
||||||
public function __construct(Builder $container)
|
public function __construct(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ namespace Symfony\Components\DependencyInjection\Dumper;
|
|||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\Parameter;
|
use Symfony\Components\DependencyInjection\Parameter;
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -159,7 +159,7 @@ class GraphvizDumper extends Dumper
|
|||||||
|
|
||||||
protected function getValue($value, $default = '')
|
protected function getValue($value, $default = '')
|
||||||
{
|
{
|
||||||
return Builder::resolveValue($value, $this->container->getParameterBag()->all());
|
return ContainerBuilder::resolveValue($value, $this->container->getParameterBag()->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function startDot()
|
protected function startDot()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Dumper;
|
namespace Symfony\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Container;
|
use Symfony\Components\DependencyInjection\Container;
|
||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
@ -354,7 +354,7 @@ EOF;
|
|||||||
|
|
||||||
protected function wrapServiceConditionals($value, $code)
|
protected function wrapServiceConditionals($value, $code)
|
||||||
{
|
{
|
||||||
if (!$services = Builder::getServiceConditionals($value)) {
|
if (!$services = ContainerBuilder::getServiceConditionals($value)) {
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Loader;
|
namespace Symfony\Components\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -26,23 +26,22 @@ class IniFileLoader extends FileLoader
|
|||||||
/**
|
/**
|
||||||
* Loads a resource.
|
* Loads a resource.
|
||||||
*
|
*
|
||||||
* @param mixed $resource The resource
|
* @param mixed $resource The resource
|
||||||
* @param Boolean $main Whether this is the main load() call
|
* @param ContainerBuilder $container A ContainerBuilder instance to use for the configuration
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance to use for the configuration
|
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When ini file is not valid
|
* @throws \InvalidArgumentException When ini file is not valid
|
||||||
*/
|
*/
|
||||||
public function load($file, $main = true, BuilderConfiguration $configuration = null)
|
public function load($file, ContainerBuilder $container = null)
|
||||||
{
|
{
|
||||||
$path = $this->findFile($file);
|
$path = $this->findFile($file);
|
||||||
|
|
||||||
if (null === $configuration) {
|
if (null === $container) {
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->addResource(new FileResource($path));
|
$container->addResource(new FileResource($path));
|
||||||
|
|
||||||
$result = parse_ini_file($path, true);
|
$result = parse_ini_file($path, true);
|
||||||
if (false === $result || array() === $result) {
|
if (false === $result || array() === $result) {
|
||||||
@ -51,10 +50,10 @@ class IniFileLoader extends FileLoader
|
|||||||
|
|
||||||
if (isset($result['parameters']) && is_array($result['parameters'])) {
|
if (isset($result['parameters']) && is_array($result['parameters'])) {
|
||||||
foreach ($result['parameters'] as $key => $value) {
|
foreach ($result['parameters'] as $key => $value) {
|
||||||
$configuration->setParameter($key, $value);
|
$container->setParameter($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Loader;
|
namespace Symfony\Components\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -22,29 +22,16 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||||||
*/
|
*/
|
||||||
abstract class LoaderExtension implements LoaderExtensionInterface
|
abstract class LoaderExtension implements LoaderExtensionInterface
|
||||||
{
|
{
|
||||||
protected $resources = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a configuration entry point for the given extension name.
|
|
||||||
*
|
|
||||||
* @param string $name The configuration extension name
|
|
||||||
* @param mixed $resource A resource
|
|
||||||
*/
|
|
||||||
public function setConfiguration($name, $resource)
|
|
||||||
{
|
|
||||||
$this->resources[$name] = $resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a specific configuration.
|
* Loads a specific configuration.
|
||||||
*
|
*
|
||||||
* @param string $tag The tag name
|
* @param string $tag The tag name
|
||||||
* @param array $config An array of configuration values
|
* @param array $config An array of configuration values
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param ContainerBuilder $configuration A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
||||||
*/
|
*/
|
||||||
public function load($tag, array $config, BuilderConfiguration $configuration)
|
public function load($tag, array $config, ContainerBuilder $configuration)
|
||||||
{
|
{
|
||||||
if (!method_exists($this, $method = $tag.'Load')) {
|
if (!method_exists($this, $method = $tag.'Load')) {
|
||||||
throw new \InvalidArgumentException(sprintf('The tag "%s:%s" is not defined in the "%s" extension.', $this->getAlias(), $tag, $this->getAlias()));
|
throw new \InvalidArgumentException(sprintf('The tag "%s:%s" is not defined in the "%s" extension.', $this->getAlias(), $tag, $this->getAlias()));
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Loader;
|
namespace Symfony\Components\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -22,26 +22,18 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||||||
*/
|
*/
|
||||||
interface LoaderExtensionInterface
|
interface LoaderExtensionInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Sets a configuration entry point for the given extension name.
|
|
||||||
*
|
|
||||||
* @param string $name The configuration extension name
|
|
||||||
* @param mixed $resource A resource
|
|
||||||
*/
|
|
||||||
public function setConfiguration($name, $resource);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a specific configuration.
|
* Loads a specific configuration.
|
||||||
*
|
*
|
||||||
* @param string $tag The tag name
|
* @param string $tag The tag name
|
||||||
* @param array $config An array of configuration values
|
* @param array $config An array of configuration values
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param ContainerBuilder $configuration A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension
|
||||||
*/
|
*/
|
||||||
public function load($tag, array $config, BuilderConfiguration $configuration);
|
public function load($tag, array $config, ContainerBuilder $configuration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the namespace to be used for this extension (XML namespace).
|
* Returns the namespace to be used for this extension (XML namespace).
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Components\DependencyInjection\Loader;
|
namespace Symfony\Components\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -19,7 +19,7 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||||||
* $loader = new XXXLoader();
|
* $loader = new XXXLoader();
|
||||||
* $config = $loader->load('resource_name');
|
* $config = $loader->load('resource_name');
|
||||||
*
|
*
|
||||||
* $container = new Builder();
|
* $container = new ContainerBuilder();
|
||||||
* $container->merge($config);
|
* $container->merge($config);
|
||||||
*
|
*
|
||||||
* @package Symfony
|
* @package Symfony
|
||||||
@ -32,7 +32,7 @@ interface LoaderInterface
|
|||||||
* Loads a resource.
|
* Loads a resource.
|
||||||
*
|
*
|
||||||
* A resource can be anything that can be converted to a
|
* A resource can be anything that can be converted to a
|
||||||
* BuilderConfiguration instance.
|
* ContainerBuilder instance.
|
||||||
*
|
*
|
||||||
* Some loaders support an array of resources as an argument to the
|
* Some loaders support an array of resources as an argument to the
|
||||||
* constructor.
|
* constructor.
|
||||||
@ -58,13 +58,12 @@ interface LoaderInterface
|
|||||||
* If you load file1.xml and file2.xml in this order, the value of complex
|
* If you load file1.xml and file2.xml in this order, the value of complex
|
||||||
* will be "foo".
|
* will be "foo".
|
||||||
*
|
*
|
||||||
* @param mixed $resource The resource
|
* @param mixed $resource The resource
|
||||||
* @param Boolean $main Whether this is the main load() call
|
* @param ContainerBuilder $container A ContainerBuilder instance to use for the configuration
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance to use for the configuration
|
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
function load($resource, $main = true, BuilderConfiguration $configuration = null);
|
function load($resource, ContainerBuilder $container = null);
|
||||||
|
|
||||||
static function registerExtension(LoaderExtensionInterface $extension);
|
static function registerExtension(LoaderExtensionInterface $extension);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Components\DependencyInjection\Loader;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\SimpleXMLElement;
|
use Symfony\Components\DependencyInjection\SimpleXMLElement;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
|
|
||||||
@ -29,67 +29,62 @@ class XmlFileLoader extends FileLoader
|
|||||||
/**
|
/**
|
||||||
* Loads an array of XML files.
|
* Loads an array of XML files.
|
||||||
*
|
*
|
||||||
* @param mixed $resource The resource
|
* @param mixed $resource The resource
|
||||||
* @param Boolean $main Whether this is the main load() call
|
* @param ContainerBuilder $container A ContainerBuilder instance to use for the configuration
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance to use for the configuration
|
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function load($file, $main = true, BuilderConfiguration $configuration = null)
|
public function load($file, ContainerBuilder $container = null)
|
||||||
{
|
{
|
||||||
$path = $this->findFile($file);
|
$path = $this->findFile($file);
|
||||||
|
|
||||||
$xml = $this->parseFile($path);
|
$xml = $this->parseFile($path);
|
||||||
|
|
||||||
if (null === $configuration) {
|
if (null === $container) {
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->addResource(new FileResource($path));
|
$container->addResource(new FileResource($path));
|
||||||
|
|
||||||
// anonymous services
|
// anonymous services
|
||||||
$xml = $this->processAnonymousServices($configuration, $xml, $file);
|
$xml = $this->processAnonymousServices($container, $xml, $file);
|
||||||
|
|
||||||
// imports
|
// imports
|
||||||
$this->parseImports($configuration, $xml, $file);
|
$this->parseImports($container, $xml, $file);
|
||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
$this->loadFromExtensions($configuration, $xml);
|
$this->loadFromExtensions($container, $xml);
|
||||||
|
|
||||||
if ($main) {
|
|
||||||
$configuration->mergeExtensionsConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
$this->parseParameters($configuration, $xml, $file);
|
$this->parseParameters($container, $xml, $file);
|
||||||
|
|
||||||
// services
|
// services
|
||||||
$this->parseDefinitions($configuration, $xml, $file);
|
$this->parseDefinitions($container, $xml, $file);
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseParameters(BuilderConfiguration $configuration, $xml, $file)
|
protected function parseParameters(ContainerBuilder $container, $xml, $file)
|
||||||
{
|
{
|
||||||
if (!$xml->parameters) {
|
if (!$xml->parameters) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->getParameterBag()->add($xml->parameters->getArgumentsAsPhp('parameter'));
|
$container->getParameterBag()->add($xml->parameters->getArgumentsAsPhp('parameter'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseImports(BuilderConfiguration $configuration, $xml, $file)
|
protected function parseImports(ContainerBuilder $container, $xml, $file)
|
||||||
{
|
{
|
||||||
if (!$xml->imports) {
|
if (!$xml->imports) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($xml->imports->import as $import) {
|
foreach ($xml->imports->import as $import) {
|
||||||
$this->parseImport($configuration, $import, $file);
|
$this->parseImport($container, $import, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseImport(BuilderConfiguration $configuration, $import, $file)
|
protected function parseImport(ContainerBuilder $container, $import, $file)
|
||||||
{
|
{
|
||||||
$class = null;
|
$class = null;
|
||||||
if (isset($import['class']) && $import['class'] !== get_class($this)) {
|
if (isset($import['class']) && $import['class'] !== get_class($this)) {
|
||||||
@ -110,24 +105,24 @@ class XmlFileLoader extends FileLoader
|
|||||||
|
|
||||||
$importedFile = $this->getAbsolutePath((string) $import['resource'], dirname($file));
|
$importedFile = $this->getAbsolutePath((string) $import['resource'], dirname($file));
|
||||||
|
|
||||||
return $loader->load($importedFile, false, $configuration);
|
return $loader->load($importedFile, $container);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseDefinitions(BuilderConfiguration $configuration, $xml, $file)
|
protected function parseDefinitions(ContainerBuilder $container, $xml, $file)
|
||||||
{
|
{
|
||||||
if (!$xml->services) {
|
if (!$xml->services) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($xml->services->service as $service) {
|
foreach ($xml->services->service as $service) {
|
||||||
$this->parseDefinition($configuration, (string) $service['id'], $service, $file);
|
$this->parseDefinition($container, (string) $service['id'], $service, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseDefinition(BuilderConfiguration $configuration, $id, $service, $file)
|
protected function parseDefinition(ContainerBuilder $container, $id, $service, $file)
|
||||||
{
|
{
|
||||||
if ((string) $service['alias']) {
|
if ((string) $service['alias']) {
|
||||||
$configuration->setAlias($id, (string) $service['alias']);
|
$container->setAlias($id, (string) $service['alias']);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -178,7 +173,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$definition->addAnnotation((string) $annotation['name'], $parameters);
|
$definition->addAnnotation((string) $annotation['name'], $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setDefinition($id, $definition);
|
$container->setDefinition($id, $definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,7 +194,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
return simplexml_import_dom($dom, 'Symfony\\Components\\DependencyInjection\\SimpleXMLElement');
|
return simplexml_import_dom($dom, 'Symfony\\Components\\DependencyInjection\\SimpleXMLElement');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processAnonymousServices(BuilderConfiguration $configuration, $xml, $file)
|
protected function processAnonymousServices(ContainerBuilder $container, $xml, $file)
|
||||||
{
|
{
|
||||||
$definitions = array();
|
$definitions = array();
|
||||||
$count = 0;
|
$count = 0;
|
||||||
@ -218,7 +213,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
// resolve definitions
|
// resolve definitions
|
||||||
krsort($definitions);
|
krsort($definitions);
|
||||||
foreach ($definitions as $id => $def) {
|
foreach ($definitions as $id => $def) {
|
||||||
$this->parseDefinition($configuration, $id, $def[0], $def[1]);
|
$this->parseDefinition($container, $id, $def[0], $def[1]);
|
||||||
|
|
||||||
$oNode = dom_import_simplexml($def[0]);
|
$oNode = dom_import_simplexml($def[0]);
|
||||||
$oNode->parentNode->removeChild($oNode);
|
$oNode->parentNode->removeChild($oNode);
|
||||||
@ -321,7 +316,7 @@ EOF
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadFromExtensions(BuilderConfiguration $configuration, $xml)
|
protected function loadFromExtensions(ContainerBuilder $container, $xml)
|
||||||
{
|
{
|
||||||
foreach (dom_import_simplexml($xml)->childNodes as $node) {
|
foreach (dom_import_simplexml($xml)->childNodes as $node) {
|
||||||
if (!$node instanceof \DOMElement || $node->namespaceURI === 'http://www.symfony-project.org/schema/dic/services') {
|
if (!$node instanceof \DOMElement || $node->namespaceURI === 'http://www.symfony-project.org/schema/dic/services') {
|
||||||
@ -333,7 +328,7 @@ EOF
|
|||||||
$values = array();
|
$values = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->loadFromExtension($this->getExtension($node->namespaceURI), $node->localName, $values);
|
$container->loadFromExtension($this->getExtension($node->namespaceURI), $node->localName, $values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace Symfony\Components\DependencyInjection\Loader;
|
|||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
use Symfony\Components\Yaml\Yaml;
|
use Symfony\Components\Yaml\Yaml;
|
||||||
|
|
||||||
@ -32,63 +32,58 @@ class YamlFileLoader extends FileLoader
|
|||||||
/**
|
/**
|
||||||
* Loads an array of Yaml files.
|
* Loads an array of Yaml files.
|
||||||
*
|
*
|
||||||
* @param mixed $resource The resource
|
* @param mixed $resource The resource
|
||||||
* @param Boolean $main Whether this is the main load() call
|
* @param ContainerBuilder $container A ContainerBuilder instance to use for the configuration
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance to use for the configuration
|
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function load($file, $main = true, BuilderConfiguration $configuration = null)
|
public function load($file, ContainerBuilder $container = null)
|
||||||
{
|
{
|
||||||
$path = $this->findFile($file);
|
$path = $this->findFile($file);
|
||||||
|
|
||||||
$content = $this->loadFile($path);
|
$content = $this->loadFile($path);
|
||||||
|
|
||||||
if (null === $configuration) {
|
if (null === $container) {
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->addResource(new FileResource($path));
|
$container->addResource(new FileResource($path));
|
||||||
|
|
||||||
if (!$content) {
|
if (!$content) {
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
// imports
|
// imports
|
||||||
$this->parseImports($configuration, $content, $file);
|
$this->parseImports($container, $content, $file);
|
||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
$this->loadFromExtensions($configuration, $content);
|
$this->loadFromExtensions($container, $content);
|
||||||
|
|
||||||
if ($main) {
|
|
||||||
$configuration->mergeExtensionsConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
if (isset($content['parameters'])) {
|
if (isset($content['parameters'])) {
|
||||||
foreach ($content['parameters'] as $key => $value) {
|
foreach ($content['parameters'] as $key => $value) {
|
||||||
$configuration->setParameter($key, $this->resolveServices($value));
|
$container->setParameter($key, $this->resolveServices($value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// services
|
// services
|
||||||
$this->parseDefinitions($configuration, $content, $file);
|
$this->parseDefinitions($container, $content, $file);
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseImports(BuilderConfiguration $configuration, $content, $file)
|
protected function parseImports(ContainerBuilder $container, $content, $file)
|
||||||
{
|
{
|
||||||
if (!isset($content['imports'])) {
|
if (!isset($content['imports'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($content['imports'] as $import) {
|
foreach ($content['imports'] as $import) {
|
||||||
$this->parseImport($configuration, $import, $file);
|
$this->parseImport($container, $import, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseImport(BuilderConfiguration $configuration, $import, $file)
|
protected function parseImport(ContainerBuilder $container, $import, $file)
|
||||||
{
|
{
|
||||||
$class = null;
|
$class = null;
|
||||||
if (isset($import['class']) && $import['class'] !== get_class($this)) {
|
if (isset($import['class']) && $import['class'] !== get_class($this)) {
|
||||||
@ -109,24 +104,24 @@ class YamlFileLoader extends FileLoader
|
|||||||
|
|
||||||
$importedFile = $this->getAbsolutePath($import['resource'], dirname($file));
|
$importedFile = $this->getAbsolutePath($import['resource'], dirname($file));
|
||||||
|
|
||||||
return $loader->load($importedFile, false, $configuration);
|
return $loader->load($importedFile, $container);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseDefinitions(BuilderConfiguration $configuration, $content, $file)
|
protected function parseDefinitions(ContainerBuilder $container, $content, $file)
|
||||||
{
|
{
|
||||||
if (!isset($content['services'])) {
|
if (!isset($content['services'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($content['services'] as $id => $service) {
|
foreach ($content['services'] as $id => $service) {
|
||||||
$this->parseDefinition($configuration, $id, $service, $file);
|
$this->parseDefinition($container, $id, $service, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseDefinition(BuilderConfiguration $configuration, $id, $service, $file)
|
protected function parseDefinition(ContainerBuilder $container, $id, $service, $file)
|
||||||
{
|
{
|
||||||
if (is_string($service) && 0 === strpos($service, '@')) {
|
if (is_string($service) && 0 === strpos($service, '@')) {
|
||||||
$configuration->setAlias($id, substr($service, 1));
|
$container->setAlias($id, substr($service, 1));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -180,7 +175,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setDefinition($id, $definition);
|
$container->setDefinition($id, $definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadFile($file)
|
protected function loadFile($file)
|
||||||
@ -235,7 +230,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadFromExtensions(BuilderConfiguration $configuration, $content)
|
protected function loadFromExtensions(ContainerBuilder $container, $content)
|
||||||
{
|
{
|
||||||
foreach ($content as $key => $values) {
|
foreach ($content as $key => $values) {
|
||||||
if (in_array($key, array('imports', 'parameters', 'services'))) {
|
if (in_array($key, array('imports', 'parameters', 'services'))) {
|
||||||
@ -248,7 +243,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
$values = array();
|
$values = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->loadFromExtension($this->getExtension($namespace), $tag, $values);
|
$container->loadFromExtension($this->getExtension($namespace), $tag, $values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ abstract class Bundle implements BundleInterface
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ interface BundleInterface
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag);
|
public function buildContainer(ParameterBagInterface $parameterBag);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Framework\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony package.
|
* This file is part of the Symfony package.
|
||||||
@ -24,41 +24,41 @@ use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|||||||
*/
|
*/
|
||||||
class KernelExtension extends LoaderExtension
|
class KernelExtension extends LoaderExtension
|
||||||
{
|
{
|
||||||
public function testLoad($config, BuilderConfiguration $configuration)
|
public function testLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
$configuration->merge($loader->load('test.xml'));
|
$container->merge($loader->load('test.xml'));
|
||||||
$configuration->setParameter('kernel.include_core_classes', false);
|
$container->setParameter('kernel.include_core_classes', false);
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the session configuration.
|
* Loads the session configuration.
|
||||||
*
|
*
|
||||||
* @param array $config A configuration array
|
* @param array $config A configuration array
|
||||||
* @param BuilderConfiguration $configuration A BuilderConfiguration instance
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||||
*
|
*
|
||||||
* @return BuilderConfiguration A BuilderConfiguration instance
|
* @return ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function sessionLoad($config, BuilderConfiguration $configuration)
|
public function sessionLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('session')) {
|
if (!$container->hasDefinition('session')) {
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
$configuration->merge($loader->load('session.xml'));
|
$container->merge($loader->load('session.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['default_locale'])) {
|
if (isset($config['default_locale'])) {
|
||||||
$configuration->setParameter('session.default_locale', $config['default_locale']);
|
$container->setParameter('session.default_locale', $config['default_locale']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['class'])) {
|
if (isset($config['class'])) {
|
||||||
$configuration->setParameter('session.class', $config['class']);
|
$container->setParameter('session.class', $config['class']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('name', 'auto_start', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
|
foreach (array('name', 'auto_start', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
|
||||||
if (isset($config['session'][$name])) {
|
if (isset($config['session'][$name])) {
|
||||||
$configuration->setParameter('session.options.'.$name, $config['session'][$name]);
|
$container->setParameter('session.options.'.$name, $config['session'][$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +68,16 @@ class KernelExtension extends LoaderExtension
|
|||||||
$class = 'Symfony\\Framework\\FrameworkBundle\\SessionStorage\\'.$class.'SessionStorage';
|
$class = 'Symfony\\Framework\\FrameworkBundle\\SessionStorage\\'.$class.'SessionStorage';
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->setParameter('session.session', 'session.session.'.strtolower($class));
|
$container->setParameter('session.session', 'session.session.'.strtolower($class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configLoad($config, BuilderConfiguration $configuration)
|
public function configLoad($config, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
if (isset($config['charset'])) {
|
if (isset($config['charset'])) {
|
||||||
$configuration->setParameter('kernel.charset', $config['charset']);
|
$container->setParameter('kernel.charset', $config['charset']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists('compilation', $config)) {
|
if (!array_key_exists('compilation', $config)) {
|
||||||
@ -113,13 +113,13 @@ class KernelExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$configuration->setParameter('kernel.compiled_classes', $classes);
|
$container->setParameter('kernel.compiled_classes', $classes);
|
||||||
|
|
||||||
if (array_key_exists('error_handler_level', $config)) {
|
if (array_key_exists('error_handler_level', $config)) {
|
||||||
$configuration->setParameter('error_handler.level', $config['error_handler_level']);
|
$container->setParameter('error_handler.level', $config['error_handler_level']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
namespace Symfony\Framework;
|
namespace Symfony\Framework;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|
||||||
use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
|
use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
@ -340,18 +339,18 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
|
|||||||
{
|
{
|
||||||
$parameterBag = new ParameterBag($this->getKernelParameters());
|
$parameterBag = new ParameterBag($this->getKernelParameters());
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder($parameterBag);
|
||||||
foreach ($this->bundles as $bundle) {
|
foreach ($this->bundles as $bundle) {
|
||||||
$configuration->merge($bundle->buildContainer($parameterBag));
|
if (null !== $c = $bundle->buildContainer($parameterBag)) {
|
||||||
|
$container->merge($c);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
$configuration->addObjectResource($bundle);
|
$container->addObjectResource($bundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$configuration->merge($this->registerContainerConfiguration());
|
$container->merge($this->registerContainerConfiguration());
|
||||||
|
$container->commit();
|
||||||
$container = new Builder($parameterBag);
|
|
||||||
$container->merge($configuration);
|
|
||||||
$container->freeze();
|
$container->freeze();
|
||||||
|
|
||||||
foreach (array('cache', 'logs') as $name) {
|
foreach (array('cache', 'logs') as $name) {
|
||||||
@ -374,10 +373,10 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
|
|||||||
$this->writeCacheFile($file, $content);
|
$this->writeCacheFile($file, $content);
|
||||||
|
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
$configuration->addObjectResource($this);
|
$container->addObjectResource($this);
|
||||||
|
|
||||||
// save the resources
|
// save the resources
|
||||||
$this->writeCacheFile($this->getCacheDir().'/'.$class.'.meta', serialize($configuration->getResources()));
|
$this->writeCacheFile($this->getCacheDir().'/'.$class.'.meta', serialize($container->getResources()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Loader\Loader;
|
use Symfony\Components\DependencyInjection\Loader\Loader;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony framework.
|
* This file is part of the Symfony framework.
|
||||||
@ -34,23 +34,23 @@ class KernelBundle extends Bundle
|
|||||||
*
|
*
|
||||||
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
* @param \Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag A ParameterBagInterface instance
|
||||||
*
|
*
|
||||||
* @return \Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
|
* @return \Symfony\Components\DependencyInjection\ContainerBuilder A ContainerBuilder instance
|
||||||
*/
|
*/
|
||||||
public function buildContainer(ParameterBagInterface $parameterBag)
|
public function buildContainer(ParameterBagInterface $parameterBag)
|
||||||
{
|
{
|
||||||
Loader::registerExtension(new KernelExtension());
|
Loader::registerExtension(new KernelExtension());
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration();
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
$configuration->merge($loader->load('services.xml'));
|
$container->merge($loader->load('services.xml'));
|
||||||
|
|
||||||
if ($parameterBag->get('kernel.debug')) {
|
if ($parameterBag->get('kernel.debug')) {
|
||||||
$configuration->merge($loader->load('debug.xml'));
|
$container->merge($loader->load('debug.xml'));
|
||||||
$configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher'));
|
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configuration;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,7 +132,7 @@ use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Loader\Loader;
|
use Symfony\Components\DependencyInjection\Loader\Loader;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class KernelBundle extends Bundle
|
|||||||
{
|
{
|
||||||
Loader::registerExtension(new KernelExtension());
|
Loader::registerExtension(new KernelExtension());
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration();
|
$configuration = new ContainerBuilder();
|
||||||
|
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
$configuration->merge($loader->load('services.xml'));
|
$configuration->merge($loader->load('services.xml'));
|
||||||
@ -173,14 +173,14 @@ namespace Symfony\Framework\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class KernelExtension extends LoaderExtension
|
class KernelExtension extends LoaderExtension
|
||||||
{
|
{
|
||||||
public function testLoad($config, BuilderConfiguration $configuration)
|
public function testLoad($config, ContainerBuilder $configuration)
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
$configuration->merge($loader->load('test.xml'));
|
$configuration->merge($loader->load('test.xml'));
|
||||||
@ -190,7 +190,7 @@ class KernelExtension extends LoaderExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function sessionLoad($config, BuilderConfiguration $configuration)
|
public function sessionLoad($config, ContainerBuilder $configuration)
|
||||||
{
|
{
|
||||||
if (!$configuration->hasDefinition('session')) {
|
if (!$configuration->hasDefinition('session')) {
|
||||||
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
$loader = new XmlFileLoader(array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
|
||||||
@ -223,7 +223,7 @@ class KernelExtension extends LoaderExtension
|
|||||||
return $configuration;
|
return $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configLoad($config, BuilderConfiguration $configuration)
|
public function configLoad($config, ContainerBuilder $configuration)
|
||||||
{
|
{
|
||||||
if (isset($config['charset'])) {
|
if (isset($config['charset'])) {
|
||||||
$configuration->setParameter('kernel.charset', $config['charset']);
|
$configuration->setParameter('kernel.charset', $config['charset']);
|
||||||
|
@ -1,211 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection;
|
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
|
||||||
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
|
||||||
|
|
||||||
class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
static protected $fixturesPath;
|
|
||||||
|
|
||||||
static public function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
self::$fixturesPath = __DIR__.'/Fixtures/';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::__construct
|
|
||||||
*/
|
|
||||||
public function testConstructor()
|
|
||||||
{
|
|
||||||
$definitions = array(
|
|
||||||
'foo' => new Definition('FooClass'),
|
|
||||||
'bar' => new Definition('BarClass'),
|
|
||||||
);
|
|
||||||
$parameters = array(
|
|
||||||
'foo' => 'foo',
|
|
||||||
'bar' => 'bar',
|
|
||||||
);
|
|
||||||
$configuration = new BuilderConfiguration($definitions, new ParameterBag($parameters));
|
|
||||||
$this->assertEquals($definitions, $configuration->getDefinitions(), '__construct() takes an array of definitions as its first argument');
|
|
||||||
$this->assertEquals($parameters, $configuration->getParameterBag()->all(), '__construct() takes a ParameterBag instance as its second argument');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::merge
|
|
||||||
*/
|
|
||||||
public function testMerge()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$configuration->merge(null);
|
|
||||||
$this->assertEquals(array(), $configuration->getParameterBag()->all(), '->merge() accepts null as an argument');
|
|
||||||
$this->assertEquals(array(), $configuration->getDefinitions(), '->merge() accepts null as an argument');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration(array(), new ParameterBag(array('bar' => 'foo')));
|
|
||||||
$configuration1 = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
|
||||||
$configuration->merge($configuration1);
|
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $configuration->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration(array(), new ParameterBag(array('bar' => 'foo', 'foo' => 'baz')));
|
|
||||||
$config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
|
||||||
$configuration->merge($config);
|
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $configuration->getParameterBag()->all(), '->merge() overrides existing parameters');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration(array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass')));
|
|
||||||
$config = new BuilderConfiguration(array('baz' => new Definition('BazClass')));
|
|
||||||
$config->setAlias('alias_for_foo', 'foo');
|
|
||||||
$configuration->merge($config);
|
|
||||||
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($configuration->getDefinitions()), '->merge() merges definitions already defined ones');
|
|
||||||
$this->assertEquals(array('alias_for_foo' => 'foo'), $configuration->getAliases(), '->merge() registers defined aliases');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration(array('foo' => new Definition('FooClass')));
|
|
||||||
$config->setDefinition('foo', new Definition('BazClass'));
|
|
||||||
$configuration->merge($config);
|
|
||||||
$this->assertEquals('BazClass', $configuration->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$configuration->addResource($a = new FileResource(self::$fixturesPath.'/xml/services1.xml'));
|
|
||||||
$config = new BuilderConfiguration();
|
|
||||||
$config->addResource($b = new FileResource(self::$fixturesPath.'/xml/services2.xml'));
|
|
||||||
$configuration->merge($config);
|
|
||||||
$this->assertEquals(array($a, $b), $configuration->getResources(), '->merge() merges resources');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getParameterBag
|
|
||||||
*/
|
|
||||||
public function testGetParameterBag()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$this->assertEquals(array(), $configuration->getParameterBag()->all(), '->getParameterBag() returns an empty bag if no parameter has been defined');
|
|
||||||
|
|
||||||
$configuration = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
|
||||||
$this->assertEquals(array('foo' => 'bar'), $configuration->getParameterBag()->all(), '->getParameterBag() returns the parameter bag passed at construction time');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getParameter
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::setParameter
|
|
||||||
*/
|
|
||||||
public function testSetGetParameter()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
|
||||||
$configuration->setParameter('bar', 'foo');
|
|
||||||
$this->assertEquals('foo', $configuration->getParameter('bar'), '->setParameter() sets the value of a new parameter');
|
|
||||||
|
|
||||||
$configuration->setParameter('foo', 'baz');
|
|
||||||
$this->assertEquals('baz', $configuration->getParameter('foo'), '->setParameter() overrides previously set parameter');
|
|
||||||
|
|
||||||
$configuration->setParameter('Foo', 'baz1');
|
|
||||||
$this->assertEquals('baz1', $configuration->getParameter('foo'), '->setParameter() converts the key to lowercase');
|
|
||||||
$this->assertEquals('baz1', $configuration->getParameter('FOO'), '->getParameter() converts the key to lowercase');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$configuration->getParameter('baba');
|
|
||||||
$this->fail('->getParameter() throws an \InvalidArgumentException if the key does not exist');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() throws an \InvalidArgumentException if the key does not exist');
|
|
||||||
$this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->getParameter() throws an \InvalidArgumentException if the key does not exist');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::setAlias
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getAlias
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::hasAlias
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getAliases
|
|
||||||
*/
|
|
||||||
public function testAliases()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$configuration->setAlias('bar', 'foo');
|
|
||||||
$this->assertEquals('foo', $configuration->getAlias('bar'), '->setAlias() defines a new alias');
|
|
||||||
$this->assertTrue($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined');
|
|
||||||
$this->assertFalse($configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$configuration->getAlias('baba');
|
|
||||||
$this->fail('->getAlias() throws an \InvalidArgumentException if the alias does not exist');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getAlias() throws an \InvalidArgumentException if the alias does not exist');
|
|
||||||
$this->assertEquals('The service alias "baba" does not exist.', $e->getMessage(), '->getAlias() throws an \InvalidArgumentException if the alias does not exist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$configuration->setAlias('barbar', 'foofoo');
|
|
||||||
$this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo'), $configuration->getAliases(), '->getAliases() returns an array of all defined aliases');
|
|
||||||
|
|
||||||
$configuration->addAliases(array('foo' => 'bar'));
|
|
||||||
$this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), $configuration->getAliases(), '->addAliases() adds some aliases');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::setDefinitions
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::addDefinitions
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::hasDefinition
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getDefinition
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::setDefinition
|
|
||||||
*/
|
|
||||||
public function testDefinitions()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$definitions = array(
|
|
||||||
'foo' => new Definition('FooClass'),
|
|
||||||
'bar' => new Definition('BarClass'),
|
|
||||||
);
|
|
||||||
$configuration->setDefinitions($definitions);
|
|
||||||
$this->assertEquals($definitions, $configuration->getDefinitions(), '->setDefinitions() sets the service definitions');
|
|
||||||
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
|
|
||||||
$this->assertFalse($configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
|
|
||||||
|
|
||||||
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
|
|
||||||
$this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
|
|
||||||
$this->assertTrue($configuration->setDefinition('foobar', new Definition('FooBarClass')) === $configuration, '->setDefinition() implements a fuild interface');
|
|
||||||
|
|
||||||
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
|
|
||||||
$this->assertEquals(array_merge($definitions, $defs), $configuration->getDefinitions(), '->addDefinitions() adds the service definitions');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$configuration->getDefinition('baz');
|
|
||||||
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
|
|
||||||
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::findDefinition
|
|
||||||
*/
|
|
||||||
public function testFindDefinition()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
|
|
||||||
$configuration->setAlias('bar', 'foo');
|
|
||||||
$configuration->setAlias('foobar', 'bar');
|
|
||||||
$this->assertEquals($definition, $configuration->findDefinition('foobar'), '->findDefinition() returns a Definition');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::getResources
|
|
||||||
* @covers Symfony\Components\DependencyInjection\BuilderConfiguration::addResource
|
|
||||||
*/
|
|
||||||
public function testResources()
|
|
||||||
{
|
|
||||||
$configuration = new BuilderConfiguration();
|
|
||||||
$configuration->addResource($a = new FileResource(self::$fixturesPath.'/xml/services1.xml'));
|
|
||||||
$configuration->addResource($b = new FileResource(self::$fixturesPath.'/xml/services2.xml'));
|
|
||||||
$this->assertEquals(array($a, $b), $configuration->getResources(), '->getResources() returns an array of resources read for the current configuration');
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,26 +10,26 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection;
|
namespace Symfony\Tests\Components\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
use Symfony\Components\DependencyInjection\Resource\FileResource;
|
||||||
|
|
||||||
require_once __DIR__.'/Fixtures/includes/classes.php';
|
require_once __DIR__.'/Fixtures/includes/classes.php';
|
||||||
|
|
||||||
class BuilderTest extends \PHPUnit_Framework_TestCase
|
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::setDefinitions
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::setDefinitions
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::getDefinitions
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getDefinitions
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::setDefinition
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::setDefinition
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::getDefinition
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getDefinition
|
||||||
*/
|
*/
|
||||||
public function testDefinitions()
|
public function testDefinitions()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$definitions = array(
|
$definitions = array(
|
||||||
'foo' => new Definition('FooClass'),
|
'foo' => new Definition('FooClass'),
|
||||||
'bar' => new Definition('BarClass'),
|
'bar' => new Definition('BarClass'),
|
||||||
@ -56,22 +56,22 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::register
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::register
|
||||||
*/
|
*/
|
||||||
public function testRegister()
|
public function testRegister()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo', 'FooClass');
|
$builder->register('foo', 'FooClass');
|
||||||
$this->assertTrue($builder->hasDefinition('foo'), '->register() registers a new service definition');
|
$this->assertTrue($builder->hasDefinition('foo'), '->register() registers a new service definition');
|
||||||
$this->assertInstanceOf('Symfony\Components\DependencyInjection\Definition', $builder->getDefinition('foo'), '->register() returns the newly created Definition instance');
|
$this->assertInstanceOf('Symfony\Components\DependencyInjection\Definition', $builder->getDefinition('foo'), '->register() returns the newly created Definition instance');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::has
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::has
|
||||||
*/
|
*/
|
||||||
public function testHas()
|
public function testHas()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$this->assertFalse($builder->has('foo'), '->has() returns false if the service does not exist');
|
$this->assertFalse($builder->has('foo'), '->has() returns false if the service does not exist');
|
||||||
$builder->register('foo', 'FooClass');
|
$builder->register('foo', 'FooClass');
|
||||||
$this->assertTrue($builder->has('foo'), '->has() returns true if a service definition exists');
|
$this->assertTrue($builder->has('foo'), '->has() returns true if a service definition exists');
|
||||||
@ -80,11 +80,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::get
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::get
|
||||||
*/
|
*/
|
||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
try {
|
try {
|
||||||
$builder->get('foo');
|
$builder->get('foo');
|
||||||
$this->fail('->get() throws an InvalidArgumentException if the service does not exist');
|
$this->fail('->get() throws an InvalidArgumentException if the service does not exist');
|
||||||
@ -116,11 +116,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::getServiceIds
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getServiceIds
|
||||||
*/
|
*/
|
||||||
public function testGetServiceIds()
|
public function testGetServiceIds()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo', 'stdClass');
|
$builder->register('foo', 'stdClass');
|
||||||
$builder->bar = $bar = new \stdClass();
|
$builder->bar = $bar = new \stdClass();
|
||||||
$builder->register('bar', 'stdClass');
|
$builder->register('bar', 'stdClass');
|
||||||
@ -128,13 +128,13 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::setAlias
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::setAlias
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::hasAlias
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::hasAlias
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::getAlias
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getAlias
|
||||||
*/
|
*/
|
||||||
public function testAliases()
|
public function testAliases()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo', 'stdClass');
|
$builder->register('foo', 'stdClass');
|
||||||
$builder->setAlias('bar', 'foo');
|
$builder->setAlias('bar', 'foo');
|
||||||
$this->assertTrue($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
|
$this->assertTrue($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
|
||||||
@ -153,11 +153,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::getAliases
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getAliases
|
||||||
*/
|
*/
|
||||||
public function testGetAliases()
|
public function testGetAliases()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->setAlias('bar', 'foo');
|
$builder->setAlias('bar', 'foo');
|
||||||
$builder->setAlias('foobar', 'foo');
|
$builder->setAlias('foobar', 'foo');
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
||||||
@ -168,32 +168,32 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::setAliases
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::setAliases
|
||||||
*/
|
*/
|
||||||
public function testSetAliases()
|
public function testSetAliases()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
|
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::addAliases
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::addAliases
|
||||||
*/
|
*/
|
||||||
public function testAddAliases()
|
public function testAddAliases()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->setAliases(array('bar' => 'foo'));
|
$builder->setAliases(array('bar' => 'foo'));
|
||||||
$builder->addAliases(array('foobar' => 'foo'));
|
$builder->addAliases(array('foobar' => 'foo'));
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateService()
|
public function testCreateService()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo1', 'FooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php');
|
$builder->register('foo1', 'FooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php');
|
||||||
$this->assertInstanceOf('\FooClass', $builder->get('foo1'), '->createService() requires the file defined by the service definition');
|
$this->assertInstanceOf('\FooClass', $builder->get('foo1'), '->createService() requires the file defined by the service definition');
|
||||||
$builder->register('foo2', 'FooClass')->setFile(__DIR__.'/Fixtures/includes/%file%.php');
|
$builder->register('foo2', 'FooClass')->setFile(__DIR__.'/Fixtures/includes/%file%.php');
|
||||||
@ -202,22 +202,22 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceClass()
|
public function testCreateServiceClass()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo1', '%class%');
|
$builder->register('foo1', '%class%');
|
||||||
$builder->setParameter('class', 'stdClass');
|
$builder->setParameter('class', 'stdClass');
|
||||||
$this->assertInstanceOf('\stdClass', $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
|
$this->assertInstanceOf('\stdClass', $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceArguments()
|
public function testCreateServiceArguments()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('bar', 'stdClass');
|
$builder->register('bar', 'stdClass');
|
||||||
$builder->register('foo1', 'FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
$builder->register('foo1', 'FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
||||||
$builder->setParameter('value', 'bar');
|
$builder->setParameter('value', 'bar');
|
||||||
@ -225,11 +225,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceFactoryMethod()
|
public function testCreateServiceFactoryMethod()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('bar', 'stdClass');
|
$builder->register('bar', 'stdClass');
|
||||||
$builder->register('foo1', 'FooClass')->setFactoryMethod('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
$builder->register('foo1', 'FooClass')->setFactoryMethod('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
||||||
$builder->setParameter('value', 'bar');
|
$builder->setParameter('value', 'bar');
|
||||||
@ -238,11 +238,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceFactoryService()
|
public function testCreateServiceFactoryService()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('baz_service')->setFactoryService('baz_factory')->setFactoryMethod('getInstance');
|
$builder->register('baz_service')->setFactoryService('baz_factory')->setFactoryMethod('getInstance');
|
||||||
$builder->register('baz_factory', 'BazClass');
|
$builder->register('baz_factory', 'BazClass');
|
||||||
|
|
||||||
@ -250,11 +250,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceMethodCalls()
|
public function testCreateServiceMethodCalls()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('bar', 'stdClass');
|
$builder->register('bar', 'stdClass');
|
||||||
$builder->register('foo1', 'FooClass')->addMethodCall('setBar', array(array('%value%', new Reference('bar'))));
|
$builder->register('foo1', 'FooClass')->addMethodCall('setBar', array(array('%value%', new Reference('bar'))));
|
||||||
$builder->setParameter('value', 'bar');
|
$builder->setParameter('value', 'bar');
|
||||||
@ -262,11 +262,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::createService
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::createService
|
||||||
*/
|
*/
|
||||||
public function testCreateServiceConfigurator()
|
public function testCreateServiceConfigurator()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo1', 'FooClass')->setConfigurator('sc_configure');
|
$builder->register('foo1', 'FooClass')->setConfigurator('sc_configure');
|
||||||
$this->assertTrue($builder->get('foo1')->configured, '->createService() calls the configurator');
|
$this->assertTrue($builder->get('foo1')->configured, '->createService() calls the configurator');
|
||||||
|
|
||||||
@ -289,23 +289,23 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::resolveValue
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::resolveValue
|
||||||
*/
|
*/
|
||||||
public function testResolveValue()
|
public function testResolveValue()
|
||||||
{
|
{
|
||||||
$this->assertEquals('foo', Builder::resolveValue('foo', array()), '->resolveValue() returns its argument unmodified if no placeholders are found');
|
$this->assertEquals('foo', ContainerBuilder::resolveValue('foo', array()), '->resolveValue() returns its argument unmodified if no placeholders are found');
|
||||||
$this->assertEquals('I\'m a bar', Builder::resolveValue('I\'m a %foo%', array('foo' => 'bar')), '->resolveValue() replaces placeholders by their values');
|
$this->assertEquals('I\'m a bar', ContainerBuilder::resolveValue('I\'m a %foo%', array('foo' => 'bar')), '->resolveValue() replaces placeholders by their values');
|
||||||
$this->assertTrue(Builder::resolveValue('%foo%', array('foo' => true)) === true, '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
|
$this->assertTrue(ContainerBuilder::resolveValue('%foo%', array('foo' => true)) === true, '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
|
||||||
|
|
||||||
$this->assertEquals(array('bar' => 'bar'), Builder::resolveValue(array('%foo%' => '%foo%'), array('foo' => 'bar')), '->resolveValue() replaces placeholders in keys and values of arrays');
|
$this->assertEquals(array('bar' => 'bar'), ContainerBuilder::resolveValue(array('%foo%' => '%foo%'), array('foo' => 'bar')), '->resolveValue() replaces placeholders in keys and values of arrays');
|
||||||
|
|
||||||
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), Builder::resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%'))), array('foo' => 'bar')), '->resolveValue() replaces placeholders in nested arrays');
|
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), ContainerBuilder::resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%'))), array('foo' => 'bar')), '->resolveValue() replaces placeholders in nested arrays');
|
||||||
|
|
||||||
$this->assertEquals('I\'m a %foo%', Builder::resolveValue('I\'m a %%foo%%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
$this->assertEquals('I\'m a %foo%', ContainerBuilder::resolveValue('I\'m a %%foo%%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
||||||
$this->assertEquals('I\'m a bar %foo bar', Builder::resolveValue('I\'m a %foo% %%foo %foo%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
$this->assertEquals('I\'m a bar %foo bar', ContainerBuilder::resolveValue('I\'m a %foo% %%foo %foo%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Builder::resolveValue('%foobar%', array());
|
ContainerBuilder::resolveValue('%foobar%', array());
|
||||||
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
$this->assertInstanceOf('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
||||||
@ -313,7 +313,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Builder::resolveValue('foo %foobar% bar', array());
|
ContainerBuilder::resolveValue('foo %foobar% bar', array());
|
||||||
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
$this->assertInstanceOf('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
|
||||||
@ -322,57 +322,51 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::resolveServices
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::resolveServices
|
||||||
*/
|
*/
|
||||||
public function testResolveServices()
|
public function testResolveServices()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->register('foo', 'FooClass');
|
$builder->register('foo', 'FooClass');
|
||||||
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances');
|
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances');
|
||||||
$this->assertEquals(array('foo' => array('foo', $builder->get('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays');
|
$this->assertEquals(array('foo' => array('foo', $builder->get('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::merge
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::merge
|
||||||
*/
|
*/
|
||||||
public function testMerge()
|
public function testMerge()
|
||||||
{
|
{
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
|
||||||
$container->merge(null);
|
$config = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
|
||||||
$this->assertEquals(array(), $container->getParameterBag()->all(), '->merge() accepts null as an argument');
|
|
||||||
$this->assertEquals(array(), $container->getDefinitions(), '->merge() accepts null as an argument');
|
|
||||||
|
|
||||||
$container = new Builder(new ParameterBag(array('bar' => 'foo')));
|
|
||||||
$config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
|
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
|
||||||
|
|
||||||
$container = new Builder(new ParameterBag(array('bar' => 'foo', 'foo' => 'baz')));
|
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
|
||||||
$config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
|
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%')));
|
||||||
$container->merge($config);
|
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'baz'), $container->getParameterBag()->all(), '->merge() does not change the already defined parameters');
|
|
||||||
|
|
||||||
$container = new Builder(new ParameterBag(array('bar' => 'foo')));
|
|
||||||
$config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => '%bar%')));
|
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
|
////// FIXME
|
||||||
|
$container->commit();
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
|
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||||
|
|
||||||
$container = new Builder(new ParameterBag(array('bar' => 'foo')));
|
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
|
||||||
$config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
|
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
|
////// FIXME
|
||||||
|
$container->commit();
|
||||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
|
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$container->register('foo', 'FooClass');
|
$container->register('foo', 'FooClass');
|
||||||
$container->register('bar', 'BarClass');
|
$container->register('bar', 'BarClass');
|
||||||
$config = new BuilderConfiguration();
|
$config = new ContainerBuilder();
|
||||||
$config->setDefinition('baz', new Definition('BazClass'));
|
$config->setDefinition('baz', new Definition('BazClass'));
|
||||||
$config->setAlias('alias_for_foo', 'foo');
|
$config->setAlias('alias_for_foo', 'foo');
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
|
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
|
||||||
$this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
|
$this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$container->register('foo', 'FooClass');
|
$container->register('foo', 'FooClass');
|
||||||
$config->setDefinition('foo', new Definition('BazClass'));
|
$config->setDefinition('foo', new Definition('BazClass'));
|
||||||
$container->merge($config);
|
$container->merge($config);
|
||||||
@ -380,11 +374,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Builder::findAnnotatedServiceIds
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::findAnnotatedServiceIds
|
||||||
*/
|
*/
|
||||||
public function testFindAnnotatedServiceIds()
|
public function testFindAnnotatedServiceIds()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$builder
|
$builder
|
||||||
->register('foo', 'FooClass')
|
->register('foo', 'FooClass')
|
||||||
->addAnnotation('foo', array('foo' => 'foo'))
|
->addAnnotation('foo', array('foo' => 'foo'))
|
||||||
@ -399,4 +393,28 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
|
), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
|
||||||
$this->assertEquals(array(), $builder->findAnnotatedServiceIds('foobar'), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
|
$this->assertEquals(array(), $builder->findAnnotatedServiceIds('foobar'), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::findDefinition
|
||||||
|
*/
|
||||||
|
public function testFindDefinition()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->setDefinition('foo', $definition = new Definition('FooClass'));
|
||||||
|
$container->setAlias('bar', 'foo');
|
||||||
|
$container->setAlias('foobar', 'bar');
|
||||||
|
$this->assertEquals($definition, $container->findDefinition('foobar'), '->findDefinition() returns a Definition');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::getResources
|
||||||
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::addResource
|
||||||
|
*/
|
||||||
|
public function testResources()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->addResource($a = new FileResource(__DIR__.'/Fixtures/xml/services1.xml'));
|
||||||
|
$container->addResource($b = new FileResource(__DIR__.'/Fixtures/xml/services2.xml'));
|
||||||
|
$this->assertEquals(array($a, $b), $container->getResources(), '->getResources() returns an array of resources read for the current configuration');
|
||||||
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection;
|
namespace Symfony\Tests\Components\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
|||||||
$loaderClass = 'Symfony\\Components\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
|
$loaderClass = 'Symfony\\Components\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
|
||||||
$dumperClass = 'Symfony\\Components\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
|
$dumperClass = 'Symfony\\Components\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
|
||||||
|
|
||||||
$container1 = new Builder();
|
$container1 = new ContainerBuilder();
|
||||||
$loader1 = new $loaderClass($container1);
|
$loader1 = new $loaderClass($container1);
|
||||||
$loader1->load(self::$fixturesPath.'/'.$type.'/'.$fixture);
|
$loader1->load(self::$fixturesPath.'/'.$type.'/'.$fixture);
|
||||||
$container1->setParameter('path', self::$fixturesPath.'/includes');
|
$container1->setParameter('path', self::$fixturesPath.'/includes');
|
||||||
@ -41,7 +41,7 @@ class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tmp = tempnam('sf_service_container', 'sf');
|
$tmp = tempnam('sf_service_container', 'sf');
|
||||||
file_put_contents($tmp, $dumper->dump());
|
file_put_contents($tmp, $dumper->dump());
|
||||||
|
|
||||||
$container2 = new Builder();
|
$container2 = new ContainerBuilder();
|
||||||
$loader2 = new $loaderClass($container2);
|
$loader2 = new $loaderClass($container2);
|
||||||
$loader2->load($tmp);
|
$loader2->load($tmp);
|
||||||
$container2->setParameter('path', self::$fixturesPath.'/includes');
|
$container2->setParameter('path', self::$fixturesPath.'/includes');
|
||||||
|
@ -10,14 +10,14 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Dumper\Dumper;
|
use Symfony\Components\DependencyInjection\Dumper\Dumper;
|
||||||
|
|
||||||
class DumperTest extends \PHPUnit_Framework_TestCase
|
class DumperTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$builder = new Builder();
|
$builder = new ContainerBuilder();
|
||||||
$dumper = new ProjectDumper($builder);
|
$dumper = new ProjectDumper($builder);
|
||||||
try {
|
try {
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Dumper\GraphvizDumper;
|
use Symfony\Components\DependencyInjection\Dumper\GraphvizDumper;
|
||||||
|
|
||||||
class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -24,11 +24,11 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$dumper = new GraphvizDumper($container = new Builder());
|
$dumper = new GraphvizDumper($container = new ContainerBuilder());
|
||||||
|
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$dumper = new GraphvizDumper($container);
|
$dumper = new GraphvizDumper($container);
|
||||||
|
|
||||||
$container = include self::$fixturesPath.'/containers/container9.php';
|
$container = include self::$fixturesPath.'/containers/container9.php';
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
|
use Symfony\Components\DependencyInjection\Dumper\PhpDumper;
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
@ -26,12 +26,12 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$dumper = new PhpDumper($container = new Builder());
|
$dumper = new PhpDumper($container = new ContainerBuilder());
|
||||||
|
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), '->dump() takes a class and a base_class options');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), '->dump() takes a class and a base_class options');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$dumper = new PhpDumper($container);
|
$dumper = new PhpDumper($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExportParameters()
|
public function testExportParameters()
|
||||||
{
|
{
|
||||||
$dumper = new PhpDumper($container = new Builder(new ParameterBag(array('foo' => new Reference('foo')))));
|
$dumper = new PhpDumper($container = new ContainerBuilder(new ParameterBag(array('foo' => new Reference('foo')))));
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dumper = new PhpDumper($container);
|
$dumper = new PhpDumper($container);
|
||||||
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
|
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
|
||||||
|
|
||||||
$dumper = new PhpDumper($container = new Builder());
|
$dumper = new PhpDumper($container = new ContainerBuilder());
|
||||||
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
||||||
try {
|
try {
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Dumper\XmlDumper;
|
use Symfony\Components\DependencyInjection\Dumper\XmlDumper;
|
||||||
|
|
||||||
class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -24,11 +24,11 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$dumper = new XmlDumper($container = new Builder());
|
$dumper = new XmlDumper($container = new ContainerBuilder());
|
||||||
|
|
||||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services1.xml', $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
|
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services1.xml', $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$dumper = new XmlDumper($container);
|
$dumper = new XmlDumper($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dumper = new XmlDumper($container);
|
$dumper = new XmlDumper($container);
|
||||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
|
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
|
||||||
|
|
||||||
$dumper = new XmlDumper($container = new Builder());
|
$dumper = new XmlDumper($container = new ContainerBuilder());
|
||||||
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
||||||
try {
|
try {
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
namespace Symfony\Tests\Components\DependencyInjection\Dumper;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Dumper\YamlDumper;
|
use Symfony\Components\DependencyInjection\Dumper\YamlDumper;
|
||||||
|
|
||||||
class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -24,11 +24,11 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
$dumper = new YamlDumper($container = new Builder());
|
$dumper = new YamlDumper($container = new ContainerBuilder());
|
||||||
|
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$dumper = new YamlDumper($container);
|
$dumper = new YamlDumper($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dumper = new YamlDumper($container);
|
$dumper = new YamlDumper($container);
|
||||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
|
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
|
||||||
|
|
||||||
$dumper = new YamlDumper($container = new Builder());
|
$dumper = new YamlDumper($container = new ContainerBuilder());
|
||||||
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
|
||||||
try {
|
try {
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
require_once __DIR__.'/../includes/classes.php';
|
require_once __DIR__.'/../includes/classes.php';
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$container->
|
$container->
|
||||||
register('foo', 'FooClass')->
|
register('foo', 'FooClass')->
|
||||||
addArgument(new Reference('bar'))
|
addArgument(new Reference('bar'))
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
$container = new Builder(new ParameterBag(array(
|
$container = new ContainerBuilder(new ParameterBag(array(
|
||||||
'FOO' => 'bar',
|
'FOO' => 'bar',
|
||||||
'bar' => 'foo is %foo bar',
|
'bar' => 'foo is %foo bar',
|
||||||
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
|
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
require_once __DIR__.'/../includes/classes.php';
|
require_once __DIR__.'/../includes/classes.php';
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\ContainerInterface;
|
use Symfony\Components\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Reference;
|
use Symfony\Components\DependencyInjection\Reference;
|
||||||
use Symfony\Components\DependencyInjection\Parameter;
|
use Symfony\Components\DependencyInjection\Parameter;
|
||||||
|
|
||||||
$container = new Builder();
|
$container = new ContainerBuilder();
|
||||||
$container->
|
$container->
|
||||||
register('foo', 'FooClass')->
|
register('foo', 'FooClass')->
|
||||||
addAnnotation('foo', array('foo' => 'foo'))->
|
addAnnotation('foo', array('foo' => 'foo'))->
|
||||||
|
@ -3,5 +3,5 @@ digraph sc {
|
|||||||
node [fontsize="11" fontname="Arial" shape="record"];
|
node [fontsize="11" fontname="Arial" shape="record"];
|
||||||
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
||||||
|
|
||||||
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\Builder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ digraph sc {
|
|||||||
edge [fontsize="12" fontname="Verdana" color="white" arrowhead="closed" arrowsize="1"];
|
edge [fontsize="12" fontname="Verdana" color="white" arrowhead="closed" arrowsize="1"];
|
||||||
|
|
||||||
node_foo [label="foo\nFooClass\n", shape=square, fillcolor="grey", style="filled"];
|
node_foo [label="foo\nFooClass\n", shape=square, fillcolor="grey", style="filled"];
|
||||||
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\Builder\n", shape=square, fillcolor="green", style="empty"];
|
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\ContainerBuilder\n", shape=square, fillcolor="green", style="empty"];
|
||||||
node_bar [label="bar\n\n", shape=square, fillcolor="red", style="empty"];
|
node_bar [label="bar\n\n", shape=square, fillcolor="red", style="empty"];
|
||||||
node_foo -> node_bar [label="" style="filled"];
|
node_foo -> node_bar [label="" style="filled"];
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ digraph sc {
|
|||||||
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
||||||
|
|
||||||
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\Builder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
node_bar [label="bar\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
node_bar [label="bar\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
||||||
node_foo -> node_bar [label="" style="filled"];
|
node_foo -> node_bar [label="" style="filled"];
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ digraph sc {
|
|||||||
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_factory_service [label="factory_service\n\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_factory_service [label="factory_service\n\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\Builder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
node_service_container [label="service_container\nSymfony\\Components\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
||||||
node_foo -> node_foo_baz [label="" style="filled"];
|
node_foo -> node_foo_baz [label="" style="filled"];
|
||||||
node_foo -> node_service_container [label="" style="filled"];
|
node_foo -> node_service_container [label="" style="filled"];
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
|
|
||||||
class ProjectExtension extends LoaderExtension
|
class ProjectExtension extends LoaderExtension
|
||||||
{
|
{
|
||||||
public function barLoad(array $config, BuilderConfiguration $configuration)
|
public function barLoad(array $config, ContainerBuilder $configuration)
|
||||||
{
|
{
|
||||||
$configuration->setDefinition('project.service.bar', new Definition('FooClass'));
|
$configuration->setDefinition('project.service.bar', new Definition('FooClass'));
|
||||||
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
|
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\Definition;
|
use Symfony\Components\DependencyInjection\Definition;
|
||||||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Components\DependencyInjection\Loader;
|
namespace Symfony\Tests\Components\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Builder;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\FileLoader;
|
use Symfony\Components\DependencyInjection\Loader\FileLoader;
|
||||||
|
|
||||||
class FileLoaderTest extends \PHPUnit_Framework_TestCase
|
class FileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -51,7 +50,7 @@ class ProjectLoader extends FileLoader
|
|||||||
{
|
{
|
||||||
public $paths;
|
public $paths;
|
||||||
|
|
||||||
public function load($resource, $main = true, BuilderConfiguration $configuration = null)
|
public function load($resource, ContainerBuilder $container = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace Symfony\Tests\Components\DependencyInjection\Loader;
|
|||||||
|
|
||||||
require_once __DIR__.'/../Fixtures/includes/ProjectExtension.php';
|
require_once __DIR__.'/../Fixtures/includes/ProjectExtension.php';
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
|
class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -24,14 +24,14 @@ class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$extension = new \ProjectExtension();
|
$extension = new \ProjectExtension();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$extension->load('foo', array(), new BuilderConfiguration());
|
$extension->load('foo', array(), new ContainerBuilder());
|
||||||
$this->fail('->load() throws an InvalidArgumentException if the tag does not exist');
|
$this->fail('->load() throws an InvalidArgumentException if the tag does not exist');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag does not exist');
|
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag does not exist');
|
||||||
$this->assertEquals('The tag "project:foo" is not defined in the "project" extension.', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag does not exist');
|
$this->assertEquals('The tag "project:foo" is not defined in the "project" extension.', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
$extension->load('bar', array('foo' => 'bar'), $config = new BuilderConfiguration());
|
$extension->load('bar', array('foo' => 'bar'), $config = new ContainerBuilder());
|
||||||
$this->assertEquals(array('project.parameter.bar' => 'bar', 'project.parameter.foo' => 'bar'), $config->getParameterBag()->all(), '->load() calls the method tied to the given tag');
|
$this->assertEquals(array('project.parameter.bar' => 'bar', 'project.parameter.foo' => 'bar'), $config->getParameterBag()->all(), '->load() calls the method tied to the given tag');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ namespace Symfony\Tests\Components\DependencyInjection\Loader;
|
|||||||
require_once __DIR__.'/../Fixtures/includes/ProjectExtension.php';
|
require_once __DIR__.'/../Fixtures/includes/ProjectExtension.php';
|
||||||
|
|
||||||
use Symfony\Components\DependencyInjection\Loader\Loader;
|
use Symfony\Components\DependencyInjection\Loader\Loader;
|
||||||
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
use Symfony\Components\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
class ProjectLoader1 extends Loader
|
class ProjectLoader1 extends Loader
|
||||||
{
|
{
|
||||||
public function load($resource, $main = true, BuilderConfiguration $configuration = null)
|
public function load($resource, ContainerBuilder $container = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// extension without an XSD
|
// extension without an XSD
|
||||||
$config = $loader->load('extensions/services1.xml');
|
$config = $loader->load('extensions/services1.xml');
|
||||||
|
$config->commit();
|
||||||
$services = $config->getDefinitions();
|
$services = $config->getDefinitions();
|
||||||
$parameters = $config->getParameterBag()->all();
|
$parameters = $config->getParameterBag()->all();
|
||||||
|
|
||||||
@ -184,6 +185,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// extension with an XSD
|
// extension with an XSD
|
||||||
$config = $loader->load('extensions/services2.xml');
|
$config = $loader->load('extensions/services2.xml');
|
||||||
|
$config->commit();
|
||||||
$services = $config->getDefinitions();
|
$services = $config->getDefinitions();
|
||||||
$parameters = $config->getParameterBag()->all();
|
$parameters = $config->getParameterBag()->all();
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$loader = new ProjectLoader3(self::$fixturesPath.'/yaml');
|
$loader = new ProjectLoader3(self::$fixturesPath.'/yaml');
|
||||||
|
|
||||||
$config = $loader->load('services10.yml');
|
$config = $loader->load('services10.yml');
|
||||||
|
$config->commit();
|
||||||
$services = $config->getDefinitions();
|
$services = $config->getDefinitions();
|
||||||
$parameters = $config->getParameterBag()->all();
|
$parameters = $config->getParameterBag()->all();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user