当前位置: 首页>>代码示例>>PHP>>正文


PHP BuilderConfiguration::setAlias方法代码示例

本文整理汇总了PHP中Symfony\Components\DependencyInjection\BuilderConfiguration::setAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP BuilderConfiguration::setAlias方法的具体用法?PHP BuilderConfiguration::setAlias怎么用?PHP BuilderConfiguration::setAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Components\DependencyInjection\BuilderConfiguration的用法示例。


在下文中一共展示了BuilderConfiguration::setAlias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mailerLoad

 /**
  * Loads the Swift Mailer configuration.
  *
  * Usage example:
  *
  *      <swift:mailer transport="gmail" delivery_strategy="spool">
  *        <swift:username>fabien</swift:username>
  *        <swift:password>xxxxx</swift:password>
  *        <swift:spool path="/path/to/spool/" />
  *      </swift:mailer>
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function mailerLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('swiftmailer.mailer')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load($this->resources['mailer']));
         $configuration->setAlias('mailer', 'swiftmailer.mailer');
     }
     $r = new \ReflectionClass('Swift_Message');
     $configuration->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename()))));
     $transport = $configuration->getParameter('swiftmailer.transport.name');
     if (array_key_exists('transport', $config)) {
         if (null === $config['transport']) {
             $transport = 'null';
         } elseif ('gmail' === $config['transport']) {
             $config['encryption'] = 'ssl';
             $config['auth_mode'] = 'login';
             $config['host'] = 'smtp.gmail.com';
             $transport = 'smtp';
         } else {
             $transport = $config['transport'];
         }
         $configuration->setParameter('swiftmailer.transport.name', $transport);
     }
     $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $transport);
     if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
         $config['port'] = 465;
     }
     foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
         if (isset($config[$key])) {
             $configuration->setParameter('swiftmailer.transport.' . $transport . '.' . $key, $config[$key]);
         }
     }
     // spool?
     if (isset($config['spool'])) {
         $type = isset($config['type']) ? $config['type'] : 'file';
         $configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $transport);
         $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
         $configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
         foreach (array('path') as $key) {
             if (isset($config['spool'][$key])) {
                 $configuration->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
             }
         }
     }
     if (isset($config['delivery_address'])) {
         $configuration->setParameter('swiftmailer.single_address', $config['delivery_address']);
         $configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
     }
     if (isset($config['disable_delivery']) && $config['disable_delivery']) {
         $configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
     }
     return $configuration;
 }
开发者ID:pgodel,项目名称:PageRoller,代码行数:68,代码来源:SwiftmailerExtension.php

示例2: mailerLoad

 /**
  * Loads the Swift Mailer configuration.
  *
  * Usage example:
  *
  *      <swift:mailer transport="gmail" delivery_strategy="spool">
  *        <swift:username>fabien</swift:username>
  *        <swift:password>xxxxx</swift:password>
  *        <swift:spool path="/path/to/spool/" />
  *      </swift:mailer>
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function mailerLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['mailer']));
     if (isset($config['transport']) && null === $config['transport']) {
         $config['transport'] = 'null';
     } elseif (!isset($config['transport'])) {
         $config['transport'] = 'smtp';
     } elseif ('gmail' === $config['transport']) {
         $config['encryption'] = 'ssl';
         $config['auth_mode'] = 'login';
         $config['host'] = 'smtp.gmail.com';
         $config['transport'] = 'smtp';
     }
     $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $config['transport']);
     if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
         $config['port'] = 465;
     }
     foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
         if (isset($config[$key])) {
             $configuration->setParameter('swiftmailer.transport.' . $config['transport'] . '.' . $key, $config[$key]);
         }
     }
     // spool?
     if (isset($config['spool'])) {
         $type = isset($config['type']) ? $config['type'] : 'file';
         $configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $config['transport']);
         $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
         $configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
         foreach (array('path') as $key) {
             if (isset($config['spool'][$key])) {
                 $configuration->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
             }
         }
     }
     $configuration->setAlias('mailer', 'swiftmailer.mailer');
     return $configuration;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:54,代码来源:SwiftmailerExtension.php

示例3: loggerLoad

 /**
  * Loads the logger configuration.
  *
  * Usage example:
  *
  *      <zend:logger priority="info" path="/path/to/some.log" />
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function loggerLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['logger']));
     if (isset($config['priority'])) {
         $configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend_Log::' . strtoupper($config['priority'])));
     }
     if (isset($config['path'])) {
         $configuration->setParameter('zend.logger.path', $config['path']);
     }
     $configuration->setAlias('logger', 'zend.logger');
     return $configuration;
 }
开发者ID:robo47,项目名称:symfony,代码行数:25,代码来源:ZendExtension.php

示例4: loggerLoad

 /**
  * Loads the logger configuration.
  *
  * Usage example:
  *
  *      <zend:logger priority="info" path="/path/to/some.log" />
  *
  * @param array                $config        A configuration array
  * @param BuilderConfiguration $configuration A BuilderConfiguration instance
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function loggerLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('zend.logger')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load($this->resources['logger']));
         $configuration->setAlias('logger', 'zend.logger');
     }
     if (isset($config['priority'])) {
         $configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::' . strtoupper($config['priority'])));
     }
     if (isset($config['path'])) {
         $configuration->setParameter('zend.logger.path', $config['path']);
     }
 }
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:26,代码来源:ZendExtension.php

示例5: dbalLoad

 /**
  * Loads the DBAL configuration.
  *
  * Usage example:
  *
  *      <doctrine:dbal dbname="sfweb" username="root" />
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function dbalLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['dbal']));
     foreach (array('dbname', 'host', 'username', 'password', 'path', 'port') as $key) {
         if (isset($config[$key])) {
             $configuration->setParameter('doctrine.dbal.' . $key, $config[$key]);
         }
     }
     if (isset($config['options'])) {
         $configuration->setParameter('doctrine.dbal.driver.options', $config['options']);
     }
     if (isset($config['driver'])) {
         $class = $config['driver'];
         if (in_array($class, array('OCI8', 'PDOMsSql', 'PDOMySql', 'PDOOracle', 'PDOPgSql', 'PDOSqlite'))) {
             $class = 'Doctrine\\DBAL\\Driver\\' . $class . '\\Driver';
         }
         $configuration->setParameter('doctrine.dbal.driver.class', $class);
     }
     $configuration->setAlias('database_connection', null !== $this->alias ? $this->alias : 'doctrine.dbal.connection');
     return $configuration;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:34,代码来源:DoctrineExtension.php

示例6: templatingLoad

 /**
  * Loads the templating configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function templatingLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['templating']));
     $configuration->setParameter('templating.output_escaper', array_key_exists('escaping', $config) ? $config['escaping'] : false);
     $configuration->setParameter('templating.assets.version', array_key_exists('assets_version', $config) ? $config['assets_version'] : null);
     // path for the filesystem loader
     if (isset($config['path'])) {
         $configuration->setParameter('templating.loader.filesystem.path', $config['path']);
     }
     // loaders
     if (isset($config['loader'])) {
         $loaders = array();
         $ids = is_array($config['loader']) ? $config['loader'] : array($config['loader']);
         foreach ($ids as $id) {
             $loaders[] = new Reference($id);
         }
     } else {
         $loaders = array(new Reference('templating.loader.filesystem'));
     }
     if (1 === count($loaders)) {
         $configuration->setAlias('templating.loader', (string) $loaders[0]);
     } else {
         $configuration->getDefinition('templating.loader.chain')->addArgument($loaders);
         $configuration->setAlias('templating.loader', 'templating.loader.chain');
     }
     // cache?
     if (isset($config['cache'])) {
         // wrap the loader with some cache
         $configuration->setDefinition('templating.loader.wrapped', $configuration->findDefinition('templating.loader'));
         $configuration->setDefinition('templating.loader', $configuration->getDefinition('templating.loader.cache'));
         $configuration->setParameter('templating.loader.cache.path', $config['cache']);
     }
     return $configuration;
 }
开发者ID:CodingFabian,项目名称:symfony,代码行数:43,代码来源:WebExtension.php

示例7: Definition

$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');

$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');

try
{
  $configuration->getDefinition('baz');
  $t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
catch (InvalidArgumentException $e)
{
  $t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}

// ->findDefinition()
$t->diag('->findDefinition()');
$configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
$configuration->setAlias('bar', 'foo');
$configuration->setAlias('foobar', 'bar');
$t->is($configuration->findDefinition('foobar'), $definition, '->findDefinition() returns a Definition');

// ->addResource() ->getResources()
$t->diag('->addResource() ->getResources()');
$configuration = new BuilderConfiguration();
$configuration->addResource($a = new FileResource('foo.xml'));
$configuration->addResource($b = new FileResource('foo.yml'));
$t->is($configuration->getResources(), array($a, $b), '->getResources() returns an array of resources read for the current configuration');
开发者ID:nicolasmartin,项目名称:symfony,代码行数:30,代码来源:BuilderConfigurationTest.php

示例8: ormLoad

 /**
  * Loads the Doctrine ORM configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function ormLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['orm']));
     $config['default_entity_manager'] = isset($config['default_entity_manager']) ? $config['default_entity_manager'] : 'default';
     foreach (array('metadata_driver', 'cache_driver') as $key) {
         if (isset($config[$key])) {
             $configuration->setParameter('doctrine.orm.' . $key, $config[$key]);
         }
     }
     $config['entity_managers'] = isset($config['entity_managers']) ? $config['entity_managers'] : array($config['default_entity_manager'] => array());
     foreach ($config['entity_managers'] as $name => $connection) {
         $ormConfigDef = new Definition('Doctrine\\ORM\\Configuration');
         $configuration->setDefinition(sprintf('doctrine.orm.%s_configuration', $name), $ormConfigDef);
         $drivers = array('metadata', 'query', 'result');
         foreach ($drivers as $driver) {
             $definition = $configuration->getDefinition(sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver')));
             $clone = clone $definition;
             $clone->addMethodCall('setNamespace', array(sprintf('doctrine_%s_', $driver)));
             $configuration->setDefinition(sprintf('doctrine.orm.%s_cache', $driver), $clone);
         }
         // configure metadata driver for each bundle based on the type of mapping files found
         $mappingDriverDef = new Definition('Doctrine\\ORM\\Mapping\\Driver\\DriverChain');
         $bundleEntityMappings = array();
         $bundleDirs = $this->bundleDirs;
         $aliasMap = array();
         foreach (array_reverse($this->bundles) as $className) {
             $tmp = dirname(str_replace('\\', '/', $className));
             $namespace = str_replace('/', '\\', dirname($tmp));
             $class = basename($tmp);
             if (!isset($bundleDirs[$namespace])) {
                 continue;
             }
             $type = false;
             if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Resources/config/doctrine/metadata')) {
                 $type = $this->detectMappingType($dir);
             }
             if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Entities')) {
                 if ($type === false) {
                     $type = 'annotation';
                 }
                 $aliasMap[$class] = $namespace . '\\' . $class . '\\Entities';
             }
             if (false !== $type) {
                 $mappingDriverDef->addMethodCall('addDriver', array(new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), $namespace . '\\' . $class . '\\Entities'));
             }
         }
         $ormConfigDef->addMethodCall('setEntityNamespaces', array($aliasMap));
         $configuration->setDefinition('doctrine.orm.metadata_driver', $mappingDriverDef);
         $methods = array('setMetadataCacheImpl' => new Reference('doctrine.orm.metadata_cache'), 'setQueryCacheImpl' => new Reference('doctrine.orm.query_cache'), 'setResultCacheImpl' => new Reference('doctrine.orm.result_cache'), 'setMetadataDriverImpl' => new Reference('doctrine.orm.metadata_driver'), 'setProxyDir' => '%kernel.cache_dir%/doctrine/Proxies', 'setProxyNamespace' => 'Proxies', 'setAutoGenerateProxyClasses' => true);
         foreach ($methods as $method => $arg) {
             $ormConfigDef->addMethodCall($method, array($arg));
         }
         $ormEmArgs = array(new Reference(sprintf('doctrine.dbal.%s_connection', isset($connection['connection']) ? $connection['connection'] : $name)), new Reference(sprintf('doctrine.orm.%s_configuration', $name)));
         $ormEmDef = new Definition('Doctrine\\ORM\\EntityManager', $ormEmArgs);
         $ormEmDef->setConstructor('create');
         $configuration->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $name), $ormEmDef);
         if ($name == $config['default_entity_manager']) {
             $configuration->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $name));
         }
     }
     $configuration->setAlias('doctrine.orm.cache', sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver')));
     return $configuration;
 }
开发者ID:poulikov,项目名称:symfony,代码行数:72,代码来源:DoctrineExtension.php

示例9: debugLoad

 public function debugLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['debug']));
     if (isset($config['exception']) && $config['exception']) {
         $configuration->merge($loader->load('debug_exception_handler.xml'));
     }
     if (isset($config['toolbar']) && $config['toolbar']) {
         $configuration->merge($loader->load('debug_data_collector.xml'));
         $configuration->merge($loader->load('debug_web_debug_toolbar.xml'));
     }
     if (isset($config['ide']) && 'textmate' === $config['ide']) {
         $configuration->setParameter('web_debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
     }
     $configuration->setAlias('event_dispatcher', 'debug.event_dispatcher');
     return $configuration;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:18,代码来源:WebExtension.php

示例10: array

$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->merge() does not change the already defined parameters');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%', 'baz' => '%foo%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder();
$container->register('foo', 'FooClass');
$container->register('bar', 'BarClass');
$config = new BuilderConfiguration();
$config->setDefinition('baz', new Definition('BazClass'));
$config->setAlias('alias_for_foo', 'foo');
$container->merge($config);
$t->is(array_keys($container->getDefinitions()), array('foo', 'bar', 'baz'), '->merge() merges definitions already defined ones');
$t->is($container->getAliases(), array('alias_for_foo' => 'foo'), '->merge() registers defined aliases');
$container = new Builder();
$container->register('foo', 'FooClass');
$config->setDefinition('foo', new Definition('BazClass'));
$container->merge($config);
$t->is($container->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');
// ->findAnnotatedServiceIds()
$t->diag('->findAnnotatedServiceIds()');
$builder = new Builder();
$builder->register('foo', 'FooClass')->addAnnotation('foo', array('foo' => 'foo'))->addAnnotation('bar', array('bar' => 'bar'))->addAnnotation('foo', array('foofoo' => 'foofoo'));
$t->is($builder->findAnnotatedServiceIds('foo'), array('foo' => array(array('foo' => 'foo'), array('foofoo' => 'foofoo'))), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
$t->is($builder->findAnnotatedServiceIds('foobar'), array(), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
开发者ID:pablosik,项目名称:symfony,代码行数:31,代码来源:BuilderTest.php

示例11: testMerge

 /**
  * @covers Symfony\Components\DependencyInjection\Builder::merge
  */
 public function testMerge()
 {
     $container = new Builder();
     $container->merge(null);
     $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);
     $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')));
     $config = new BuilderConfiguration(array(), 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);
     $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')));
     $config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
     $container->merge($config);
     $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->register('foo', 'FooClass');
     $container->register('bar', 'BarClass');
     $config = new BuilderConfiguration();
     $config->setDefinition('baz', new Definition('BazClass'));
     $config->setAlias('alias_for_foo', 'foo');
     $container->merge($config);
     $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');
     $container = new Builder();
     $container->register('foo', 'FooClass');
     $config->setDefinition('foo', new Definition('BazClass'));
     $container->merge($config);
     $this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
 }
