setConfigurator() public method

Sets a configurator to call after the service is fully initialized.
public setConfigurator ( string | array $configurator ) : Definition
$configurator string | array A PHP callable
return Definition The current instance
 public function create(string $repositoryServiceId, string $class) : Definition
 {
     $definition = new Definition();
     $definition->setClass($class);
     $definition->addArgument(new Reference($repositoryServiceId));
     $definition->addArgument(new Reference('dataset.manager'));
     $definition->addArgument(new Reference('event_dispatcher'));
     $definition->setConfigurator([new Reference('dataset.configurator'), 'configure']);
     $definition->addMethodCall('setContainer', [new Reference('service_container')]);
     return $definition;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
     $metroCommands = ['FailedCommand', 'InspectCommand', 'LogsCommand', 'PendingCommand', 'PutCommand', 'RetryCommand', 'RmCommand', 'SuccessfulCommand', 'WorkCommand'];
     foreach ($metroCommands as $commandBaseName) {
         $definition = new Definition('Metro\\Console\\' . $commandBaseName);
         $definition->addTag('console.command');
         $definition->setConfigurator([new Reference('metro.command_integrator'), 'integrate']);
         $definition->setArguments([new Reference('metro')]);
         $container->setDefinition(strtolower("metro.{$commandBaseName}"), $definition);
     }
     $workCommandDefinition = $container->getDefinition('metro.workcommand');
     $workCommandDefinition->addMethodCall('setLogger', [new Reference('logger')]);
     $workCommandDefinition->addMethodCall('setJobExecutor', [new Reference('metro.job_executor')]);
 }
 protected function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     $definition = new Definition();
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['shared'])) {
         $definition->setShared($service['shared']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     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['tags'])) {
         foreach ($service['tags'] as $tag) {
             $name = $tag['name'];
             unset($tag['name']);
             $definition->addTag($name, $tag);
         }
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * Parses an individual Definition.
  *
  * @param string           $id
  * @param SimpleXMLElement $service
  * @param string           $file
  */
 private function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $public = true;
         if (isset($service['public'])) {
             $public = $service->getAttributeAsPhp('public');
         }
         $this->container->setAlias($id, new Alias((string) $service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator((string) $service['parent']);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'synchronized', 'lazy', 'abstract') 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'));
     $definition->setProperties($service->getArgumentsAsPhp('property'));
     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'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } 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->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = SimpleXMLElement::phpize($value);
             }
             // keep not normalized key for BC too
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         if ('' === (string) $tag['name']) {
             throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * Resolves the definition.
  *
  * @param ContainerBuilder    $container  The ContainerBuilder
  * @param DefinitionDecorator $definition
  *
  * @return Definition
  *
  * @throws \RuntimeException When the definition is invalid
  */
 private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
 {
     if (!$container->hasDefinition($parent = $definition->getParent())) {
         throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $this->currentId));
     }
     $parentDef = $container->getDefinition($parent);
     if ($parentDef instanceof DefinitionDecorator) {
         $id = $this->currentId;
         $this->currentId = $parent;
         $parentDef = $this->resolveDefinition($container, $parentDef);
         $container->setDefinition($parent, $parentDef);
         $this->currentId = $id;
     }
     $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $this->currentId, $parent));
     $def = new Definition();
     // merge in parent definition
     // purposely ignored attributes: scope, abstract, tags
     $def->setClass($parentDef->getClass());
     $def->setArguments($parentDef->getArguments());
     $def->setMethodCalls($parentDef->getMethodCalls());
     $def->setProperties($parentDef->getProperties());
     $def->setAutowiringTypes($parentDef->getAutowiringTypes());
     if ($parentDef->getFactoryClass(false)) {
         $def->setFactoryClass($parentDef->getFactoryClass(false));
     }
     if ($parentDef->getFactoryMethod(false)) {
         $def->setFactoryMethod($parentDef->getFactoryMethod(false));
     }
     if ($parentDef->getFactoryService(false)) {
         $def->setFactoryService($parentDef->getFactoryService(false));
     }
     if ($parentDef->isDeprecated()) {
         $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
     }
     $def->setFactory($parentDef->getFactory());
     $def->setConfigurator($parentDef->getConfigurator());
     $def->setFile($parentDef->getFile());
     $def->setPublic($parentDef->isPublic());
     $def->setLazy($parentDef->isLazy());
     // overwrite with values specified in the decorator
     $changes = $definition->getChanges();
     if (isset($changes['class'])) {
         $def->setClass($definition->getClass());
     }
     if (isset($changes['factory_class'])) {
         $def->setFactoryClass($definition->getFactoryClass(false));
     }
     if (isset($changes['factory_method'])) {
         $def->setFactoryMethod($definition->getFactoryMethod(false));
     }
     if (isset($changes['factory_service'])) {
         $def->setFactoryService($definition->getFactoryService(false));
     }
     if (isset($changes['factory'])) {
         $def->setFactory($definition->getFactory());
     }
     if (isset($changes['configurator'])) {
         $def->setConfigurator($definition->getConfigurator());
     }
     if (isset($changes['file'])) {
         $def->setFile($definition->getFile());
     }
     if (isset($changes['public'])) {
         $def->setPublic($definition->isPublic());
     }
     if (isset($changes['lazy'])) {
         $def->setLazy($definition->isLazy());
     }
     if (isset($changes['deprecated'])) {
         $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
     }
     if (isset($changes['decorated_service'])) {
         $decoratedService = $definition->getDecoratedService();
         if (null === $decoratedService) {
             $def->setDecoratedService($decoratedService);
         } else {
             $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
         }
     }
     // merge arguments
     foreach ($definition->getArguments() as $k => $v) {
         if (is_numeric($k)) {
             $def->addArgument($v);
             continue;
         }
         if (0 !== strpos($k, 'index_')) {
             throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
         }
         $index = (int) substr($k, strlen('index_'));
         $def->replaceArgument($index, $v);
     }
     // merge properties
     foreach ($definition->getProperties() as $k => $v) {
         $def->setProperty($k, $v);
     }
     // append method calls
     if (count($calls = $definition->getMethodCalls()) > 0) {
         $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
     }
     // merge autowiring types
     foreach ($definition->getAutowiringTypes() as $autowiringType) {
         $def->addAutowiringType($autowiringType);
     }
     // these attributes are always taken from the child
     $def->setAbstract($definition->isAbstract());
     $def->setScope($definition->getScope(false), false);
     $def->setShared($definition->isShared());
     $def->setTags($definition->getTags());
     return $def;
 }
