Blade::extend PHP Méthode

extend() public static méthode

Register a custom Blade compiler.
public static extend ( callable $compiler ) : void
$compiler callable
Résultat void
        public static function extend($compiler)
        {
            \Illuminate\View\Compilers\BladeCompiler::extend($compiler);
        }

Usage Example

 public function boot()
 {
     $directivesDirectory = base_path() . '/resources/views/directives';
     // Check if directory exists
     if (!File::exists($directivesDirectory)) {
         return;
     }
     $directivePaths = File::files($directivesDirectory);
     // Check if we have at least one file
     if (empty($directivePaths)) {
         return;
     }
     $regex = $this->buildRegex($directivePaths);
     \Blade::extend(function ($view) use($regex) {
         $offset = 0;
         while (preg_match($regex, $view, $matches, PREG_OFFSET_CAPTURE, $offset)) {
             // Store directive name
             $directiveName = $matches[1][0];
             // Store start and length of pattern
             $patternStart = $matches[0][1];
             $patternLength = strlen($matches[0][0]);
             $expressionStart = $matches[2][1];
             // Fetch expression
             $expr = $this->fetchExpression($view, $expressionStart, $patternStart + $patternLength);
             // Store beginning and end
             $beginning = substr($view, 0, $patternStart);
             $end = substr($view, $expressionStart + strlen($expr) + 1);
             // Construct view
             $view = $beginning . "@include('directives.{$directiveName}', array('param' => ({$expr})))" . $end;
             // Compute new offset to search from
             $offset = $patternStart + strlen($expr);
         }
         return $view;
     });
 }
All Usage Examples Of Blade::extend