开发者ID:bill97420,项目名称:symfony,代码行数:40,代码来源:BuilderTest.php

示例12: parseDefinition

 protected function parseDefinition(BuilderConfiguration $configuration, $id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $configuration->setAlias($id, substr($service, 1));
         return;
     }
     $definition = new Definition($service['class']);
     if (isset($service['shared'])) {
         $definition->setShared($service['shared']);
     }
     if (isset($service['constructor'])) {
         $definition->setConstructor($service['constructor']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         foreach ($service['calls'] as $call) {
             $definition->addMethodCall($call[0], $this->resolveServices($call[1]));
         }
     }
     if (isset($service['annotations'])) {
         foreach ($service['annotations'] as $annotation) {
             $name = $annotation['name'];
             unset($annotation['name']);
             $definition->addAnnotation($name, $annotation);
         }
     }
     $configuration->setDefinition($id, $definition);
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:40,代码来源:YamlFileLoader.php

示例13: testFindDefinition

 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');
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:7,代码来源:BuilderConfigurationTest.php

示例14: odmLoad

 public function odmLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->_resources['odm']));
     $configuration->setParameter('doctrine.odm.mongo.default_database', $this->appName);
     $configuration->setParameter('doctrine.odm.mongo.proxy_dir', sprintf('%s/Proxies', $this->tmpDir));
     if (isset($config['cache_driver'])) {
         $configuration->setAlias('doctrine.odm.cache', sprintf('doctrine.odm.cache.%s', $config['cache_driver']));
     }
     $config['metadata_driver'] = isset($config['metadata_driver']) ? $config['metadata_driver'] : 'auto';
     if ('auto' == $config['metadata_driver']) {
         $configuration->setAlias('doctrine.odm.mongo.metadata_driver', 'doctrine.odm.mongo.metadata_driver.chain');
         $driverChainDef = $configuration->getDefinition('doctrine.odm.mongo.metadata_driver.chain');
         foreach (array_reverse($this->bundles) as $className) {
             $tmp = dirname(str_replace('\\', '/', $className));
             $namespace = str_replace('/', '\\', dirname($tmp));
             $class = basename($tmp);
             if (!isset($this->bundleDirs[$namespace])) {
                 continue;
             }
             $type = false;
             if (is_dir($dir = $this->bundleDirs[$namespace] . '/' . $class . '/Resources/config/doctrine/metadata')) {
                 $type = $this->detectMappingType($dir);
             }
             if (is_dir($dir = $this->bundleDirs[$namespace] . '/' . $class . '/Documents')) {
                 $type = 'annotation';
             }
             if (false !== $type) {
                 $driverChainDef->addMethodCall('addDriver', array(new Reference(sprintf('doctrine.odm.mongo.metadata_driver.%s', $type)), $namespace . '\\' . $class));
             }
         }
     } else {
         $configuration->setAlias('doctrine.odm.mongo.metadata_driver', sprintf('doctrine.odm.mongo.metadata_driver.%s', $config['metadata_driver']));
     }
     $config['default_document_manager'] = isset($config['default_document_manager']) ? $config['default_document_manager'] : 'default';
     $config['document_managers'] = isset($config['document_managers']) ? $config['document_managers'] : array($config['default_document_manager'] => array());
     $defaultManagerParams = array('connection' => 'default');
     $defaultConnectionParams = array('server' => sprintf('localhost:27017/%s', $this->appName), 'options' => array('connect' => true));
     $documentManagers = array();
     $connections = array();
     foreach ($config['document_managers'] as $name => $params) {
         $managerParams = array_merge($defaultManagerParams, $params);
         $documentManagers[$name] = $managerParams;
         $connectionName = $managerParams['connection'];
         if (isset($config['connections']) && isset($config['connections'][$connectionName])) {
             $conn = array_merge($defaultConnectionParams, $config['connections'][$connectionName]);
         } else {
             $conn = $defaultConnectionParams;
         }
         $connections[$connectionName] = $conn;
     }
     $defaultConfDef = $configuration->getDefinition('doctrine.odm.mongo.configuration');
     $defaultConnection = $configuration->getDefinition('doctrine.odm.mongo.connection');
     $defaultDocManager = $configuration->getDefinition('doctrine.odm.document_manager');
     if (count($documentManagers) > 1) {
         foreach ($documentManagers as $name => $connection) {
             $server = $connections[$connection['connection']]['server'];
             $options = $connections[$connection['connection']]['options'];
             $pieces = explode('/', $server);
             $db = isset($pieces[1]) ? $pieces[1] : null;
             $odmConfiguration = clone $defaultConfDef;
             $odmConfiguration->setClass($configuration->getParameter('doctrine.odm.mongo.configuration_class'));
             if (isset($db)) {
                 $odmConfiguration->addMethodCall('setDefaultDB', array($db));
             }
             $odmConnection = clone $defaultConnection;
             $odmConnection->setClass($configuration->getParameter('doctrine.odm.mongo_class'));
             $odmConnection->setArguments(array($server, $options));
             $configuration->setDefinition(sprintf('doctrine.odm.mongo.%s_connection', $name), $odmConnection);
             $configuration->setDefinition(sprintf('doctrine.odm.mongo.%s_configuration', $name), $odmConfiguration);
             $documentManager = clone $defaultDocManager;
             $documentManager->setClass($configuration->getParameter('doctrine.odm.mongo.document_manager_class'));
             $odmManagerArgs = array(new Reference(sprintf('doctrine.odm.mongo.%s_connection', $name)), new Reference(sprintf('doctrine.odm.mongo.%s_configuration', $name)));
             $documentManager->setArguments($odmManagerArgs);
             $configuration->setDefinition(sprintf('doctrine.odm.%s_document_manager', $name), $documentManager);
             if ($name == $config['default_document_manager']) {
                 $configuration->setAlias('doctrine.odm.document_manager', sprintf('doctrine.odm.%s_document_manager', $name));
             }
         }
     } else {
         list($name, $connection) = each($documentManagers);
         $server = $connections[$connection['connection']]['server'];
         $options = $connections[$connection['connection']]['options'];
         $pieces = explode('/', $server);
         $db = isset($pieces[1]) ? $pieces[1] : null;
         $configuration->setParameter('doctrine.odm.mongo.default_database', $db);
         $configuration->setParameter('doctrine.odm.mongo.default_server', $server);
         $configuration->setParameter('doctrine.odm.mongo.default_connection_options', $options);
         $configuration->setAlias(sprintf('doctrine.odm.%s_document_manager', $name), 'doctrine.odm.document_manager');
     }
     return $configuration;
 }
