本文整理汇总了PHP中Blade::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Blade::extend方法的具体用法?PHP Blade::extend怎么用?PHP Blade::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blade
的用法示例。
在下文中一共展示了Blade::extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
});
}
示例2: registerBladeTemplate
/**
* Register the view environment.
*/
public function registerBladeTemplate()
{
/*
|--------------------------------------------------------------------------
| @lm-attrs
|--------------------------------------------------------------------------
|
| Buffers the output if there's any.
| The output will be passed to mergeStatic()
| where it is merged with item's attributes
|
*/
\Blade::extend(function ($view, $compiler) {
$pattern = '/(\\s*)@lm-attrs\\s*\\((\\$[^)]+)\\)/';
return preg_replace($pattern, '$1<?php $lm_attrs = $2->attr(); ob_start(); ?>', $view);
});
/*
|--------------------------------------------------------------------------
| @lm-endattrs
|--------------------------------------------------------------------------
|
| Reads the buffer data using ob_get_clean()
| and passes it to MergeStatic().
| mergeStatic() takes the static string,
| converts it into a normal array and merges it with others.
|
*/
\Blade::extend(function ($view, $compiler) {
$pattern = $compiler->CreatePlainMatcher('lm-endattrs');
return preg_replace($pattern, '$1<?php echo \\Lavary\\Menu\\Builder::mergeStatic(ob_get_clean(), $lm_attrs); ?>$2', $view);
});
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
/* @eval($var++) */
\Blade::extend(function ($view) {
return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view);
});
}
示例4: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::extend(function ($value) {
$value = preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
return $value;
});
}
示例5: 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);
});
}
示例6: boot
public function boot()
{
//@define $i = 'whatever'
\Blade::extend(function ($value) {
return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
});
}
示例7: registerPHP
/**
* register `@php()` directive
*/
public static function registerPHP($tagName = 'php')
{
\Blade::extend(function ($view, $compiler) use($tagName) {
$pattern = $compiler->createMatcher($tagName);
$code = "<?php \$2 ?" . ">";
return preg_replace($pattern, $code, $view);
});
}
示例8: boot
/**
* 引导任何应用服务。
*
* @return void
*/
public function boot()
{
\Blade::extend(function ($view, $compiler) {
$this->app->make('phpBlade')->php($view, $compiler);
$this->app->make('phpBlade')->endphp($view, $compiler);
$this->app->make('phpBlade')->datetime($view, $compiler);
return $view;
});
}
示例9: register
public static function register()
{
foreach (static::$compiles as $function) {
if (!method_exists(__CLASS__, $function = 'compile_' . $function)) {
continue;
}
\Blade::extend(function ($view, $compiler) use($function) {
return call_user_func([__CLASS__, $function], $view, $compiler);
});
}
}
示例10: boot
public function boot()
{
/* @datetime($var) */
\Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createOpenMatcher('datetime');
return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/Y H:i\')); ?>', $view);
});
/* @eval($var++) */
\Blade::extend(function ($view) {
return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view);
});
}
示例11: boot
public function boot()
{
$this->publishes([__DIR__ . '/../../../database/migrations/' => database_path('/migrations')], 'migrations');
$this->publishes([__DIR__ . '/../../../config/' => config_path()], 'config');
SiteConfig::macro('has_bonus', function () {
return config('bonus') != null;
});
\Blade::extend(function ($view, $compiler) {
$pattern = "/(?<!\\w)(\\s*)@blink\\(\\s*(.*?)\\)/";
return preg_replace($pattern, '$1' . '<?php if($auth->admin || $auth->id == $2->user->id || $auth->id == $2->user->referral_id|| $auth->id == $2->user->new_referral_id) {?>' . PHP_EOL . '<a href="/bonus-management/view/<?php echo $2->id ?>">' . PHP_EOL . '#<?php echo (1024 + $2->id) ?>' . PHP_EOL . '</a>' . PHP_EOL . '<?php } else { ?>' . PHP_EOL . '<?php echo (1024 + $2->id) ?>' . PHP_EOL . '<?php }?>', $view);
});
}
示例12: boot
public function boot()
{
/*
|--------------------------------------------------------------------------
| Extend blade so we can define a variable
| <code>
| @define $variable = "whatever"
| </code>
|--------------------------------------------------------------------------
*/
\Blade::extend(function ($value) {
return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
});
}
示例13: boot
public function boot()
{
\Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createOpenMatcher('tab');
return str_replace('-Ab-', '<a href="chords.php" class="Ab">Ab</a>', $view);
});
\Blade::extend(function ($view, $compiler) {
$pattern = $compiler->createOpenMatcher('datetime');
return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/Y H:i\')); ?>', $view);
});
/* @eval($var++) */
\Blade::extend(function ($view) {
return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view);
});
}
示例14: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\HTML::macro('activeClass', function ($path, $active = 'active') {
if (Request::is($path . "*")) {
return $active;
}
return '';
});
\Validator::resolver(function ($translator, $data, $rules, $messages) {
return new CustomValidator($translator, $data, $rules, $messages);
});
\Blade::extend(function ($value) {
return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
});
}
示例15: registerBladeExtensions
public function registerBladeExtensions()
{
\Blade::extend(function ($view, $compiler) {
$pattern = '/@content\\(\'(.*?)\'\\)(.*?)@endcontent/is';
preg_match_all($pattern, $view, $result);
if (is_array($result)) {
for ($i = 0; count($result[1]) > $i; $i++) {
$replace = $result[0][$i];
$key = $result[1][$i];
$value = $result[2][$i];
if ($key && $value) {
$o = \KSPM\LCMS\Model\Content::where('key', '=', $key)->first();
if (!$o) {
$o = \KSPM\LCMS\Model\Content::create(array('key' => $key, 'value' => $value));
}
$o = "<?php echo \\KSPM\\LCMS\\Model\\Content::where('key', '=', '{$key}')->first()->value; ?>";
$view = str_replace($replace, $o, $view);
}
}
}
$pattern = '/@editable_content\\(\'(.*?)\'\\)(.*?)@endeditable_content/is';
preg_match_all($pattern, $view, $result);
$cmswrapper = '<div class="laikacms-editable" data-id="%%%oid%%%">%%%php%%%</div>';
if (is_array($result)) {
for ($i = 0; count($result[1]) > $i; $i++) {
$replace = $result[0][$i];
$key = $result[1][$i];
$value = $result[2][$i];
if ($key && $value) {
$o = \KSPM\LCMS\Model\Content::where('key', '=', $key)->first();
if (!$o) {
$o = \KSPM\LCMS\Model\Content::create(array('key' => $key, 'value' => $value));
}
$o = "<?php \$c = \\KSPM\\LCMS\\Model\\Content::where('key', '=', '{$key}')->first()->value; echo str_replace('%%%oid%%%','{$o->id}', str_replace('%%%php%%%', \$c, '{$cmswrapper}')); ?>";
$view = str_replace($replace, $o, $view);
}
}
}
return $view;
});
}