本文整理汇总了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;
}
示例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>";
});
}
示例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());
}
示例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} ?>";
});
}
示例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;
});
}
示例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}); ?>";
});
}
示例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(); ?>";
});
}
示例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;
}
示例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);
}
示例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}); ?>";
});
}
示例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}";
});
}
示例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(); ?>";
});
}
示例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}; ?>";
});
}
示例14: registerBladeDirective
/**
* Register the `@criticalCss($uri)` Blade directive.
*
* @return void
*/
public static function registerBladeDirective(BladeCompiler $blade)
{
$blade->directive('criticalCss', [static::class, 'parseBladeDirective']);
}
示例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());
}];