本文整理汇总了PHP中Blade类的典型用法代码示例。如果您正苦于以下问题:PHP Blade类的具体用法?PHP Blade怎么用?PHP Blade使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Blade类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* Метод подключения шаблонов
* @param string $view имя шаблона
* @param array $params массив параметров
* @param boolean $return выводить или возвращать код
* @return string сформированный код
*/
public static function view($template, $params = [], $return = false)
{
$blade = new Blade(APP . '/views', STORAGE . '/cache');
if ($return) {
return $blade->view()->make($template, $params)->render();
} else {
echo $blade->view()->make($template, $params)->render();
}
}
示例2: boot
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;
});
}
示例3: boot
/**
* 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; ?>';
});
}
示例4: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{', '}}');
\Blade::setEchoFormat('nl2br(e(%s))');
\Form::component('checklist', 'components.form.checklist', ['name', 'options']);
}
示例5: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::extend(function ($value) {
$value = preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
return $value;
});
}
示例6: sharpen
/**
* Register the Blade view engine with Laravel.
*
* @return void
*/
public static function sharpen()
{
Event::listen(View::engine, function ($view) {
// The Blade view engine should only handle the rendering of views which
// end with the Blade extension. If the given view does not, we will
// return false so the View can be rendered as normal.
if (!str_contains($view->path, BLADE_EXT)) {
//return;
}
$compiled = Blade::compiled($view->path);
// If the view doesn't exist or has been modified since the last time it
// was compiled, we will recompile the view into pure PHP from it's
// Blade representation, writing it to cached storage.
if (!file_exists($compiled) or Blade::expired($view->view, $view->path)) {
file_put_contents($compiled, Blade::compile($view));
}
$view->mytplengine or $view->mytplengine = new \TemplateEngine(TEMPLATEPATH);
//kd($compiled);
$compiled = $view->mytplengine->display($compiled, true);
$view->path = $compiled;
// Once the view has been compiled, we can simply set the path to the
// compiled view on the view instance and call the typical "get"
// method on the view to evaluate the compiled PHP view.
return ltrim($view->get());
});
}
示例7: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::setContentTags('<%', '%>');
// for variables and all things Blade
\Blade::setEscapedContentTags('<%%', '%%>');
// for escaped data
}
示例8: register
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../../../config/veer.php', 'veer');
\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');
}
示例9: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$_this =& $this;
$this->app->bind('theme.assets', function ($app) {
return new \Onefasteuro\Theme\Assets(new \Assetic\AssetManager(), $app);
});
$this->app->bind('theme.page', function ($app) {
return new Page\StaticPage($app['config'], $app['theme.assets']);
});
$this->app->bind('theme.parser', function ($app) use(&$_this) {
$parser = Helper::parser($app);
$class = new \ReflectionClass("\\Onefasteuro\\Theme\\{$parser}");
$class = $class->newInstance($app['config'], $app['theme.page']);
return $class;
});
$this->app->booting(function () {
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Helper', '\\Onefasteuro\\Theme\\Helper');
});
/** blade partials **/
\Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createMatcher('partials');
return preg_replace($pattern, '$1<?php echo \\$__env->make("theme.views::".Helper::skin().".partials.".$2, array_except(get_defined_vars(), array("__data", "__path")))->render(); ?>', $view);
});
}
示例10: bladeDirectives
/**
* Register the blade directives
*
* @return void
*/
private function bladeDirectives()
{
if (!class_exists('\\Blade')) {
return;
}
// Call to Entrust::hasRole
\Blade::directive('role', function ($expression) {
return "<?php if (\\Entrust::hasRole{$expression}) : ?>";
});
\Blade::directive('endrole', function ($expression) {
return "<?php endif; // Entrust::hasRole ?>";
});
// Call to Entrust::can
\Blade::directive('permission', function ($expression) {
return "<?php if (\\Entrust::can{$expression}) : ?>";
});
\Blade::directive('endpermission', function ($expression) {
return "<?php endif; // Entrust::can ?>";
});
// Call to Entrust::ability
\Blade::directive('ability', function ($expression) {
return "<?php if (\\Entrust::ability{$expression}) : ?>";
});
\Blade::directive('endability', function ($expression) {
return "<?php endif; // Entrust::ability ?>";
});
}
示例11: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
app()->booted(function () {
if (!defined('LARAVEL_BOOTED')) {
define('LARAVEL_BOOTED', microtime(true));
}
});
// \View::composer('*', function($view)
// {
// // prifile views?
// });
\Blade::directive('li', function ($args) {
$args = explode(',', str_replace(["(", ")"], '', $args));
$cmd = str_replace(["'", '"'], '', $args[0]);
array_shift($args);
$args = implode(',', $args);
return "<?php li()->{$cmd}({$args}); ?>";
});
if (\DB::connection()->getDatabaseName()) {
\DB::listen(function ($sql) {
\Lsrur\Inspector\Facade\Inspector::addSql($sql);
});
}
if (is_dir(base_path() . '/resources/views/packages/lsrur/inspector')) {
$this->loadViewsFrom(base_path() . '/resources/views/packages/lsrur/inspector', 'inspector');
} else {
// The package views have not been published. Use the defaults.
$this->loadViewsFrom(__DIR__ . '/views', 'inspector');
}
$kernel = $this->app->make('Illuminate\\Contracts\\Http\\Kernel');
$kernel->pushMiddleware('Lsrur\\Inspector\\Middleware\\Inspector');
$this->publishes([__DIR__ . '/config/inspector.php' => config_path('inspector.php')], 'config');
$this->mergeConfigFrom(__DIR__ . '/config/inspector.php', 'inspector');
}
示例12: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
/* @eval($var++) */
\Blade::extend(function ($view) {
return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view);
});
}
示例13: register
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('Illuminate\\Contracts\\Auth\\Registrar', 'App\\Services\\Registrar');
\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');
}
示例14: boot
public function boot()
{
//@define $i = 'whatever'
\Blade::extend(function ($value) {
return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
});
}
示例15: index
/**
* Return template for Angular
*
* @return View
*/
public function index()
{
// Change blade tags so they don't clash with Angular
Blade::setEscapedContentTags('[[[', ']]]');
Blade::setContentTags('[[', ']]');
return View::make('addressbook');
}