本文整理匯總了PHP中Blade::getCompiler方法的典型用法代碼示例。如果您正苦於以下問題:PHP Blade::getCompiler方法的具體用法?PHP Blade::getCompiler怎麽用?PHP Blade::getCompiler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Blade
的用法示例。
在下文中一共展示了Blade::getCompiler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: extend
/**
* Extend blade
* @return void
*/
protected function extend()
{
// add @acfrepeater
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@acf\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( have_rows( $2 ) ) : ';
$replacement .= 'while ( have_rows( $2 ) ) : the_row(); ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @acfempty
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@acfempty', '<?php endwhile; ?><?php else: ?>', $view);
});
// add @acfend
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
return str_replace('@acfend', '<?php endif; ?>', $view);
});
// add @subfield
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@subfield\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_sub_field( $2 ) ) : ';
$replacement .= 'the_sub_field($2); endif; ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @field
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@field\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_field( $2 ) ) : ';
$replacement .= 'the_field($2); endif; ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @hasfield
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@hasfield\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_field( $2 ) ) : ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @wpposts
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpposts', '<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>', $view);
});
// add @wpquery
$this->blade->getCompiler()->extend(function ($view, $compiler) {
$pattern = '/(\\s*)@wpquery(\\s*\\(.*\\))/';
$replacement = '$1<?php $bladequery = new WP_Query$2; ';
$replacement .= 'if ( $bladequery->have_posts() ) : ';
$replacement .= 'while ( $bladequery->have_posts() ) : ';
$replacement .= '$bladequery->the_post(); ?> ';
return preg_replace($pattern, $replacement, $view);
});
// add @wpempty
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpempty', '<?php endwhile; ?><?php else: ?>', $view);
});
// add @wpend
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpend', '<?php endif; wp_reset_postdata(); ?>', $view);
});
// add @scripts
$self = $this;
$this->blade->getCompiler()->directive('scripts', function ($expression) use($self) {
return '<?php ' . get_class($self) . '::add_scripts(' . $expression . '); ?>';
});
}