/**
  * @expectedException \OutOfBoundsException
  */
 public function testGetArgumentShouldCheckBounds()
 {
     $def = new DefinitionDecorator('foo');
     $def->setArguments(array(0 => 'foo'));
     $def->replaceArgument(0, 'foo');
     $def->getArgument(1);
 }
Ejemplo n.º 2
0
 public function process(ContainerBuilder $container)
 {
     if (!($container->hasDefinition('fragment.listener') && $container->hasDefinition('ezpublish.decorated_fragment_renderer'))) {
         return null;
     }
     $fragmentListenerDef = $container->findDefinition('fragment.listener');
     $fragmentListenerDef->setFactoryService('ezpublish.fragment_listener.factory')->setFactoryMethod('buildFragmentListener')->addArgument('%fragment.listener.class%');
     // Looping over all fragment renderers to decorate them
     // This is to make sure they are siteaccess aware (siteaccess is serialized in rendered path).
     foreach ($container->findTaggedServiceIds('kernel.fragment_renderer') as $id => $attributes) {
         $renamedId = "{$id}.inner";
         $definition = $container->getDefinition($id);
         $public = $definition->isPublic();
         $tags = $definition->getTags();
         $definition->setPublic(false);
         $container->setDefinition($renamedId, $definition);
         $decoratedDef = new DefinitionDecorator('ezpublish.decorated_fragment_renderer');
         $decoratedDef->setArguments(array(new Reference($renamedId)));
         $decoratedDef->setPublic($public);
         $decoratedDef->setTags($tags);
         // Special treatment for inline fragment renderer, to fit ESI renderer constructor type hinting (forced to InlineFragmentRenderer)
         if ($id === 'fragment.renderer.inline') {
             $decoratedDef->setClass($container->getParameter('ezpublish.decorated_fragment_renderer.inline.class'));
         }
         $container->setDefinition($id, $decoratedDef);
     }
 }
 /**
  * @param array            $config
  * @param ContainerBuilder $container
  */
 private function loadArrayFormType(ContainerBuilder $container, array $config)
 {
     $serviceId = 'jd_form.form_type.array';
     $types = ['hidden', 'text'];
     foreach ($types as $type) {
         $typeDef = new DefinitionDecorator($serviceId);
         $typeDef->setArguments([$type, $config['delimiter']])->addTag('form.type', ['alias' => 'array_' . $type]);
         $container->setDefinition($serviceId . '_' . $type, $typeDef);
     }
 }
 private function configureConnectionClient(ContainerBuilder $builder, $connectionName, array $connectionConfig, $profiling)
 {
     $connectionDef = new DefinitionDecorator('kassko_cassandra.connection.prototype');
     $connectionDef->addTag('kassko_cassandra.connection');
     //logger Cql creation.
     $loggerCqlServiceName = $this->computeLoggerCqlServiceName($connectionName);
     $loggerCqlServiceDef = new DefinitionDecorator('kassko_cassandra.logger_cql.prototype');
     if (isset($connectionConfig['logger_service'])) {
         $loggerCqlServiceDef->replaceArgument(0, new Reference($connectionConfig['logger_service']));
     }
     $builder->setDefinition($loggerCqlServiceName, $loggerCqlServiceDef);
     //loggerChain creation.
     $loggerChainServiceName = $this->computeLoggerChainServiceName($connectionName);
     $loggerChainDef = new DefinitionDecorator('kassko_cassandra.logger_chain.prototype');
     $builder->setDefinition($loggerChainServiceName, $loggerChainDef);
     $loggerChainDef->addMethodCall('addLogger', [new Reference($loggerCqlServiceName)]);
     if ($profiling) {
         $loggerProfilerServiceName = $this->computeLoggerProfilerServiceName($connectionName);
         $builder->setDefinition($loggerProfilerServiceName, new DefinitionDecorator('kassko_cassandra.logger_profiler.prototype'));
         $loggerChainDef->addMethodCall('addLogger', [new Reference($loggerProfilerServiceName)]);
         $queryStatsManagerDef = $builder->getDefinition('kassko_cassandra.query_stats.manager');
         $queryStatsManagerDef->addMethodCall('addLogger', [$connectionName, new Reference($loggerProfilerServiceName)]);
     }
     if (isset($connectionConfig['event_dispatcher_service'])) {
         $connectionDef->addMethodCall('setEventDispatcher', [new Reference($connectionConfig['event_dispatcher_service'])]);
     }
     $connectionDef->addMethodCall('setLogger', [new Reference($loggerChainServiceName)]);
     $connectionDef->addMethodCall('useKeyspace', [$connectionConfig['keyspace']]);
     list($dsn, $username, $password) = $this->resolveConnectionParam($connectionConfig);
     if (null === $username xor null === $password) {
         throw new \LogicException(sprintf('username and password should be provided both or neither for keyspace "%s".', $connectionConfig['keyspace']));
     }
     if (null !== $username) {
         $connectionDef->setArguments([$dsn, $username, $password]);
     } else {
         $connectionDef->setArguments([$dsn]);
     }
     $serviceName = $this->computeServiceName($connectionName);
     $builder->setDefinition($serviceName, $connectionDef);
     if (isset($connectionConfig['alias'])) {
         $builder->setAlias($connectionConfig['alias'], $serviceName);
     }
 }
 /**
  * Converts class hierarchy metadata to definition instances.
  *
  * @param ClassHierarchyMetadata $metadata
  * @return array an array of Definition instances
  */
 public function convert(ClassHierarchyMetadata $metadata)
 {
     static $count = 0;
     $definitions = array();
     $previous = null;
     foreach ($metadata->classMetadata as $classMetadata) {
         if (null === $previous && null === $classMetadata->parent) {
             $definition = new Definition();
         } else {
             $definition = new DefinitionDecorator($classMetadata->parent ?: $previous->id);
         }
         $definition->setClass($classMetadata->name);
         if (null !== $classMetadata->scope) {
             $definition->setScope($classMetadata->scope);
         }
         if (null !== $classMetadata->public) {
             $definition->setPublic($classMetadata->public);
         }
         if (null !== $classMetadata->abstract) {
             $definition->setAbstract($classMetadata->abstract);
         }
         if (null !== $classMetadata->lazy) {
             $definition->setLazy($classMetadata->lazy);
         }
         if (null !== $classMetadata->arguments) {
             $definition->setArguments($classMetadata->arguments);
         }
         $definition->setMethodCalls($classMetadata->methodCalls);
         $definition->setTags($classMetadata->tags);
         $definition->setProperties($classMetadata->properties);
         if (null !== $classMetadata->decorates) {
             if (!method_exists($definition, 'setDecoratedService')) {
                 throw new InvalidAnnotationException(sprintf("decorations require symfony >=2.8 on class %s", $classMetadata->name));
             }
             $definition->setDecoratedService($classMetadata->decorates, $classMetadata->decoration_inner_name);
         }
         if (null !== $classMetadata->deprecated && method_exists($definition, 'setDeprecated')) {
             $definition->setDeprecated(true, $classMetadata->deprecated);
         }
         if (null === $classMetadata->id) {
             $classMetadata->id = '_jms_di_extra.unnamed.service_' . $count++;
         }
         if (0 !== count($classMetadata->initMethods)) {
             foreach ($classMetadata->initMethods as $initMethod) {
                 $definition->addMethodCall($initMethod);
             }
         } elseif (null !== $classMetadata->initMethod) {
             @trigger_error('ClassMetadata::$initMethod is deprecated since version 1.7 and will be removed in 2.0. Use ClassMetadata::$initMethods instead.', E_USER_DEPRECATED);
             $definition->addMethodCall($classMetadata->initMethod);
         }
         $definitions[$classMetadata->id] = $definition;
         $previous = $classMetadata;
     }
     return $definitions;
 }
 public function definitionProvider()
 {
     $definitionWithNoArguments = new Definition();
     $definitionWithArguments = new Definition();
     $rightValue = 'the right value';
     $wrongValue = 'the wrong value';
     $arguments = array(0 => 'first argument', 1 => $rightValue);
     $definitionWithArguments->setArguments($arguments);
     $decoratedDefinitionWithArguments = new DefinitionDecorator('parent_service_id');
     $decoratedDefinitionWithArguments->setArguments(array(0 => 'first argument', 1 => $wrongValue));
     $decoratedDefinitionWithArguments->replaceArgument(1, $rightValue);
     return array(array($definitionWithNoArguments, 1, $rightValue, false), array($definitionWithNoArguments, 1, $wrongValue, false), array($definitionWithArguments, 1, $rightValue, true), array($decoratedDefinitionWithArguments, 1, $rightValue, true));
 }
 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');
     if (empty($config['default_connection'])) {
         $keys = array_keys($config['connections']);
         $config['default_connection'] = reset($keys);
     }
     $connections = [];
     foreach ($config['connections'] as $name => $connectionOptions) {
         $connections[$name] = sprintf('sirian.sphinx.%s_connection', $name);
         $connectionDefinition = new DefinitionDecorator('sirian.sphinx.connection');
         $connectionDefinition->setArguments([$connectionOptions]);
         $container->setDefinition($connections[$name], $connectionDefinition);
     }
     $container->setParameter('sirian.sphinx.default_connection', $config['default_connection']);
     $container->setParameter('sirian.sphinx.connections', $connections);
 }
Ejemplo n.º 8
0
 /**
  * Converts class hierarchy metadata to definition instances.
  *
  * @param ClassHierarchyMetadata $metadata
  * @return array an array of Definition instances
  */
 public function convert(ClassHierarchyMetadata $metadata)
 {
     static $count = 0;
     $definitions = array();
     $previous = null;
     foreach ($metadata->classMetadata as $classMetadata) {
         if (null === $previous && null === $classMetadata->parent) {
             $definition = new Definition();
         } else {
             $definition = new DefinitionDecorator($classMetadata->parent ?: $previous->id);
         }
         $definition->setClass($classMetadata->name);
         if (null !== $classMetadata->scope) {
             $definition->setScope($classMetadata->scope);
         }
         if (null !== $classMetadata->public) {
             $definition->setPublic($classMetadata->public);
         }
         if (null !== $classMetadata->abstract) {
             $definition->setAbstract($classMetadata->abstract);
         }
         if (null !== $classMetadata->arguments) {
             $definition->setArguments($classMetadata->arguments);
         }
         $definition->setMethodCalls($classMetadata->methodCalls);
         $definition->setTags($classMetadata->tags);
         $definition->setProperties($classMetadata->properties);
         if (null === $classMetadata->id) {
             $classMetadata->id = '_jms_di_extra.unnamed.service_' . $count++;
         }
         if ($classMetadata->initMethod) {
             if (!method_exists($definition, 'setInitMethod')) {
                 throw new \RuntimeException(sprintf('@AfterSetup is not available on your Symfony version.'));
             }
             $definition->setInitMethod($classMetadata->initMethod);
         }
         $definitions[$classMetadata->id] = $definition;
         $previous = $classMetadata;
     }
     return $definitions;
 }
 /**
  * @throws \LogicException
  */
 public function generate()
 {
     $definition = new DefinitionDecorator('phpmentors_pageflower.reflection_conversational_controller');
     $definition->setArguments(array($this->controllerClass->getName()));
     foreach ($this->controllerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         /* @var $method \ReflectionMethod */
         if ($method->getDeclaringClass()->getName() == $this->controllerClass->getName()) {
             foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
                 if ($annotation instanceof Init) {
                     $definition->addMethodCall('addInitMethod', array($method->getName()));
                 } elseif ($annotation instanceof Accept) {
                     if ($annotation->value === null || is_string($annotation->value) && strlen($annotation->value) == 0) {
                         throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                     }
                     foreach ((array) $annotation->value as $accept) {
                         if ($accept === null || strlen($accept) == 0) {
                             throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                         }
                         if (!in_array($accept, $this->states)) {
                             throw new \LogicException(sprintf('The value for annotation "%s" must be a one of [ %s ], "%s" is specified.', 'PHPMentors\\PageflowerBundle\\Annotation\\Accept', implode(', ', $this->states), $accept));
                         }
                         $definition->addMethodCall('addAcceptableState', array($method->getName(), $accept));
                     }
                 }
             }
         }
     }
     foreach ($this->controllerClass->getProperties() as $property) {
         /* @var $property \ReflectionProperty */
         if ($property->getDeclaringClass()->getName() == $this->controllerClass->getName() && !$property->isStatic()) {
             foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
                 $definition->addMethodCall('addStatefulProperty', array($property->getName()));
             }
         }
     }
     $reflectionConversationalControllerServiceId = 'phpmentors_pageflower.reflection_conversational_controller.' . $this->controllerServiceId;
     $this->container->setDefinition($reflectionConversationalControllerServiceId, $definition);
     $this->container->getDefinition('phpmentors_pageflower.reflection_conversational_controller_repository')->addMethodCall('add', array(new Reference($reflectionConversationalControllerServiceId)));
 }
 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  * @param string $providerKey
  * @param array config
  * @param string $facebookAdapterId
  * @return string
  */
 public function createListener(ContainerBuilder $container, $providerKey, array $config, $facebookAdapterId)
 {
     $listenerId = FacebookAuthenticationExtension::CONTAINER_SERVICE_ID_SECURITY_FIREWALL_LISTENER;
     $listener = new DefinitionDecorator($listenerId);
     $listener->setArguments([new Reference('security.context'), new Reference('security.authentication.manager'), new Reference('security.authentication.session_strategy'), new Reference('security.http_utils'), $providerKey, new Reference($config[self::CONFIG_NODE_NAME_AUTHENTICATION_SUCCESS_HANDLER]), new Reference($config[self::CONFIG_NODE_NAME_AUTHENTICATION_FAILURE_HANDLER]), $config, $container->has('logger') ? new Reference('logger') : null, new Reference('event_dispatcher')]);
     $listener->addMethodCall('setFacebookAdapter', [new Reference($facebookAdapterId)]);
     $listenerId = $this->namespaceServiceId($listenerId, $providerKey);
     $container->setDefinition($listenerId, $listener);
     return $listenerId;
 }
 /**
  * Configures the basic auth subscriber definition.
  *
  * @param \Symfony\Component\DependencyInjection\Definition       $subscriber  The subscriber.
  * @param array                                                   $basicAuth   The basic auth.
  * @param string                                                  $adapterName The adapter name.
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container   The container.
  */
 private function configureBasicAuthSubscriberDefinition(Definition $subscriber, array $basicAuth, $adapterName, ContainerBuilder $container)
 {
     $model = new DefinitionDecorator(self::createServiceName('subscriber.basic_auth.model'));
     $model->setArguments(array($basicAuth['username'], $basicAuth['password']));
     if (isset($basicAuth['matcher'])) {
         $model->addArgument($basicAuth['matcher']);
     }
     $container->setDefinition($service = self::createServiceName($adapterName . '.basic_auth.model'), $model);
     $subscriber->setArguments(array(new Reference($service)));
 }
 /**
  * @throws \LogicException
  */
 public function generate()
 {
     $pageflowAnnotation = $this->reader->getClassAnnotation($this->controllerClass, 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow');
     if ($pageflowAnnotation === null) {
         throw new \LogicException(sprintf('Annotation "%s" is not found in class "%s".', 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow', $this->controllerClass->getName()));
     }
     $pageflowBuilderDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow_builder');
     $pageflowBuilderDefinition->setArguments(array($this->controllerServiceId));
     $statesFound = false;
     $transitionsFound = false;
     foreach ($pageflowAnnotation->value as $annotation) {
         if ($annotation instanceof States) {
             if ($statesFound) {
                 throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
             }
             $statesFound = true;
             foreach ($annotation->value as $state) {
                 if ($state instanceof AnnotationInterface) {
                     if ($state->value === null || strlen($state->value) == 0) {
                         throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($state)));
                     }
                     if ($state instanceof Start) {
                         $pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
                         $pageflowBuilderDefinition->addMethodCall('setStartState', array($state->value));
                         $this->states[] = $state->value;
                     } elseif ($state instanceof End) {
                         $pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
                         $pageflowBuilderDefinition->addMethodCall('setEndState', array($state->value, StateInterface::STATE_FINAL));
                         $this->states[] = $state->value;
                     } else {
                         throw new \LogicException(sprintf('State "%s" must be encapsulated with one of [ %s ], "%s" is specified.', $state->value, implode(', ', array('PHPMentors\\PageflowerBundle\\Annotation\\Start', 'PHPMentors\\PageflowerBundle\\Annotation\\End')), get_class($state)));
                     }
                 } else {
                     if ($state === null || strlen($state) == 0) {
                         throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                     }
                     $pageflowBuilderDefinition->addMethodCall('addState', array($state));
                     $this->states[] = $state;
                 }
             }
         } elseif ($annotation instanceof Transitions) {
             if ($transitionsFound) {
                 throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
             }
             $transitionsFound = true;
             foreach ($annotation->value as $transition) {
                 if (is_array($transition) && count($transition) == 2 && is_string($transition[0]) && is_string($transition[1])) {
                     foreach (array($transition[0], $transition[1]) as $state) {
                         if ($state === null || strlen($state) == 0) {
                             throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
                         }
                         if (!in_array($state, $this->states)) {
                             throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($annotation), implode(', ', $this->states), $state));
                         }
                     }
                     $pageflowBuilderDefinition->addMethodCall('addTransition', array($transition[0], $transition[1], $transition[1]));
                 } else {
                     throw new \LogicException(sprintf('The value for annotation "%s" must be string array, "%s" is specified.', get_class($annotation), var_export($transition, true)));
                 }
             }
         } else {
             throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($pageflowAnnotation), implode(', ', array('"PHPMentors\\PageflowerBundle\\Annotation\\States"', '"PHPMentors\\PageflowerBundle\\Annotation\\Transitions"')), is_object($annotation) ? get_class($annotation) : $annotation));
         }
     }
     $pageflowBuilderServiceId = 'phpmentors_pageflower.pageflow_builder.' . $this->controllerServiceId;
     $this->container->setDefinition($pageflowBuilderServiceId, $pageflowBuilderDefinition);
     $pageflowDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow');
     $pageflowDefinition->setFactoryService($pageflowBuilderServiceId);
     $pageflowServiceId = 'phpmentors_pageflower.pageflow.' . $this->controllerServiceId;
     $this->container->setDefinition($pageflowServiceId, $pageflowDefinition);
     $this->container->getDefinition('phpmentors_pageflower.pageflow_repository')->addMethodCall('add', array(new Reference($pageflowServiceId)));
     $this->container->addClassResource($this->controllerClass);
 }
 private function createCollectionDefinition($model, $type, $options, ContainerBuilder $container)
 {
     $collection = new DefinitionDecorator('lyra_admin.action_collection');
     $collection->setArguments(array($options))->setPublic(false);
     $container->setDefinition(sprintf('lyra_admin.%s.%s.collection', $model, $type), $collection);
 }
 /**
  * Configure a mapping from a filesystem path to a RequireJS namespace.
  * @param string $location
  * @param string $path
  * @param ContainerBuilder $container
  * @param boolean $generateAssets
  */
 protected function addNamespaceMapping($location, $path, ContainerBuilder $container, $generateAssets = true)
 {
     $location = $this->getRealPath($location, $container);
     // Register the namespace with the configuration
     $mapping = $container->getDefinition('hearsay_require_js.namespace_mapping');
     $mapping->addMethodCall('registerNamespace', array($path, $location));
     $config = $container->getDefinition('hearsay_require_js.configuration_builder');
     $config->addMethodCall('setPath', array($path, $location));
     if ($path && $container->hasDefinition('hearsay_require_js.optimizer_filter')) {
         $filter = $container->getDefinition('hearsay_require_js.optimizer_filter');
         $filter->addMethodCall('addPath', array($path, preg_replace('~\\.js$~', '', $location)));
     }
     if ($generateAssets) {
         $resource = new DefinitionDecorator('hearsay_require_js.filenames_resource');
         $resource->setArguments(array($location));
         $resource->addTag('assetic.formula_resource', array('loader' => 'require_js'));
         $container->addDefinitions(array('hearsay_require_js.filenames_resource.' . md5($location) => $resource));
     }
 }