Example #1
0
 /**
  * Prepare handler.
  *
  * @param ContainerBuilder $container
  * @param Closure          $closure
  *
  * @return Closure
  */
 private static function prepare(ContainerBuilder $container, Closure $closure)
 {
     return function (MessageInterface $message, $handler) use($container, $closure) {
         $handler = $container->getDi()->createInstance($handler);
         $handler = $handler->getOriginalInstance();
         self::assertHandleMethodExist($handler, $message);
         return call_user_func($closure, $message, $handler);
     };
 }
 /**
  * Build response from controller.
  *
  * @param string $bundleName
  * @param string $controller
  * @param array  $parameters
  *
  * @return mixed
  */
 private function getBundleController($bundleName, $controller, array $parameters)
 {
     $bundleManager = $this->kernel->getBundleManager();
     if (null !== ($bundle = $bundleManager->get($bundleName))) {
         $class = $bundle->getNamespace() . '\\' . $this->prefix . '\\' . $controller . 'Controller';
         if (!class_exists($class)) {
             throw new RuntimeException(sprintf('Controller "%s" is undefined.', $class));
         }
         return $this->container->getDi()->createInstance($class, $parameters);
     }
     throw new RuntimeException(sprintf('Bundle "%s" is undefined.', $bundleName));
 }
 /**
  * Add consoles.
  *
  * @param array $consoles
  */
 private function add(array $consoles, ContainerBuilder $container)
 {
     foreach ($consoles as $console) {
         if (is_string($console)) {
             $instance = $container->getDi()->createInstance($console);
             /** @var AbstractConsole $console */
             $console = $instance->getOriginalInstance();
         }
         $this->addConsole($console);
     }
 }
 public function testDefineServiceFromArrayAndCallMethod()
 {
     $services = array('hit_counter' => array('class' => 'Borobudur\\DependencyInjection\\Test\\HitCounter', 'share' => true), 'decorator' => array('class' => 'Borobudur\\DependencyInjection\\Test\\CounterDecorator', 'calls' => array('count' => array('@hit_counter'))));
     $container = new ContainerBuilder();
     $container->load($services);
     $instance = $container->getDi()->create($container->get('decorator'));
     $this->assertSame(2, $instance->callMethod('count'));
 }