Blade::directive PHP Méthode

directive() public static méthode

Register a handler for custom directives.
public static directive ( string $name, callable $handler ) : void
$name string
$handler callable
Résultat void
        public static function directive($name, $handler)
        {
            \Illuminate\View\Compilers\BladeCompiler::directive($name, $handler);
        }

Usage Example

 /**
  * Bootstrap any application services.
  */
 public function boot()
 {
     \Blade::directive('macro', function ($expression) {
         $pattern = '/(\\([\'|\\"](\\w+)[\'|\\"],\\s*(([^\\@])+|(.*))\\))/xim';
         $matches = [];
         preg_match_all($pattern, $expression, $matches);
         if (!isset($matches[3][0])) {
             throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: macro%s', $expression));
         }
         return sprintf("<?php \$___tiny['%s']=function(%s){ ob_start(); ?>\n", $matches[2][0], $matches[3][0]);
     });
     \Blade::directive('endmacro', function ($expression) {
         return "\n<?php return ob_get_clean();} ?>\n";
     });
     \Blade::directive('usemacro', function ($expression) {
         $pattern = '/(\\([\'|\\"](\\w+)[\'|\\"],\\s*(([^\\@])+|(.*))\\))/xim';
         $matches = [];
         preg_match_all($pattern, $expression, $matches);
         if (!isset($matches[3][0])) {
             throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: usemacro%s', $expression));
         }
         return sprintf("<?php echo \$___tiny['%s'](%s); ?>\n", $matches[2][0], $matches[3][0]);
     });
     \Blade::directive('permission', function ($expression) {
         return "<?php if(Auth::user()->permission{$expression}): ?>";
     });
     \Blade::directive('endpermission', function ($expression) {
         return '<?php endif; ?>';
     });
 }
All Usage Examples Of Blade::directive