Example #6
0
 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
     }
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         $definition->setSynchronized($service['synchronized']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     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'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             $definition->addMethodCall($call[0], $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $definition->setDecoratedService($service['decorates'], $renameId);
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * Parses an individual Definition
  *
  * @param string           $id
  * @param SimpleXMLElement $service
  * @param string           $file
  *
  * @return void
  */
 private function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $public = true;
         if (isset($service['public'])) {
             $public = $service->getAttributeAsPhp('public');
         }
         $this->container->setAlias($id, new Alias((string) $service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator((string) $service['parent']);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'abstract') 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'));
     $definition->setProperties($service->getArgumentsAsPhp('property'));
     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'], ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } 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->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
Example #8
0
 /**
  * Parses an individual Definition.
  *
  * @param \DOMElement $service
  * @param string      $file
  *
  * @return Definition|null
  */
 private function parseDefinition(\DOMElement $service, $file)
 {
     if ($alias = $service->getAttribute('alias')) {
         $public = true;
         if ($publicAttr = $service->getAttribute('public')) {
             $public = XmlUtils::phpize($publicAttr);
         }
         $this->container->setAlias((string) $service->getAttribute('id'), new Alias($alias, $public));
         return;
     }
     if ($parent = $service->getAttribute('parent')) {
         $definition = new DefinitionDecorator($parent);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
         if ($value = $service->getAttribute($key)) {
             if (in_array($key, array('factory-class', 'factory-method', 'factory-service'))) {
                 @trigger_error(sprintf('The "%s" attribute of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
             }
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}(XmlUtils::phpize($value));
         }
     }
     if ($value = $service->getAttribute('synchronized')) {
         $triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
         if ($triggerDeprecation) {
             @trigger_error(sprintf('The "synchronized" attribute of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
         }
         $definition->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);
     }
     if ($files = $this->getChildren($service, 'file')) {
         $definition->setFile($files[0]->nodeValue);
     }
     $definition->setArguments($this->getArgumentsAsPhp($service, 'argument'));
     $definition->setProperties($this->getArgumentsAsPhp($service, 'property'));
     if ($factories = $this->getChildren($service, 'factory')) {
         $factory = $factories[0];
         if ($function = $factory->getAttribute('function')) {
             $definition->setFactory($function);
         } else {
             $factoryService = $this->getChildren($factory, 'service');
             if (isset($factoryService[0])) {
                 $class = $this->parseDefinition($factoryService[0], $file);
             } elseif ($childService = $factory->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $factory->getAttribute('class');
             }
             $definition->setFactory(array($class, $factory->getAttribute('method')));
         }
     }
     if ($configurators = $this->getChildren($service, 'configurator')) {
         $configurator = $configurators[0];
         if ($function = $configurator->getAttribute('function')) {
             $definition->setConfigurator($function);
         } else {
             $configuratorService = $this->getChildren($configurator, 'service');
             if (isset($configuratorService[0])) {
                 $class = $this->parseDefinition($configuratorService[0], $file);
             } elseif ($childService = $configurator->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $configurator->getAttribute('class');
             }
             $definition->setConfigurator(array($class, $configurator->getAttribute('method')));
         }
     }
     foreach ($this->getChildren($service, 'call') as $call) {
         $definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument'));
     }
     foreach ($this->getChildren($service, 'tag') as $tag) {
         $parameters = array();
         foreach ($tag->attributes as $name => $node) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue);
             }
             // keep not normalized key for BC too
             $parameters[$name] = XmlUtils::phpize($node->nodeValue);
         }
         if ('' === $tag->getAttribute('name')) {
             throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
         }
         $definition->addTag($tag->getAttribute('name'), $parameters);
     }
     if ($value = $service->getAttribute('decorates')) {
         $renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
         $definition->setDecoratedService($value, $renameId);
     }
     return $definition;
 }
 /**
  * Register the locator
  *
  * @param ContainerBuilder $container     Container
  * @param EntityMapping    $entityMapping Entity mapping
  *
  * @return AbstractMappingCompilerPass self Object
  */
 protected function registerLocator(ContainerBuilder $container, EntityMapping $entityMapping)
 {
     /**
      * Locator
      */
     $locatorId = 'simple_doctrine_mapping.locator.' . $entityMapping->getUniqueIdentifier();
     $locator = new Definition('Mmoreram\\SimpleDoctrineMapping\\Locator\\SimpleDoctrineMappingLocator');
     $locator->setPublic(false);
     $locator->setArguments([$entityMapping->getEntityNamespace(), [$entityMapping->getEntityMappingFilePath()]]);
     $locator->setConfigurator([new Reference('simple_doctrine_mapping.locator_configurator'), 'configure']);
     $container->setDefinition($locatorId, $locator);
     return $this;
 }
Example #10
0
 protected function parseDefinition($id, $service, $file)
 {
     if ((string) $service['alias']) {
         $this->container->setAlias($id, (string) $service['alias']);
         return;
     }
     $definition = new Definition();
     foreach (array('class', 'shared', 'factory-method', 'factory-service') 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->tag as $tag) {
         $parameters = array();
         foreach ($tag->attributes() as $name => $value) {
             if ('name' === $name) {
                 continue;
             }
             $parameters[$name] = SimpleXMLElement::phpize($value);
         }
         $definition->addTag((string) $tag['name'], $parameters);
     }
     $this->container->setDefinition($id, $definition);
 }
Example #11
0
 /**
  * Set a configurator to call after the service is fully initialized.
  *
  * @param callable $callable A PHP callable
  *
  * @return tubepress_api_ioc_DefinitionInterface The current instance
  *
  * @api
  * @since 4.0.0
  */
 public function setConfigurator($callable)
 {
     $this->_underlyingSymfonyDefinition->setConfigurator($callable);
     return $this;
 }
 /**
  * @param Service $annotation
  * @param Definition $definition
  */
 private function processConfigurator(Service $annotation, Definition $definition)
 {
     if (!isset($annotation->configurator)) {
         return;
     }
     if (is_string($annotation->configurator)) {
         $definition->setConfigurator($annotation->configurator);
     } else {
         $definition->setConfigurator([$this->resolveServices($annotation->configurator[0]), $annotation->configurator[1]]);
     }
 }
 /**
  * Set the definition configurator into definition object if it exists.
  *
  * @param Definition $definition definition object to hydrate
  * @param array      $array      raw definition datas
  */
 private function setDefinitionConfigurator(Definition $definition, array $array)
 {
     if (isset($array['configurator'])) {
         $configurator = $array['configurator'];
         if (is_array($configurator)) {
             $configurator[0] = $this->convertArgument($configurator[0]);
         }
         $definition->setConfigurator($configurator);
     }
 }
 protected function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     } else {
         if (isset($service['alias'])) {
             $public = !array_key_exists('public', $service) || (bool) $service['public'];
             $this->container->setAlias($id, new Alias($service['alias'], $public));
             return;
         }
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     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['tags'])) {
         foreach ($service['tags'] as $tag) {
             $name = $tag['name'];
             unset($tag['name']);
             $definition->addTag($name, $tag);
         }
     }
     $this->container->setDefinition($id, $definition);
 }
