Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function invoke($callable, array $params = [], $constructorArgs = [])
 {
     if (is_string($callable) && strpos($callable, '::') !== false) {
         $callable = explode('::', $callable, 2);
     }
     if (is_array($callable) && is_string($callable[0]) && $constructorArgs) {
         $callable[0] = $this->container->resolve($callable[0], $constructorArgs);
     }
     return $this->container->invoke($callable, $params);
 }
Beispiel #2
0
 protected function resolveClassArg(ContainerInterface $container, ClassArgument $arg, array $params)
 {
     $name = $arg->getName();
     $class = $arg->getClass();
     // loop to prevent code repetition. executes once trying to find the
     // parameter name in the $params array, then once more trying to find
     // the class name (typehint) of the parameter.
     while ($name !== null) {
         if ($params && array_key_exists($name, $params)) {
             $class = $params[$name];
         }
         if (is_object($class)) {
             return $class;
         }
         $name = $name != $class ? $class : null;
     }
     try {
         return $container->resolve($class);
     } catch (\ReflectionException $exception) {
         if (!$arg->isRequired()) {
             return null;
         }
         throw $exception;
     }
 }
Beispiel #3
0
 /**
  * Resolve the HTTP kernel.
  *
  * @return HttpKernelInterface
  */
 protected function resolveKernel()
 {
     if ($this->kernel !== null) {
         return $this->kernel;
     }
     $class = 'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface';
     $eventDispatcher = $this->container->isBound($class) ? $this->container->resolve($class) : null;
     $kernel = new Kernel($this->getRouter(), $this->requests, $this->errorHandler, $eventDispatcher);
     return $this->kernel = $this->resolveStack()->resolve($kernel);
 }
 /**
  * Make the twig environment.
  *
  * @return \Autarky\TwigTemplating\TwigEnvironment
  */
 public function makeTwigEnvironment(ContainerInterface $dic)
 {
     $config = $this->app->getConfig();
     $options = ['debug' => $config->get('app.debug')];
     if ($config->has('path.templates_cache')) {
         $options['cache'] = $config->get('path.templates_cache');
     } else {
         if ($config->has('path.storage')) {
             $options['cache'] = $config->get('path.storage') . '/twig';
         }
     }
     $env = new TwigEnvironment($dic->resolve('Twig_LoaderInterface'), $options);
     // merge core framework extensions with user extensions
     $extensions = array_merge(['Autarky\\TwigTemplating\\Extensions\\PartialExtension', 'Autarky\\TwigTemplating\\Extensions\\UrlGenerationExtension' => ['Autarky\\Routing\\UrlGenerator'], 'Autarky\\TwigTemplating\\Extensions\\SessionExtension' => ['Symfony\\Component\\HttpFoundation\\Session\\Session']], $this->app->getConfig()->get('twig.extensions', []));
     // iterate through the array of extensions. if the array key is an
     // integer, there are no dependencies defined for that extension and we
     // can simply add it. if the array key is a string, the key is the class
     // name of the extension and the value is an array of class dependencies
     // that must be bound to the service container in order for the
     // extension to be loaded.
     foreach ($extensions as $extension => $dependencies) {
         if (is_int($extension)) {
             $env->addExtension($dic->resolve($dependencies));
         } else {
             foreach ((array) $dependencies as $dependency) {
                 if (!$dic->isBound($dependency)) {
                     // break out of this inner foreach loop and continue to
                     // the next iteration of the outer foreach loop,
                     // effectively preventing the extension from loading
                     continue 2;
                 }
             }
             // if any of the dependencies are not met in the above loop,
             // this line of code will not be executed
             $env->addExtension($dic->resolve($extension));
         }
     }
     return $env;
 }
Beispiel #5
0
 /**
  * Make the session object.
  *
  * @return \Symfony\Component\HttpFoundation\Session\Session
  */
 public function makeSession()
 {
     $session = new Session($this->dic->resolve('Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface'), $this->dic->resolve('Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface'), $this->dic->resolve('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface'));
     $session->setName($this->config->get('session.cookie.name', 'autarky_session'));
     return $session;
 }
Beispiel #6
0
 protected static function resolveProxyInstance()
 {
     return static::$container->resolve(static::getProxyContainerKey());
 }
 /**
  * The implementation of the twig partial() function.
  *
  * @param  array $name   ['ClassName', 'method']
  * @param  array $params
  *
  * @return string
  */
 public function getPartial(array $name, array $params = array())
 {
     list($class, $method) = $name;
     $obj = $this->container->resolve($class);
     return call_user_func_array([$obj, $method], $params);
 }