本文整理汇总了PHP中Illuminate\View\Compilers\BladeCompiler::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP BladeCompiler::extend方法的具体用法?PHP BladeCompiler::extend怎么用?PHP BladeCompiler::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\View\Compilers\BladeCompiler
的用法示例。
在下文中一共展示了BladeCompiler::extend方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerBlade
/**
* Register blade syntax for a specific widget.
*
* @param string $name
*/
protected function registerBlade($name)
{
$this->blade->extend(function ($view, $compiler) use($name) {
$pattern = $this->createMatcher($name);
$replace = '$1<?php echo Widget::' . $name . '$2; ?>';
return preg_replace($pattern, $replace, $view);
});
}
示例2: registerTag
/**
* Register Blade syntax for a specific component.
*
* @param string $method
* @param string $namespace
* @return void
*/
protected function registerTag($method, $namespace = '')
{
$this->blade->extend(function ($view, $compiler) use($method, $namespace) {
$pattern = $compiler->createMatcher('component_' . $method);
$replace = '$1<?php echo ' . $namespace . $method . '$2; ?>';
return preg_replace($pattern, $replace, $view);
});
}
示例3: addLoopControlDirectives
/**
* Extend blade by continue and break directives.
*
* @param BladeCompiler $blade
*
* @return BladeCompiler
*/
private function addLoopControlDirectives(BladeCompiler $blade)
{
$blade->extend(function ($value) {
$pattern = '/(?<!\\w)(\\s*)@continue\\s*\\(([^)]*)\\)/';
$replacement = '$1<?php if ($2) { continue; } ?>';
return preg_replace($pattern, $replacement, $value);
});
$blade->extend(function ($value) {
$pattern = '/(?<!\\w)(\\s*)@break\\s*\\(([^)]*)\\)/';
$replacement = '$1<?php if ($2) { break; } ?>';
return preg_replace($pattern, $replacement, $value);
});
return $blade;
}
示例4: addBladeViewTesting
/**
* Adds all class methods prefixed with assert* as blade view directives
* and assigns the $view and $blade class properties
*
* @param string $viewDirectoryPath The path to the directory containing test views
*/
public function addBladeViewTesting($viewDirectoryPath = null)
{
/** @var \Illuminate\View\Factory $view */
$view = $this->app['view'];
// Add instance of current test class, this enable to call assert functions in views
$view->share('testClassInstance', $this);
// Lets make those assertions callable by fancy blade directives, nom nom nom
$this->blade = $view->getEngineResolver()->resolve('blade')->getCompiler();
$this->blade->extend(function ($value) {
return preg_replace('/@assert(\\w*)\\((.*)\\)/', "<?php \$testClassInstance->assert\$1(\$2); ?>", $value);
});
if ($viewDirectoryPath !== null) {
$view->addLocation($viewDirectoryPath);
}
}
示例5: extend
/**
* Turn $this->extend() into @extend().
*/
protected function extend()
{
$this->compiler->extend(function ($view, $compiler) {
$pattern = $compiler->createMatcher('extend');
return preg_replace($pattern, '$1<?php echo $_view->extend$2; ?>', $view);
});
}
示例6: registerSearchForm
protected function registerSearchForm(Compiler $blade, $name)
{
$blade->extend(function ($view, $compiler) use($name) {
$pattern = $compiler->createMatcher($name);
$code = <<<'EOD'
$1<?php
if (isset($searchForm)) {
echo $searchForm;
} else{
$passed = array$2;
if (count($passed) == 2) {
$m = $passed[0];
$res = $passed[1];
}
if (count($passed) == 1) {
$m = $passed[0];
$res = isset($resource) ? $resource : null;
}
if (count($passed) == 0) {
$m = isset($model) ? $model : null;
$res = isset($resource) ? $resource : null;
}
echo Resource::searchForm($m, $res);
}
?>
EOD;
return preg_replace($pattern, $code, $view);
});
}
示例7: registerDoShortcode
/**
* @shortcode
*
* @param BladeCompiler $compiler The blade compiler to extend
*/
private function registerDoShortcode($compiler)
{
$compiler->extend(function ($view, $comp) {
$pattern = $comp->createMatcher('shortcode');
$replacement = '$1<?php do_shortcode($2); ?> ';
return preg_replace($pattern, $replacement, $view);
});
}
示例8: registerEndLoop
/**
* @wpend
*
* @param BladeCompiler $compiler The blade compiler to extend
*/
private function registerEndLoop($compiler)
{
$compiler->extend(function ($view, $comp) {
$pattern = $comp->createPlainMatcher('endwploop');
$replacement = '$1<?php endif; wp_reset_postdata(); ?>';
return preg_replace($pattern, $replacement, $view);
});
}
示例9: extendBlade
/**
* Add extra functionality to the blade templating compiler.
*
* @param BladeCompiler $blade The compiler to extend
*
* @return void
*/
public static function extendBlade(BladeCompiler $blade)
{
$keywords = ["namespace", "use"];
foreach ($keywords as $keyword) {
$blade->extend(function ($view, $compiler) use($keyword) {
$pattern = $compiler->createMatcher($keyword);
return preg_replace_callback($pattern, function ($matches) use($keyword) {
return $matches[1] . "<?php {$keyword} " . substr($matches[2], 1, -1) . " ?>";
}, $view);
});
}
$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->extend(function ($view, $compiler) use($assetify) {
$pattern = $compiler->createMatcher("css");
return preg_replace_callback($pattern, function ($matches) use($assetify) {
$file = $assetify($matches[2], "css");
return "<link rel='stylesheet' type='text/css' href='{$file}'>";
}, $view);
});
$blade->extend(function ($view, $compiler) use($assetify) {
$pattern = $compiler->createMatcher("js");
return preg_replace_callback($pattern, function ($matches) use($assetify) {
$file = $assetify($matches[2], "js");
return "<script type='text/javascript' src='{$file}'></script>";
}, $view);
});
}
示例10: register
protected function register()
{
$rules = [BladedSyntax::STATEMENT => $this->getStateParser(), BladedSyntax::CONDITION => $this->getConditionParser(), BladedSyntax::CONDITION_UNLESS => $this->getUnlessConditionParser(), BladedSyntax::CONDITION_ELSE => function () {
return '<?php else: ?>';
}, BladedSyntax::CONDITION_END => function () {
return '<?php endif; ?>';
}, BladedSyntax::ITERATORS => $this->getIteratorParser(), BladedSyntax::ITERATORS_END => $this->getIteratorEndParser(), BladedSyntax::STATEMENT_CACHED => $this->getCacheStateParser(), BladedSyntax::TEMPLATE => $this->getTemplateParser(), BladedSyntax::TEMPLATE_CACHED => $this->getCacheTplParser()];
$this->blade->extend(function ($view) use($rules) {
foreach ($rules as $regexp => $callback) {
$view = preg_replace_callback($regexp, $callback, $view);
}
return $view;
});
}
示例11: 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;
}
示例12: extend
/**
* Register a custom Blade compiler.
*
* @param callable $compiler
* @return void
* @static
*/
public static function extend($compiler)
{
\Illuminate\View\Compilers\BladeCompiler::extend($compiler);
}
示例13: registerRawPhpBraces
/**
* @shortcode
*
* @param BladeCompiler $compiler The blade compiler to extend
*/
private function registerRawPhpBraces($compiler)
{
$compiler->extend(function ($view, $comp) {
return preg_replace('/#\\{\\{\\s*(.+?)\\s*\\}\\}/s', '<?php $1; ?>', $view);
});
}