开发者ID:poulikov,项目名称:DoctrineMongoDBBundle,代码行数:93,代码来源:MongoDBExtension.php

示例15: parseDefinition

 protected function parseDefinition(BuilderConfiguration $configuration, $id, $service, $file)
 {
     if ((string) $service['alias']) {
         $configuration->setAlias($id, (string) $service['alias']);
         return;
     }
     $definition = new Definition((string) $service['class']);
     foreach (array('shared', 'factory-method', 'factory-service', 'factory-class') as $key) {
         if (isset($service[$key])) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}((string) $service->getAttributeAsPhp($key));
         }
     }
     if ($service->file) {
         $definition->setFile((string) $service->file);
     }
     $definition->setArguments($service->getArgumentsAsPhp('argument'));
     if (isset($service->configurator)) {
         if (isset($service->configurator['function'])) {
             $definition->setConfigurator((string) $service->configurator['function']);
         } else {
             if (isset($service->configurator['service'])) {
                 $class = new Reference((string) $service->configurator['service']);
             } else {
                 $class = (string) $service->configurator['class'];
             }
             $definition->setConfigurator(array($class, (string) $service->configurator['method']));
         }
     }
     foreach ($service->call as $call) {
         $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
     }
     foreach ($service->annotation as $annotation) {
         $parameters = array();
         foreach ($annotation->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         $definition->addAnnotation((string) $annotation['name'], $parameters);
     }
     $configuration->setDefinition($id, $definition);
 }
开发者ID:bill97420,项目名称:symfony,代码行数:44,代码来源:XmlFileLoader.php


注:本文中的Symfony\Components\DependencyInjection\BuilderConfiguration::setAlias方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。