当前位置: 首页>>代码示例>>PHP>>正文


PHP BladeCompiler::directive方法代码示例

本文整理汇总了PHP中Illuminate\View\Compilers\BladeCompiler::directive方法的典型用法代码示例。如果您正苦于以下问题:PHP BladeCompiler::directive方法的具体用法?PHP BladeCompiler::directive怎么用?PHP BladeCompiler::directive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\View\Compilers\BladeCompiler的用法示例。


在下文中一共展示了BladeCompiler::directive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Template constructor.
  *
  * @param Container $container
  */
 public function __construct(Container $container)
 {
     $settings = $container->get('settings');
     $compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views';
     $resolver = new EngineResolver();
     $resolver->register('blade', function () use($compiledPath, &$settings) {
         $bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath);
         // Add the @webroot directive.
         $bladeCompiler->directive('webroot', function ($expression) use(&$settings) {
             $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
             $path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/');
             $path = str_replace("'", "\\'", $path);
             return "<?= e('{$path}') ?>";
         });
         // Add the @route directive.
         $bladeCompiler->directive('route', function ($expression) use(&$settings) {
             $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
             $path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/');
             $path = str_replace("'", "\\'", $path);
             return "<?= e('{$path}') ?>";
         });
         return new CompilerEngine($bladeCompiler);
     });
     $finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]);
     $factory = new ViewFactory($resolver, $finder, new Dispatcher());
     $this->factory = $factory;
     $this->container = $container;
 }
开发者ID:garbetjie,项目名称:tiny,代码行数:33,代码来源:TemplateRenderer.php

示例2: registerDirectives

 /**
  * Add extra directives to the blade templating compiler.
  *
  * @param BladeCompiler $blade The compiler to extend
  *
  * @return void
  */
 public static function registerDirectives(BladeCompiler $blade)
 {
     $keywords = ["namespace", "use"];
     foreach ($keywords as $keyword) {
         $blade->directive($keyword, function ($parameter) use($keyword) {
             $parameter = trim($parameter, "()");
             return "<?php {$keyword} {$parameter} ?>";
         });
     }
     $assetify = function ($file, $type) {
         $file = trim($file, "()");
         if (in_array(substr($file, 0, 1), ["'", '"'], true)) {
             $file = trim($file, "'\"");
         } else {
             return "{{ {$file} }}";
         }
         if (substr($file, 0, 1) !== "/") {
             $file = "/{$type}/{$file}";
         }
         if (substr($file, (strlen($type) + 1) * -1) !== ".{$type}") {
             $file .= ".{$type}";
         }
         return $file;
     };
     $blade->directive("css", function ($parameter) use($assetify) {
         $file = $assetify($parameter, "css");
         return "<link rel='stylesheet' type='text/css' href='{$file}'>";
     });
     $blade->directive("js", function ($parameter) use($assetify) {
         $file = $assetify($parameter, "js");
         return "<script type='text/javascript' src='{$file}'></script>";
     });
 }
开发者ID:quenti77,项目名称:easyhq,代码行数:40,代码来源:Blade.php

示例3: extendTo

 public function extendTo(BladeCompiler $blade)
 {
     $blade->directive('wploop', $this->start());
     $blade->directive('wpempty', $this->ifempty());
     $blade->directive('endwploop', $this->end());
     $blade->directive('wpthe', $this->the());
 }
开发者ID:kenvunz,项目名称:lucent,代码行数:7,代码来源:Loop.php

示例4: register

 public function register()
 {
     $this->app->instance(__CLASS__, $this);
     $this->app->alias(__CLASS__, $this->containerName);
     $this->blade->directive('include_layout', function ($expr) {
         return "<?php echo app('{$this->containerName}')->renderLayout{$expr} ?>";
     });
 }
开发者ID:windqyoung,项目名称:utils,代码行数:8,代码来源:BladeExtension.php

示例5: allowHighlightTag

    /**
     * Add basic syntax highlighting.
     *
     * This just adds markup that is picked up by a javascript highlighting library.
     *
     * @param BladeCompiler $compiler
     */
    protected function allowHighlightTag(BladeCompiler $compiler)
    {
        $compiler->directive('highlight', function ($expression) {
            if (is_null($expression)) {
                $expression = "('php')";
            }
            return "<?php \$__env->startSection{$expression}; ?>";
        });
        $compiler->directive('endhighlight', function () {
            return <<<'HTML'
<?php $last = $__env->stopSection(); echo '<pre><code class="language-', $last, '">', trim($__env->yieldContent($last)), '</code></pre>'; ?>
HTML;
        });
    }
开发者ID:parsnick,项目名称:steak,代码行数:21,代码来源:RegisterBladeExtensions.php

示例6: register

 /**
  * Register.
  *
  * @param \Illuminate\View\Compilers\BladeCompiler $compiler
  *
  * @return void
  */
 public static function register(BladeCompiler $compiler)
 {
     $compiler->directive('money', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo money({$expression}); ?>";
     });
     $compiler->directive('currency', function ($expression) {
         if (Str::startsWith($expression, '(')) {
             $expression = substr($expression, 1, -1);
         }
         return "<?php echo currency({$expression}); ?>";
     });
 }
开发者ID:cknow,项目名称:laravel-money,代码行数:22,代码来源:BladeExtensions.php

