Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $finder = new Finder();
     $bridge = new TwigBridge($this->laravel);
     $this->twig = $bridge->getTwig();
     $paths = $this->twig->getLoader()->getPaths();
     // Lint check all twig files on our path
     $finder->files()->in($paths)->name('*.' . $bridge->getExtension());
     $pass = 0;
     $fail = 0;
     foreach ($finder as $file) {
         if ($this->processFile($file->getRealPath())) {
             $pass++;
         } else {
             $fail++;
         }
     }
     // Output totals
     if ($fail > 0) {
         $this->line('');
     }
     if ($pass > 0) {
         $msg = $pass > 1 ? 'files' : 'file';
         $msg = $pass . ' ' . $msg . ' successfully checked';
         $this->info($msg);
     }
     if ($fail > 0) {
         $msg = $fail > 1 ? 'files' : 'file';
         $msg = $fail . ' ' . $msg . ' failed';
         $this->error($msg);
     }
     // Return exit code
     return $fail === 0 ? 0 : 1;
 }
Exemplo n.º 2
0
 /**
  * Compiles all Twig files under path to cache directory.
  *
  * @param string $path All twig files under this path are compiled.
  * @return void
  */
 protected function processPath($path)
 {
     $path = realpath($path);
     $bridge = new TwigBridge($this->laravel);
     $engine = new TwigEngine($bridge->getTwig());
     $finder = new Finder();
     $finder->files()->in($path)->name('*.' . $bridge->getExtension());
     foreach ($finder as $file) {
         $full_path = $file->getRealPath();
         // Handle files found in sub-folders
         $view = str_replace($path, '', $full_path);
         $view = $view[0] === '/' ? substr($view, 1) : $view;
         $dir = pathinfo($view, PATHINFO_DIRNAME);
         $dir = $dir !== '.' ? $dir . '/' : '';
         $view = $dir . pathinfo($view, PATHINFO_FILENAME);
         // Let Twig compile the view
         $engine->load($full_path, $view);
         $this->count++;
     }
 }
Exemplo n.º 3
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testUnsupportedExceptionType()
 {
     $bridge = new TwigBridge($this->getApplication());
     $bridge->setExtensions(array(12345));
     $bridge->getTwig();
 }