Added support for Twig style {{ include() }} blade structures that inherit the data from the view.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
parent
57cf817de4
commit
b07ee31f3a
|
@ -8,6 +8,7 @@ class Blade {
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $compilers = array(
|
protected static $compilers = array(
|
||||||
|
'includes',
|
||||||
'echos',
|
'echos',
|
||||||
'forelse',
|
'forelse',
|
||||||
'empty',
|
'empty',
|
||||||
|
@ -85,6 +86,21 @@ public static function compile_string($value)
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrites Blade "include" statements to valid PHP.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function compile_includes($value)
|
||||||
|
{
|
||||||
|
$pattern = '/\{\{(\s*)include(\s*\(.*\))(\s*)\}\}/';
|
||||||
|
|
||||||
|
$value = preg_replace($pattern, '<?php echo render$2', $value);
|
||||||
|
|
||||||
|
return rtrim($value, ')').', get_defined_vars()); ?>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewrites Blade echo statements into PHP echo statements.
|
* Rewrites Blade echo statements into PHP echo statements.
|
||||||
*
|
*
|
||||||
|
@ -115,9 +131,9 @@ protected static function compile_forelse($value)
|
||||||
{
|
{
|
||||||
preg_match('/\$[^\s]*/', $forelse, $variable);
|
preg_match('/\$[^\s]*/', $forelse, $variable);
|
||||||
|
|
||||||
// Once we have extracted the variable being looped against, we cab
|
// Once we have extracted the variable being looped against, we can prepend
|
||||||
// prepend an "if" statmeent to the start of the loop that checks
|
// an "if" statmeent to the start of the loop that checks that the count
|
||||||
// that the count of the variable is greater than zero.
|
// of the variable is greater than zero before looping the data.
|
||||||
$if = "<?php if (count({$variable[0]}) > 0): ?>";
|
$if = "<?php if (count({$variable[0]}) > 0): ?>";
|
||||||
|
|
||||||
$search = '/(\s*)@forelse(\s*\(.*\))/';
|
$search = '/(\s*)@forelse(\s*\(.*\))/';
|
||||||
|
@ -126,9 +142,9 @@ protected static function compile_forelse($value)
|
||||||
|
|
||||||
$blade = preg_replace($search, $replace, $forelse);
|
$blade = preg_replace($search, $replace, $forelse);
|
||||||
|
|
||||||
// Finally, once we have the check prepended to the loop, we will
|
// Finally, once we have the check prepended to the loop, we will replace
|
||||||
// replace all instances of this "forelse" structure in the
|
// all instances of this "forelse" structure in the content of the view
|
||||||
// content of the view being compiled to Blade syntax.
|
// being compiled to Blade syntax using a simple str_replace.
|
||||||
$value = str_replace($forelse, $blade, $value);
|
$value = str_replace($forelse, $blade, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue