Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($event, &$dispatched = NULL, EventParamResolverInterface $resolver = NULL)
 {
     $object = $this->container->getBound($this->binding);
     if ($object instanceof ScopedProxyInterface) {
         if ($this->lazy && !$object->K2IsProxyBound()) {
             return;
         }
         $object = $object->K2UnwrapScopedProxy();
     }
     if (!method_exists($object, $this->methodName)) {
         throw new \BadMethodCallException(sprintf('Method "%s" is not defined in %s', $this->methodName, get_class($object)));
     }
     if (!is_callable([$object, $this->methodName])) {
         throw new \BadMethodCallException(sprintf('%s->%s() is not callable from event listener', get_class($object), $this->methodName));
     }
     $dispatched = true;
     if ($resolver === NULL) {
         return $object->{$this->methodName}($event);
     }
     $args = array_merge([$event], $this->loadArguments(new \ReflectionMethod(get_class($object), $this->methodName), $resolver));
     switch (count($args)) {
         case 1:
             return $object->{$this->methodName}($args[0]);
         case 2:
             return $object->{$this->methodName}($args[0], $args[1]);
         case 3:
             return $object->{$this->methodName}($args[0], $args[1], $args[2]);
         case 4:
             return $object->{$this->methodName}($args[0], $args[1], $args[2], $args[3]);
         case 5:
             return $object->{$this->methodName}($args[0], $args[1], $args[2], $args[3], $args[4]);
     }
     return call_user_func_array([$object, $this->methodName], $args);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getService($name)
 {
     if ($this->shared) {
         if (empty($this->bound[$name])) {
             if (empty($this->bindings[$name])) {
                 throw new ServiceNotFoundException(sprintf('Service "%s" is not registered', $name));
             }
             $this->bound[$name] = $this->container->getBound($this->bindings[$name]);
         }
         return $this->bound[$name];
     }
     if (empty($this->bindings[$name])) {
         throw new ServiceNotFoundException(sprintf('Service "%s" is not registered', $name));
     }
     return $this->container->getBound($this->bindings[$name]);
 }
Ejemplo n.º 3
0
 public function createView(Configuration $config, ContainerInterface $container)
 {
     $view = new View();
     $container->eachMarked(function (ViewRendererFactory $factory, BindingInterface $binding) use($view, $container) {
         $view->registerFactory($container->getBound($binding));
     });
     return $view;
 }
Ejemplo n.º 4
0
 public function createExpressionContextFactory(ContainerInterface $container)
 {
     $factory = new ExpressionContextFactory();
     $container->eachMarked(function (ExpressionExtension $extension, BindingInterface $binding) use($factory, $container) {
         $factory->registerExtension($container->getBound($binding));
     });
     $container->eachMarked(function (ExpressionResolver $resolver, BindingInterface $binding) use($factory, $container) {
         $factory->getResolvers()->registerResolver($container->getBound($binding));
     });
     return $factory;
 }