Beispiel #1
0
 /**
  * add the @publicFile('/file/in/public/folder') syntax to Blade
  * to allow inline usage of css and js files
  */
 private function addPublicFileMatcher()
 {
     $this->blade->getCompiler()->extend(function ($view, $compiler) {
         $pattern = "/(?<!\\w)(\\s*)@publicFile\\('(\\s*.*)'\\)/";
         return preg_replace($pattern, '<?php include "' . realpath(__DIR__ . '/../../../public/') . '/$2"; ?>', $view);
     });
 }
Beispiel #2
0
 /**
  * @param string $template
  *
  * @return string
  */
 function render($template)
 {
     global $__env;
     if (!ends_with($template, '.php')) {
         //error_log('cache: ' . $template);
         return $template;
     }
     $this->blade->view()->addExtension('php', 'blade');
     $view = $this->blade->view()->file($template)->render();
     $cache = $this->blade->getCompiler()->getCompiledPath($template);
     $__env = $this->blade->view();
     return $cache;
 }
Beispiel #3
0
 /**
  * Render Blade template
  * 
  * @param string $template template path
  * @param array $params parameters array for template
  */
 public function render($template, array $params, $disabledebug = false)
 {
     $ret = "";
     try {
         if ($this->_container == null) {
             throw new \Exception("Missing Dependency Container, add it with setContainer Method");
         }
         \Debug::startMeasure('initblade', 'Init blade templating environnment');
         $cachepath = CACHEPATH . DS . 'blade';
         $views = $this->getPathArray();
         $blade = new Blade($views, $cachepath);
         // get blade compiler
         $compiler = $blade->getCompiler();
         // add use directive
         $compiler->directive('use', function ($expression) {
             return "<?php use {$expression}; ?>";
         });
         \Debug::stopMeasure('initblade');
         if (DEVELOPMENT_ENVIRONMENT && $disabledebug == false) {
             \Debug::startMeasure('renderblade', 'Blade rendering');
             // render the template file and echo it
             $ret = $blade->view()->make($template, $params)->render();
             \Debug::stopMeasure('renderblade', 'Blade rendering');
         } else {
             $ret = $blade->view()->make($template, $params)->render();
         }
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage());
     }
     return $ret;
 }
Beispiel #4
0
 /**
  * Apply the data to configure the theme
  */
 public function run()
 {
     $data = $this->getData();
     // If blade is enabled, initialize it
     if ($this->isBladeEnabled()) {
         $bladeConfig = $data['blade'];
         // Setup blade and paths
         $viewsPath = $bladeConfig['paths']['views'];
         $cachePath = $bladeConfig['paths']['cache'];
         $blade = new Blade($viewsPath, $cachePath);
         // Extend blade
         /** @var \Illuminate\View\Compilers\BladeCompiler $compiler */
         $compiler = $blade->getCompiler();
         $extensions = array(new WordPressLoopExtension(), new WordPressQueryExtension(), new WordPressShortcodeExtension());
         /** @var Extension $ext */
         foreach ($extensions as $ext) {
             $ext->register($compiler);
         }
         // Set the blade engine in the facade
         Baobab::setBlade($blade);
     }
 }
 /**
  * Sets up template engine to mimic Laravel.
  *
  * @param BladeDirectiveInterface $directive
  * @return Blade
  */
 private function setUpTemplateEngine(BladeDirectiveInterface $directive)
 {
     list($views, $cache) = $this->createTestWorld();
     $blade = new Blade($views, $cache);
     $blade->getCompiler()->directive($directive->openingTag(), [$directive, 'openingHandler']);
     $blade->getCompiler()->directive($directive->closingTag(), [$directive, 'closingHandler']);
     return $blade;
 }