Example #1
0
 public function __construct(Container $container)
 {
     $rootDir = $container->getParameter('root_dir');
     $productionMode = $container->getParameter('production_mode');
     $loader = new \Twig_Loader_Filesystem($rootDir);
     $this->twig = new \Twig_Environment($loader, array('cache' => $rootDir . '/tmp', 'debug' => !($productionMode === true)));
 }
Example #2
0
 /**
  * Get a factory given a service name
  *
  * @param  string            $factoryName Service name to get factory from
  * @throws \RuntimeException Throws a exception if service does not implment HttpKernelFactory
  *
  * @return \Pyrite\Factory\HttpKernelFactory a factory for a service
  */
 private function getFactory($factoryName)
 {
     $factory = $this->container->get($factoryName);
     if (!$factory instanceof HttpKernelFactory) {
         throw new \RuntimeException(sprintf("Object of class %s does not implement Pyrite\\Factory\\HttpKernelFactory interface", get_class($factory)));
     }
     return $factory;
 }
Example #3
0
 public function __construct(Container $container)
 {
     $rootDir = $container->getParameter('root_dir');
     $productionMode = $container->getParameter('production_mode');
     $debug = !$productionMode;
     $loader = new \Twig_Loader_Filesystem($rootDir);
     $this->twig = new \Twig_Environment($loader, array('cache' => $rootDir . '/tmp', 'debug' => $debug));
     if ($debug && class_exists(VarCloner::class) && class_exists(DumpExtension::class)) {
         $this->twig->addExtension(new DumpExtension(new VarCloner()));
     }
 }
Example #4
0
 private function configOnCrashOutput()
 {
     try {
         $this->uncaughtRenderer = $this->container->get("AppOnCrashHandler");
     } catch (\Exception $e) {
         $this->uncaughtRenderer = new \Pyrite\Exception\UncaughtExceptionRendererImpl(false);
     }
     return $this->uncaughtRenderer;
 }
Example #5
0
 /**
  * @return ContainerInterface
  */
 public function startContainer()
 {
     if (true === $this->isStarted()) {
         return $this->container;
     }
     $configAsArray = iterator_to_array($this->config->getIterator());
     $this->internalConfig['parameters'] = $configAsArray;
     $this->container = $this->createContainer(new ArrayConfig($this->internalConfig));
     $loggerFactory = new LoggerFactory($this->config->get('debug'), $this->config->get('log_dir'));
     $this->container->bind('LoggerFactory', $loggerFactory);
     if (null !== $this->router) {
         // Keep compatibility, use the right type hint in the application as usual (UrlGeneratorInterface, UrlMatcherInterface)
         $this->container->bind('UrlMatcher', $this->router->getUrlMatcher());
         $this->container->bind('UrlGenerator', $this->router->getUrlGenerator());
         $this->container->bind('RouteCollection', $this->router->getRouteCollection());
     }
     $this->container->bind('AppLogger', $this->loggerFactory->getLogger('app'));
     $this->started = true;
     return $this->container;
 }