Skip to content

Commit

Permalink
Revert "[10.x] Fix blade failing to compile when mixing inline/block @…
Browse files Browse the repository at this point in the history
…php directives (#48420)" (#48575)

This reverts commit 22d4530.
  • Loading branch information
driesvints committed Sep 28, 2023
1 parent f402d3f commit c834505
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 126 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected function storeVerbatimBlocks($value)
*/
protected function storePhpBlocks($value)
{
return preg_replace_callback('/(?<!@)@php((?:.(?!(?<!@)@php))*?)@endphp/s', function ($matches) {
return preg_replace_callback('/(?<!@)@php(.*?)@endphp/s', function ($matches) {
return $this->storeRawBlock("<?php{$matches[1]}?>");
}, $value);
}
Expand Down
125 changes: 0 additions & 125 deletions tests/View/Blade/BladePhpStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,131 +11,6 @@ public function testPhpStatementsWithExpressionAreCompiled()
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testMixedPhpStatementsAreCompiled()
{
$string = <<<'BLADE'
@php($set = true)
@php($set = true) @php ($set = false;) @endphp
@php ($set = true) @php($set = false;)@endphp
<div>{{ $set }}</div>
@php
$set = false;
@endphp
@php (
$set = false;
)@endphp
@php(
$set = false;
)@endphp
@php (
$set = false
)
@php(
$set = false
)
@php
$set = '@@php';
@endphp
BLADE;
$expected = <<<'PHP'
<?php ($set = true); ?>
<?php ($set = true); ?> <?php ($set = false;) ?>
<?php ($set = true); ?> <?php($set = false;)?>
<div><?php echo e($set); ?></div>
<?php
$set = false;
?>
<?php (
$set = false;
)?>
<?php(
$set = false;
)?>
<?php (
$set = false
); ?>
<?php (
$set = false
); ?>
<?php
$set = '@@php';
?>
PHP;
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testCompilationOfMixedPhpStatements()
{
$string = '@php($set = true) @php ($hello = \'hi\') @php echo "Hello world" @endphp';
$expected = '<?php ($set = true); ?> <?php ($hello = \'hi\'); ?> <?php echo "Hello world" ?>';

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testCompilationOfMixedUsageStatements()
{
$string = '@php (
$classes = [
\'admin-font-mono\', // Font weight
])
@endphp';
$expected = '<?php (
$classes = [
\'admin-font-mono\', // Font weight
])
?>';

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testMultilinePhpStatementsWithParenthesesCanBeCompiled()
{
$string = <<<'BLADE'
@php (
$classes = [
'admin-font-mono'
])
@endphp
<span class="{{ implode(' ', $classes) }}">Laravel</span>
BLADE;

$expected = <<<'PHP'
<?php (
$classes = [
'admin-font-mono'
])
?>
<span class="<?php echo e(implode(' ', $classes)); ?>">Laravel</span>
PHP;

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testMixedOfPhpStatementsCanBeCompiled()
{
$string = <<<'BLADE'
@php($total = 0)
{{-- ... --}}
<div>{{ $total }}</div>
@php
// ...
@endphp
BLADE;

$expected = <<<'PHP'
<?php ($total = 0); ?>
<div><?php echo e($total); ?></div>
<?php
// ...
?>
PHP;

$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testStringWithParenthesisWithEndPHP()
{
$string = "@php(\$data = ['related_to' => 'issue#45388'];) {{ \$data }} @endphp";
Expand Down

0 comments on commit c834505

Please sign in to comment.