Example #15
0
 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
     }
     static::checkDefinition($id, $service, $file);
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         foreach ($service as $key => $value) {
             if (!in_array($key, array('alias', 'public'))) {
                 @trigger_error(sprintf('The configuration key "%s" is unsupported for alias definition "%s" in "%s". Allowed configuration keys are "alias" and "public". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), E_USER_DEPRECATED);
             }
         }
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['shared'])) {
         $definition->setShared($service['shared']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (array_key_exists('deprecated', $service)) {
         $definition->setDeprecated(true, $service['deprecated']);
     }
     if (isset($service['factory'])) {
         $definition->setFactory($this->parseCallable($service['factory'], 'factory', $id, $file));
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         $definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
         $definition->setDecoratedService($service['decorates'], $renameId, $priority);
     }
     if (isset($service['autowire'])) {
         $definition->setAutowired($service['autowire']);
     }
     if (isset($service['autowiring_types'])) {
         if (is_string($service['autowiring_types'])) {
             $definition->addAutowiringType($service['autowiring_types']);
         } else {
             if (!is_array($service['autowiring_types'])) {
                 throw new InvalidArgumentException(sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             foreach ($service['autowiring_types'] as $autowiringType) {
                 if (!is_string($autowiringType)) {
                     throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
                 }
                 $definition->addAutowiringType($autowiringType);
             }
         }
     }
     $this->container->setDefinition($id, $definition);
 }
 /**
  * @param Bean $bean
  * @return mixed
  */
 public function create(Bean $bean)
 {
     $useConfigurator = true;
     $originalClass = $class = ltrim($bean->class, '\\');
     if ($bean->factoryMethod) {
         // We don't have a clue what what the real class is, fake it and hope nothing breaks;
         $class = "stdClass";
     } else {
         if (class_exists($class)) {
             $rClass = new \ReflectionClass($class);
             if (!$rClass->implementsInterface('MooDev\\Bounce\\Config\\Configurable')) {
                 // The class definitely doesn't need the configurator, so we can disable it.
                 $useConfigurator = false;
             }
         }
     }
     $usesLookupMethods = false;
     if ($bean->lookupMethods) {
         if (!$this->proxyGeneratorFactory) {
             throw new BounceException("Proxy generator not configured, cannot use lookup-method");
         }
         // If we have lookup methods then the class is actually a generated proxy.
         $class = ltrim($this->proxyGeneratorFactory->loadProxy($bean), '\\');
         $usesLookupMethods = true;
     }
     $def = new Definition($class);
     if ($usesLookupMethods) {
         // The proxy will take an additional, first, constructor arg which is expected to be a bean factory.
         $def->addArgument($this->getBeanFactory());
     }
     if ($useConfigurator) {
         // We use the configurator if we know the class of the bean and it implements Configurable
         // or if we have no idea what the class of the bean is (there's a factory method.)
         $def->setConfigurator($this->getConfigurator());
     }
     if ($bean->scope) {
         // This is getting killed off in Symfony 3. Sigh.
         // TODO: deal with Symfony 3.
         switch ($bean->scope) {
             case "singleton":
                 $def->setScope(ContainerBuilder::SCOPE_CONTAINER);
                 break;
             case "prototype":
                 $def->setScope(ContainerBuilder::SCOPE_PROTOTYPE);
                 break;
             default:
                 $def->setScope($bean->scope);
         }
     }
     foreach ($bean->constructorArguments as $constructorArgument) {
         $def->addArgument($this->convertValueProviderToValue($constructorArgument));
     }
     foreach ($bean->properties as $name => $property) {
         // TODO: Could support setter injection using Reflection here?
         $def->setProperty($name, $this->convertValueProviderToValue($property));
     }
     if ($bean->factoryBean) {
         $def->setFactoryService($bean->factoryBean);
         $def->setFactoryMethod($bean->factoryMethod);
     } elseif ($bean->factoryMethod) {
         $def->setFactoryClass($originalClass);
         $def->setFactoryMethod($bean->factoryMethod);
     }
     return $def;
 }
<?php

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
$container = new ContainerBuilder();
$bar = new Definition('Bar');
$bar->setConfigurator(array(new Definition('Baz'), 'configureBar'));
$fooFactory = new Definition('FooFactory');
$fooFactory->setFactory(array(new Definition('Foobar'), 'createFooFactory'));
$container->register('foo', 'Foo')->setFactory(array($fooFactory, 'createFoo'))->setConfigurator(array($bar, 'configureFoo'));
return $container;
Example #18
0
 private function buildHandler(ContainerBuilder $container, $name, array $handler)
 {
     $handlerId = $this->getHandlerId($name);
     $definition = new Definition(sprintf('%%monolog.handler.%s.class%%', $handler['type']));
     $handler['level'] = $this->levelToMonologConst($handler['level']);
     if ($handler['include_stacktraces']) {
         $definition->setConfigurator(array('Symfony\\Bundle\\MonologBundle\\MonologBundle', 'includeStacktraces'));
     }
     switch ($handler['type']) {
         case 'service':
             $container->setAlias($handlerId, $handler['id']);
             return $handlerId;
         case 'stream':
             $definition->setArguments(array($handler['path'], $handler['level'], $handler['bubble'], $handler['file_permission']));
             break;
         case 'console':
             if (!class_exists('Symfony\\Bridge\\Monolog\\Handler\\ConsoleHandler')) {
                 throw new \RuntimeException('The console handler requires symfony/monolog-bridge 2.4+');
             }
             $definition->setArguments(array(null, $handler['bubble'], isset($handler['verbosity_levels']) ? $handler['verbosity_levels'] : array()));
             $definition->addTag('kernel.event_subscriber');
             break;
         case 'firephp':
             $definition->setArguments(array($handler['level'], $handler['bubble']));
             $definition->addTag('kernel.event_listener', array('event' => 'kernel.response', 'method' => 'onKernelResponse'));
             break;
         case 'gelf':
             if (isset($handler['publisher']['id'])) {
                 $publisherId = $handler['publisher']['id'];
             } elseif (class_exists('Gelf\\Transport\\UdpTransport')) {
                 $transport = new Definition("Gelf\\Transport\\UdpTransport", array($handler['publisher']['hostname'], $handler['publisher']['port'], $handler['publisher']['chunk_size']));
                 $transportId = uniqid('monolog.gelf.transport.');
                 $transport->setPublic(false);
                 $container->setDefinition($transportId, $transport);
                 $publisher = new Definition('%monolog.gelfphp.publisher.class%', array());
                 $publisher->addMethodCall('addTransport', array(new Reference($transportId)));
                 $publisherId = uniqid('monolog.gelf.publisher.');
                 $publisher->setPublic(false);
                 $container->setDefinition($publisherId, $publisher);
             } elseif (class_exists('Gelf\\MessagePublisher')) {
                 $publisher = new Definition('%monolog.gelf.publisher.class%', array($handler['publisher']['hostname'], $handler['publisher']['port'], $handler['publisher']['chunk_size']));
                 $publisherId = uniqid('monolog.gelf.publisher.');
                 $publisher->setPublic(false);
                 $container->setDefinition($publisherId, $publisher);
             } else {
                 throw new \RuntimeException('The gelf handler requires the graylog2/gelf-php package to be installed');
             }
             $definition->setArguments(array(new Reference($publisherId), $handler['level'], $handler['bubble']));
             break;
         case 'mongo':
             if (isset($handler['mongo']['id'])) {
                 $clientId = $handler['mongo']['id'];
             } else {
                 $server = 'mongodb://';
                 if (isset($handler['mongo']['user'])) {
                     $server .= $handler['mongo']['user'] . ':' . $handler['mongo']['pass'] . '@';
                 }
                 $server .= $handler['mongo']['host'] . ':' . $handler['mongo']['port'];
                 $client = new Definition('%monolog.mongo.client.class%', array($server));
                 $clientId = uniqid('monolog.mongo.client.');
                 $client->setPublic(false);
                 $container->setDefinition($clientId, $client);
             }
             $definition->setArguments(array(new Reference($clientId), $handler['mongo']['database'], $handler['mongo']['collection'], $handler['level'], $handler['bubble']));
             break;
         case 'elasticsearch':
             if (isset($handler['elasticsearch']['id'])) {
                 $clientId = $handler['elasticsearch']['id'];
             } else {
                 // elastica client new definition
                 $elasticaClient = new Definition('%monolog.elastica.client.class%');
                 $elasticaClientArguments = array('host' => $handler['elasticsearch']['host'], 'port' => $handler['elasticsearch']['port'], 'transport' => $handler['elasticsearch']['transport']);
                 if (isset($handler['elasticsearch']['user']) && isset($handler['elasticsearch']['password'])) {
                     $elasticaClientArguments = array_merge($elasticaClientArguments, array('headers' => array('Authorization ' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password']))));
                 }
                 $elasticaClient->setArguments(array($elasticaClientArguments));
                 $clientId = uniqid('monolog.elastica.client.');
                 $elasticaClient->setPublic(false);
                 $container->setDefinition($clientId, $elasticaClient);
             }
             // elastica handler definition
             $definition->setArguments(array(new Reference($clientId), array('index' => $handler['index'], 'type' => $handler['document_type'], 'ignore_error' => $handler['ignore_error']), $handler['level'], $handler['bubble']));
             break;
         case 'chromephp':
             $definition->setArguments(array($handler['level'], $handler['bubble']));
             $definition->addTag('kernel.event_listener', array('event' => 'kernel.response', 'method' => 'onKernelResponse'));
             break;
         case 'rotating_file':
             $definition->setArguments(array($handler['path'], $handler['max_files'], $handler['level'], $handler['bubble'], $handler['file_permission']));
             $definition->addMethodCall('setFilenameFormat', array($handler['filename_format'], $handler['date_format']));
             break;
         case 'fingers_crossed':
             $handler['action_level'] = $this->levelToMonologConst($handler['action_level']);
             if (null !== $handler['passthru_level']) {
                 $handler['passthru_level'] = $this->levelToMonologConst($handler['passthru_level']);
             }
             $nestedHandlerId = $this->getHandlerId($handler['handler']);
             $this->nestedHandlers[] = $nestedHandlerId;
             if (isset($handler['activation_strategy'])) {
                 $activation = new Reference($handler['activation_strategy']);
             } elseif (!empty($handler['excluded_404s'])) {
                 $activationDef = new Definition('%monolog.activation_strategy.not_found.class%', array($handler['excluded_404s'], $handler['action_level']));
                 $activationDef->addMethodCall('setRequest', array(new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)));
                 $container->setDefinition($handlerId . '.not_found_strategy', $activationDef);
                 $activation = new Reference($handlerId . '.not_found_strategy');
             } else {
                 $activation = $handler['action_level'];
             }
             $definition->setArguments(array(new Reference($nestedHandlerId), $activation, $handler['buffer_size'], $handler['bubble'], $handler['stop_buffering'], $handler['passthru_level']));
             break;
         case 'filter':
             $handler['min_level'] = $this->levelToMonologConst($handler['min_level']);
             $handler['max_level'] = $this->levelToMonologConst($handler['max_level']);
             foreach (array_keys($handler['accepted_levels']) as $k) {
                 $handler['accepted_levels'][$k] = $this->levelToMonologConst($handler['accepted_levels'][$k]);
             }
             $nestedHandlerId = $this->getHandlerId($handler['handler']);
             $this->nestedHandlers[] = $nestedHandlerId;
             $minLevelOrList = !empty($handler['accepted_levels']) ? $handler['accepted_levels'] : $handler['min_level'];
             $definition->setArguments(array(new Reference($nestedHandlerId), $minLevelOrList, $handler['max_level'], $handler['bubble']));
             break;
         case 'buffer':
             $nestedHandlerId = $this->getHandlerId($handler['handler']);
             $this->nestedHandlers[] = $nestedHandlerId;
             $definition->setArguments(array(new Reference($nestedHandlerId), $handler['buffer_size'], $handler['level'], $handler['bubble'], $handler['flush_on_overflow']));
             break;
         case 'group':
         case 'whatfailuregroup':
             $references = array();
             foreach ($handler['members'] as $nestedHandler) {
                 $nestedHandlerId = $this->getHandlerId($nestedHandler);
                 $this->nestedHandlers[] = $nestedHandlerId;
                 $references[] = new Reference($nestedHandlerId);
             }
             $definition->setArguments(array($references, $handler['bubble']));
             break;
         case 'syslog':
             $definition->setArguments(array($handler['ident'], $handler['facility'], $handler['level'], $handler['bubble'], $handler['logopts']));
             break;
         case 'syslogudp':
             $definition->setArguments(array($handler['host'], $handler['port'], $handler['facility'], $handler['level'], $handler['bubble']));
             break;
         case 'swift_mailer':
             $oldHandler = false;
             // fallback for older symfony versions that don't have the new SwiftMailerHandler in the bridge
             $newHandlerClass = $container->getParameterBag()->resolveValue($definition->getClass());
             if (!class_exists($newHandlerClass)) {
                 $definition = new Definition('Monolog\\Handler\\SwiftMailerHandler');
                 $oldHandler = true;
             }
             if (isset($handler['email_prototype'])) {
                 if (!empty($handler['email_prototype']['method'])) {
                     $prototype = array(new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']);
                 } else {
                     $prototype = new Reference($handler['email_prototype']['id']);
                 }
             } else {
                 $messageFactory = new Definition('Symfony\\Bundle\\MonologBundle\\SwiftMailer\\MessageFactory');
                 $messageFactory->setLazy(true);
                 $messageFactory->setPublic(false);
                 $messageFactory->setArguments(array(new Reference($handler['mailer']), $handler['from_email'], $handler['to_email'], $handler['subject'], $handler['content_type']));
                 $messageFactoryId = sprintf('%s.mail_message_factory', $handlerId);
                 $container->setDefinition($messageFactoryId, $messageFactory);
                 // set the prototype as a callable
                 $prototype = array(new Reference($messageFactoryId), 'createMessage');
             }
             $definition->setArguments(array(new Reference($handler['mailer']), $prototype, $handler['level'], $handler['bubble']));
             if (!$oldHandler) {
                 $this->swiftMailerHandlers[] = $handlerId;
                 $definition->addTag('kernel.event_listener', array('event' => 'kernel.terminate', 'method' => 'onKernelTerminate'));
                 if (method_exists($newHandlerClass, 'onCliTerminate')) {
                     $definition->addTag('kernel.event_listener', array('event' => 'console.terminate', 'method' => 'onCliTerminate'));
                 }
             }
             break;
         case 'native_mailer':
             $definition->setArguments(array($handler['to_email'], $handler['subject'], $handler['from_email'], $handler['level'], $handler['bubble']));
             break;
         case 'socket':
             $definition->setArguments(array($handler['connection_string'], $handler['level'], $handler['bubble']));
             if (isset($handler['timeout'])) {
                 $definition->addMethodCall('setTimeout', array($handler['timeout']));
             }
             if (isset($handler['connection_timeout'])) {
                 $definition->addMethodCall('setConnectionTimeout', array($handler['connection_timeout']));
             }
             if (isset($handler['persistent'])) {
                 $definition->addMethodCall('setPersistent', array($handler['persistent']));
             }
             break;
         case 'pushover':
             $definition->setArguments(array($handler['token'], $handler['user'], $handler['title'], $handler['level'], $handler['bubble']));
             break;
         case 'hipchat':
             $definition->setArguments(array($handler['token'], $handler['room'], $handler['nickname'], $handler['notify'], $handler['level'], $handler['bubble'], $handler['use_ssl'], $handler['message_format'], !empty($handler['host']) ? $handler['host'] : 'api.hipchat.com', !empty($handler['api_version']) ? $handler['api_version'] : 'v1'));
             break;
         case 'slack':
             $definition->setArguments(array($handler['token'], $handler['channel'], $handler['bot_name'], $handler['use_attachment'], $handler['icon_emoji'], $handler['level'], $handler['bubble'], $handler['use_short_attachment'], $handler['include_extra']));
             break;
         case 'cube':
             $definition->setArguments(array($handler['url'], $handler['level'], $handler['bubble']));
             break;
         case 'amqp':
             $definition->setArguments(array(new Reference($handler['exchange']), $handler['exchange_name'], $handler['level'], $handler['bubble']));
             break;
         case 'error_log':
             $definition->setArguments(array($handler['message_type'], $handler['level'], $handler['bubble']));
             break;
         case 'raven':
             if (null !== $handler['client_id']) {
                 $clientId = $handler['client_id'];
             } else {
                 $client = new Definition('Raven_Client', array($handler['dsn']));
                 $client->setPublic(false);
                 $clientId = 'monolog.raven.client.' . sha1($handler['dsn']);
                 $container->setDefinition($clientId, $client);
             }
             $definition->setArguments(array(new Reference($clientId), $handler['level'], $handler['bubble']));
             break;
         case 'loggly':
             $definition->setArguments(array($handler['token'], $handler['level'], $handler['bubble']));
             if (!empty($handler['tags'])) {
                 $definition->addMethodCall('setTag', array(implode(',', $handler['tags'])));
             }
             break;
         case 'logentries':
             $definition->setArguments(array($handler['token'], $handler['use_ssl'], $handler['level'], $handler['bubble']));
             if (isset($handler['timeout'])) {
                 $definition->addMethodCall('setTimeout', array($handler['timeout']));
             }
             if (isset($handler['connection_timeout'])) {
                 $definition->addMethodCall('setConnectionTimeout', array($handler['connection_timeout']));
             }
             break;
         case 'flowdock':
             $definition->setArguments(array($handler['token'], $handler['level'], $handler['bubble']));
             if (empty($handler['formatter'])) {
                 $formatter = new Definition("Monolog\\Formatter\\FlowdockFormatter", array($handler['source'], $handler['from_email']));
                 $formatterId = 'monolog.flowdock.formatter.' . sha1($handler['source'] . '|' . $handler['from_email']);
                 $formatter->setPublic(false);
                 $container->setDefinition($formatterId, $formatter);
                 $definition->addMethodCall('setFormatter', array(new Reference($formatterId)));
             }
             break;
         case 'rollbar':
             if (!empty($handler['id'])) {
                 $rollbarId = $handler['id'];
             } else {
                 $config = $handler['config'] ?: array();
                 $config['access_token'] = $handler['token'];
                 $rollbar = new Definition('RollbarNotifier', array($config));
                 $rollbarId = 'monolog.rollbar.notifier.' . sha1(json_encode($config));
                 $rollbar->setPublic(false);
                 $container->setDefinition($rollbarId, $rollbar);
             }
             $definition->setArguments(array(new Reference($rollbarId), $handler['level'], $handler['bubble']));
             break;
             // Handlers using the constructor of AbstractHandler without adding their own arguments
         // Handlers using the constructor of AbstractHandler without adding their own arguments
         case 'browser_console':
         case 'newrelic':
         case 'test':
         case 'null':
         case 'debug':
             $definition->setArguments(array($handler['level'], $handler['bubble']));
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid handler type "%s" given for handler "%s"', $handler['type'], $name));
     }
     if (!empty($handler['formatter'])) {
         $definition->addMethodCall('setFormatter', array(new Reference($handler['formatter'])));
     }
     $container->setDefinition($handlerId, $definition);
     return $handlerId;
 }
 /**
  * Resolves the definition
  *
  * @param string              $id         The definition identifier
  * @param DefinitionDecorator $definition
  *
  * @return Definition
  */
 private function resolveDefinition($id, DefinitionDecorator $definition)
 {
     if (!$this->container->hasDefinition($parent = $definition->getParent())) {
         throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $id));
     }
     $parentDef = $this->container->getDefinition($parent);
     if ($parentDef instanceof DefinitionDecorator) {
         $parentDef = $this->resolveDefinition($parent, $parentDef);
     }
     $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent));
     $def = new Definition();
     // merge in parent definition
     // purposely ignored attributes: scope, abstract, tags
     $def->setClass($parentDef->getClass());
     $def->setArguments($parentDef->getArguments());
     $def->setMethodCalls($parentDef->getMethodCalls());
     $def->setProperties($parentDef->getProperties());
     $def->setFactoryClass($parentDef->getFactoryClass());
     $def->setFactoryMethod($parentDef->getFactoryMethod());
     $def->setFactoryService($parentDef->getFactoryService());
     $def->setConfigurator($parentDef->getConfigurator());
     $def->setFile($parentDef->getFile());
     $def->setPublic($parentDef->isPublic());
     // overwrite with values specified in the decorator
     $changes = $definition->getChanges();
     if (isset($changes['class'])) {
         $def->setClass($definition->getClass());
     }
     if (isset($changes['factory_class'])) {
         $def->setFactoryClass($definition->getFactoryClass());
     }
     if (isset($changes['factory_method'])) {
         $def->setFactoryMethod($definition->getFactoryMethod());
     }
     if (isset($changes['factory_service'])) {
         $def->setFactoryService($definition->getFactoryService());
     }
     if (isset($changes['configurator'])) {
         $def->setConfigurator($definition->getConfigurator());
     }
     if (isset($changes['file'])) {
         $def->setFile($definition->getFile());
     }
     if (isset($changes['public'])) {
         $def->setPublic($definition->isPublic());
     }
     // merge arguments
     foreach ($definition->getArguments() as $k => $v) {
         if (is_numeric($k)) {
             $def->addArgument($v);
             continue;
         }
         if (0 !== strpos($k, 'index_')) {
             throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
         }
         $index = (int) substr($k, strlen('index_'));
         $def->replaceArgument($index, $v);
     }
     // merge properties
     foreach ($definition->getProperties() as $k => $v) {
         $def->setProperty($k, $v);
     }
     // append method calls
     if (count($calls = $definition->getMethodCalls()) > 0) {
         $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
     }
     // these attributes are always taken from the child
     $def->setAbstract($definition->isAbstract());
     $def->setScope($definition->getScope());
     $def->setTags($definition->getTags());
     // set new definition on container
     $this->container->setDefinition($id, $def);
     return $def;
 }
Example #20
0
 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
     }
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         @trigger_error(sprintf('The "synchronized" key of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED);
         $definition->setSynchronized($service['synchronized'], 'request' !== $id);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         @trigger_error(sprintf('The "factory_class" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         @trigger_error(sprintf('The "factory_method" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         @trigger_error(sprintf('The "factory_service" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     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'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $definition->setDecoratedService($service['decorates'], $renameId);
     }
     $this->container->setDefinition($id, $definition);
 }
Example #21
0
    /**
     * Parses a definition.
     *
     * @param string $id
     * @param array  $service
     * @param string $file
     *
     * @throws InvalidArgumentException When tags are invalid
     */
    private function parseDefinition($id, $service, $file)
    {
        if (is_string($service) && 0 === strpos($service, '@')) {
            $this->container->setAlias($id, substr($service, 1));

            return;
        } elseif (isset($service['alias'])) {
            $public = !array_key_exists('public', $service) || (Boolean) $service['public'];
            $this->container->setAlias($id, new Alias($service['alias'], $public));

            return;
        }

        if (isset($service['parent'])) {
            $definition = new DefinitionDecorator($service['parent']);
        } else {
            $definition = new Definition();
        }

        if (isset($service['class'])) {
            $definition->setClass($service['class']);
        }

        if (isset($service['scope'])) {
            $definition->setScope($service['scope']);
        }

        if (isset($service['synthetic'])) {
            $definition->setSynthetic($service['synthetic']);
        }

        if (isset($service['public'])) {
            $definition->setPublic($service['public']);
        }

        if (isset($service['abstract'])) {
            $definition->setAbstract($service['abstract']);
        }

        if (isset($service['factory_class'])) {
            $definition->setFactoryClass($service['factory_class']);
        }

        if (isset($service['factory_method'])) {
            $definition->setFactoryMethod($service['factory_method']);
        }

        if (isset($service['factory_service'])) {
            $definition->setFactoryService($service['factory_service']);
        }

        if (isset($service['file'])) {
            $definition->setFile($service['file']);
        }

        if (isset($service['arguments'])) {
            $definition->setArguments($this->resolveServices($service['arguments']));
        }

        if (isset($service['properties'])) {
            $definition->setProperties($this->resolveServices($service['properties']));
        }

        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) {
                $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
                $definition->addMethodCall($call[0], $args);
            }
        }

        if (isset($service['tags'])) {
            if (!is_array($service['tags'])) {
                throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file));
            }

            foreach ($service['tags'] as $tag) {
                if (!isset($tag['name'])) {
                    throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
                }

                $name = $tag['name'];
                unset($tag['name']);

                foreach ($tag as $attribute => $value) {
                    if (!is_scalar($value)) {
                        throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s" in %s.', $id, $name, $file));
                    }
                }

                $definition->addTag($name, $tag);
            }
        }

        $this->container->setDefinition($id, $definition);
    }
Example #22
0
 private static function updateConfigurator(BaseDefinition $definition)
 {
     $definition->setConfigurator(str_replace('%code%', static::getCodeInitalization($definition), self::$codeInitializationDecorator));
 }
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function setConfigurator($callable)
 {
     $this->changes['configurator'] = true;
     return parent::setConfigurator($callable);
 }
Example #24
0
 /**
  * Builds bundle Config definition.
  *
  * @param string $baseDir The bundle base directory
  *
  * @return \Symfony\Component\DependencyInjection\Definition
  */
 private function buildConfigDefinition($baseDir)
 {
     $definition = new Definition('BackBee\\Config\\Config', array($this->getConfigDirByBundleBaseDir($baseDir), new Reference('cache.bootstrap'), null, '%debug%', '%config.yml_files_to_ignore%'));
     if (true === $this->application->getContainer()->getParameter('container.autogenerate')) {
         $definition->addTag('dumpable', array('dispatch_event' => false));
     }
     $definition->addMethodCall('setContainer', array(new Reference('service_container')));
     $definition->addMethodCall('setEnvironment', array('%bbapp.environment%'));
     $definition->setConfigurator(array(new Reference('config.configurator'), 'configureBundleConfig'));
     $definition->addTag('bundle.config', array('dispatch_event' => false));
     return $definition;
 }
 /**
  * Parses an individual Definition.
  *
  * @param \DOMElement $service
  * @param string      $file
  *
  * @return Definition|null
  */
 private function parseDefinition(\DOMElement $service, $file)
 {
     if ($alias = $service->getAttribute('alias')) {
         $public = true;
         if ($publicAttr = $service->getAttribute('public')) {
             $public = XmlUtils::phpize($publicAttr);
         }
         $this->container->setAlias((string) $service->getAttribute('id'), new Alias($alias, $public));
         return;
     }
     if ($parent = $service->getAttribute('parent')) {
         $definition = new DefinitionDecorator($parent);
     } else {
         $definition = new Definition();
     }
     foreach (array('class', 'shared', 'public', 'synthetic', 'lazy', 'abstract') as $key) {
         if ($value = $service->getAttribute($key)) {
             $method = 'set' . str_replace('-', '', $key);
             $definition->{$method}(XmlUtils::phpize($value));
         }
     }
     if ($value = $service->getAttribute('autowire')) {
         $definition->setAutowired(XmlUtils::phpize($value));
     }
     if ($files = $this->getChildren($service, 'file')) {
         $definition->setFile($files[0]->nodeValue);
     }
     if ($deprecated = $this->getChildren($service, 'deprecated')) {
         $definition->setDeprecated(true, $deprecated[0]->nodeValue);
     }
     $definition->setArguments($this->getArgumentsAsPhp($service, 'argument'));
     $definition->setProperties($this->getArgumentsAsPhp($service, 'property'));
     if ($factories = $this->getChildren($service, 'factory')) {
         $factory = $factories[0];
         if ($function = $factory->getAttribute('function')) {
             $definition->setFactory($function);
         } else {
             $factoryService = $this->getChildren($factory, 'service');
             if (isset($factoryService[0])) {
                 $class = $this->parseDefinition($factoryService[0], $file);
             } elseif ($childService = $factory->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $factory->getAttribute('class');
             }
             $definition->setFactory(array($class, $factory->getAttribute('method')));
         }
     }
     if ($configurators = $this->getChildren($service, 'configurator')) {
         $configurator = $configurators[0];
         if ($function = $configurator->getAttribute('function')) {
             $definition->setConfigurator($function);
         } else {
             $configuratorService = $this->getChildren($configurator, 'service');
             if (isset($configuratorService[0])) {
                 $class = $this->parseDefinition($configuratorService[0], $file);
             } elseif ($childService = $configurator->getAttribute('service')) {
                 $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
             } else {
                 $class = $configurator->getAttribute('class');
             }
             $definition->setConfigurator(array($class, $configurator->getAttribute('method')));
         }
     }
     foreach ($this->getChildren($service, 'call') as $call) {
         $definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument'));
     }
     foreach ($this->getChildren($service, 'tag') as $tag) {
         $parameters = array();
         foreach ($tag->attributes as $name => $node) {
             if ('name' === $name) {
                 continue;
             }
             if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
                 $parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue);
             }
             // keep not normalized key
             $parameters[$name] = XmlUtils::phpize($node->nodeValue);
         }
         $definition->addTag($tag->getAttribute('name'), $parameters);
     }
     foreach ($this->getChildren($service, 'autowiring-type') as $type) {
         $definition->addAutowiringType($type->textContent);
     }
     if ($value = $service->getAttribute('decorates')) {
         $renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
         $priority = $service->hasAttribute('decoration-priority') ? $service->getAttribute('decoration-priority') : 0;
         $definition->setDecoratedService($value, $renameId, $priority);
     }
     return $definition;
 }