示例7: registerBladeDirective

 /**
  * Register the custom Blade directive
  *
  * @param \Illuminate\View\Compilers\BladeCompiler $compiler
  */
 private function registerBladeDirective($compiler)
 {
     $compiler->directive('notifications', function () {
         $expression = 'Gloudemans\\Notify\\Notifications\\Notification';
         return "<?php echo app('{$expression}')->render(); ?>";
     });
 }
开发者ID:Crinsane,项目名称:LaravelNotify,代码行数:12,代码来源:NotificationsDirectiveTest.php

示例8: extend

 /**
  * extend
  *
  * @param   BladeCompiler $blade
  * @param   string        $name
  * @param   callable      $closure
  *
  * @return  void
  */
 public static function extend(BladeCompiler $blade, $name, $closure)
 {
     // For 5.0 after
     if (is_callable(array($blade, 'directive'))) {
         $blade->directive($name, $closure);
         return;
     }
     // For 4.x before
     $blade->extend(function ($view, BladeCompiler $compiler) use($name, $closure) {
         $pattern = $compiler->createMatcher($name);
         return preg_replace_callback($pattern, function ($matches) use($closure) {
             if (empty($matches[2])) {
                 return $matches[0];
             }
             return $matches[1] . $closure($matches[2]);
         }, $view);
     });
     return;
 }
开发者ID:im286er,项目名称:windwalker,代码行数:28,代码来源:BladeExtending.php

示例9: directive

 /**
  * Register a handler for custom directives.
  *
  * @param string $name
  * @param callable $handler
  * @return void 
  * @static 
  */
 public static function directive($name, $handler)
 {
     \Illuminate\View\Compilers\BladeCompiler::directive($name, $handler);
 }
开发者ID:satriashp,项目名称:tour,代码行数:12,代码来源:_ide_helper.php

示例10: registerDoShortcode

 /**
  * @shortcode
  *
  * @param BladeCompiler $compiler The blade compiler to extend
  */
 private function registerDoShortcode($compiler)
 {
     $compiler->directive('shortcode', function ($expression) {
         return "<?php do_shortcode(with{$expression}); ?>";
     });
 }
开发者ID:marvinlabs,项目名称:baobab,代码行数:11,代码来源:WordPressShortcodeExtension.php

示例11: registerTag

 /**
  * Register Blade syntax for a specific plugin.
  *
  * @param   string  $method
  * @return  void
  */
 protected function registerTag($method)
 {
     $this->blade->directive($method, function ($expression) use($method) {
         return "Plugin::{$method}{$expression}";
     });
 }
开发者ID:caffeinated,项目名称:plugins,代码行数:12,代码来源:Plugins.php

示例12: registerEndLoop

 /**
  * @wpend
  *
  * @param BladeCompiler $compiler The blade compiler to extend
  */
 private function registerEndLoop($compiler)
 {
     $compiler->directive('endwpquery', function ($expression) {
         return "<?php endif; wp_reset_postdata(); ?>";
     });
 }
开发者ID:marvinlabs,项目名称:baobab,代码行数:11,代码来源:WordPressQueryExtension.php

示例13: registerTag

 /**
  * Register Blade syntax for a specific component.
  *
  * @param  string $method
  * @param  string $namespace
  * @return void
  */
 protected function registerTag($method, $namespace = '')
 {
     $this->blade->directive('component_' . $method, function ($view) use($method, $namespace) {
         return '<?php echo ' . $namespace . $method . "{$view}; ?>";
     });
 }
开发者ID:Dalvej,项目名称:triweb,代码行数:13,代码来源:Components.php

示例14: registerBladeDirective

 /**
  * Register the `@criticalCss($uri)` Blade directive.
  *
  * @return void
  */
 public static function registerBladeDirective(BladeCompiler $blade)
 {
     $blade->directive('criticalCss', [static::class, 'parseBladeDirective']);
 }
开发者ID:krisawzm,项目名称:critical-css,代码行数:9,代码来源:BladeUtils.php

示例15: function

}, 'template' => function (Container $container) {
    return new TemplateRenderer($container);
}, 'validator' => function (Container $container) {
    return new ValidationFactory($container['translator']);
}, 'translator' => function (Container $container) {
    return new Translator($container['settings']['locale']);
}, 'viewFactory' => function (Container $container) {
    $settings = $container->get('settings');
    $compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views';
    $resolver = new EngineResolver();
    $resolver->register('blade', function () use($compiledPath, &$settings) {
        $bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath);
        // Add the @webroot directive.
        $bladeCompiler->directive('webroot', function ($expression) use(&$settings) {
            $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
            $path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/');
            $path = str_replace("'", "\\'", $path);
            return "<?= e('{$path}') ?>";
        });
        // Add the @route directive.
        $bladeCompiler->directive('route', function ($expression) use(&$settings) {
            $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression));
            $path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/');
            $path = str_replace("'", "\\'", $path);
            return "<?= e('{$path}') ?>";
        });
        return new CompilerEngine($bladeCompiler);
    });
    $finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]);
    return new ViewFactory($resolver, $finder, new Dispatcher());
}];
开发者ID:garbetjie,项目名称:tiny,代码行数:31,代码来源:bootstrap.php


注:本文中的Illuminate\View\Compilers\BladeCompiler::directive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。