public function __construct($kernel)
 {
     if (empty($kernel) || !$kernel instanceof Kernel) {
         throw new \InvalidArgumentException("It seems you did not set the new settings in services.yml, please add \"@kernel\" to templating.engine.pug service arguments, see https://github.com/pug-php/pug-symfony#readme", 1);
     }
     $this->kernel = $kernel;
     $cache = $this->getCacheDir();
     if (!file_exists($cache)) {
         mkdir($cache);
     }
     $container = $kernel->getContainer();
     $this->container = $container;
     $environment = $container->getParameter('kernel.environment');
     $appDir = $container->getParameter('kernel.root_dir');
     $rootDir = dirname($appDir);
     $assetsDirectories = array($appDir . '/Resources/assets');
     $srcDir = $rootDir . '/src';
     $webDir = $rootDir . '/web';
     $baseDir = null;
     foreach (scandir($srcDir) as $directory) {
         if ($directory === '.' || $directory === '..' || is_file($srcDir . '/' . $directory)) {
             continue;
         }
         if (is_null($baseDir) && is_dir($srcDir . '/Resources/views')) {
             $baseDir = $appDir . '/Resources/views';
         }
         $assetsDirectories[] = $srcDir . '/' . $directory . '/Resources/assets';
     }
     if (is_null($baseDir)) {
         $baseDir = $appDir . '/Resources/views';
     }
     $this->jade = new Jade(array('assetDirectory' => $assetsDirectories, 'baseDir' => $baseDir, 'cache' => substr($environment, 0, 3) === 'dev' ? false : $cache, 'environment' => $environment, 'extension' => array('.pug', '.jade'), 'outputDirectory' => $webDir, 'preRender' => array($this, 'preRender'), 'prettyprint' => $kernel->isDebug()));
     $this->registerHelpers($container, array_slice(func_get_args(), 1));
     $this->assets = new Assets($this->jade);
     $app = new AppVariable();
     $app->setDebug($kernel->isDebug());
     $app->setEnvironment($environment);
     $app->setRequestStack($container->get('request_stack'));
     $app->setTokenStorage($container->get('security.token_storage'));
     $this->jade->share(array('app' => $app, 'user' => $app->getUser()));
 }
Beispiel #2
0
 public function testEnvironment()
 {
     $this->appVariable->setEnvironment('dev');
     $this->assertEquals('dev', $this->appVariable->getEnvironment());
 }