Example #26
0
 /**
  * Parses a definition
  *
  * @param string $id      The service ID
  * @param array  $service The service definition
  * @param string $file    The file path
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 protected function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         $message = sprintf('A service definition must be an array or a string starting with "@" but %s found for ' . 'service "%s" in %s. Check your JSON syntax', gettype($service), $id, $file);
         throw new InvalidArgumentException($message);
     }
     static::checkDefinition($id, $service, $file);
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['shared'])) {
         $definition->setShared($service['shared']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (array_key_exists('deprecated', $service)) {
         $definition->setDeprecated(true, $service['deprecated']);
     }
     if (isset($service['factory'])) {
         $definition->setFactory($this->parseCallable($service['factory'], 'factory', $id, $file));
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         $definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             $message = sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
             throw new InvalidArgumentException($message);
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             $message = sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
             throw new InvalidArgumentException($message);
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 $message = sprintf('A "tags" entry must be an array for service "%s" in %s. Check your JSON syntax', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             if (!isset($tag['name'])) {
                 $message = sprintf('A "tags" entry is missing a "name" key for service "%s" in %s', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             if (!is_string($tag['name']) || '' === $tag['name']) {
                 $message = sprintf('The tag name for service "%s" in %s must be a non-empty string', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     $message = sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", ' . 'attribute "%s" in %s. Check your JSON syntax', $id, $name, $attribute, $file);
                     throw new InvalidArgumentException($message);
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) {
             $message = sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without ' . 'the "@" prefix (replace "%s" with "%s")', $id, $service['decorates'], substr($service['decorates'], 1));
             throw new InvalidArgumentException($message);
         }
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $priority = isset($service['decoration_priority']) ? $service['decoration_priority'] : 0;
         $definition->setDecoratedService($service['decorates'], $renameId, $priority);
     }
     if (isset($service['autowire'])) {
         $definition->setAutowired($service['autowire']);
     }
     if (isset($service['autowiring_types'])) {
         if (is_string($service['autowiring_types'])) {
             $definition->addAutowiringType($service['autowiring_types']);
         } else {
             if (!is_array($service['autowiring_types'])) {
                 $message = sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. ' . 'Check your JSON syntax', $id, $file);
                 throw new InvalidArgumentException($message);
             }
             foreach ($service['autowiring_types'] as $autowiringType) {
                 if (!is_string($autowiringType)) {
                     $message = sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. ' . 'Check your JSON syntax', $id, $file);
                     throw new InvalidArgumentException($message);
                 }
                 $definition->addAutowiringType($autowiringType);
             }
         }
     }
     $this->container->setDefinition($id, $definition);
 }