Пример #1
0
 public function barLoad(array $config, BuilderConfiguration $configuration)
 {
     $configuration->setDefinition('project.service.bar', new Definition('FooClass'));
     $configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
     $configuration->setDefinition('project.service.foo', new Definition('FooClass'));
     $configuration->setParameter('project.parameter.foo', isset($config['foo']) ? $config['foo'] : 'foobar');
     return $configuration;
 }
Пример #2
0
 /**
  * Customizes the Container instance.
  *
  * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
  *
  * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
  */
 public function buildContainer(ContainerInterface $container)
 {
     Loader::registerExtension(new KernelExtension());
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(array(__DIR__ . '/../Resources/config', __DIR__ . '/Resources/config'));
     $configuration->merge($loader->load('services.xml'));
     if ($container->getParameter('kernel.debug')) {
         $configuration->merge($loader->load('debug.xml'));
         $configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher'));
     }
     return $configuration;
 }
Пример #3
0
 /**
  * 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;
 }
$configuration->addAliases(array('foo' => 'bar'));
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), '->addAliases() adds some aliases');

// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$configuration = new BuilderConfiguration();
$definitions = array(
  'foo' => new Definition('FooClass'),
  'bar' => new Definition('BarClass'),
);
$configuration->setDefinitions($definitions);
$t->is($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');

$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');
}
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
$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');
Пример #7
0
 /**
  * @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');
 }
 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);
 }
 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');
     }
 }
 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;
 }
Пример #11
0
 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);
 }
Пример #12
0
 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', 'constructor') as $key) {
         $method = 'set' . ucfirst($key);
         if (isset($service[$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'));
     }
     $configuration->setDefinition($id, $definition);
 }
 public function testDefinitions()
 {
     $configuration = new BuilderConfiguration();
     $definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
     $configuration->setDefinitions($definitions);
     $this->assertEquals($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
     $this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
     $this->assertTrue(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
     $configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
     $this->assertEquals($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
     $this->assertTrue($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')));
     $this->assertEquals($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
     try {
         $configuration->getDefinition('baz');
         $this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
     } catch (\InvalidArgumentException $e) {
     }
 }