Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BladeCompiler extends Compiler implements CompilerInterface {
*
* @var array
*/
protected $extensions = array();
protected $extensions = [];

/**
* The file currently being compiled.
Expand All @@ -23,33 +23,33 @@ class BladeCompiler extends Compiler implements CompilerInterface {
*
* @var array
*/
protected $compilers = array(
protected $compilers = [
'Extensions',
'Statements',
'Comments',
'Echos'
);
];

/**
* Array of opening and closing tags for raw echos.
*
* @var array
*/
protected $rawTags = array('{!!', '!!}');
protected $rawTags = ['{!!', '!!}'];

/**
* Array of opening and closing tags for regular echos.
*
* @var array
*/
protected $contentTags = array('{{', '}}');
protected $contentTags = ['{{', '}}'];

/**
* Array of opening and closing tags for escaped echos.
*
* @var array
*/
protected $escapedTags = array('{{{', '}}}');
protected $escapedTags = ['{{{', '}}}'];

/**
* The "regular" / legacy echo string format.
Expand All @@ -63,7 +63,7 @@ class BladeCompiler extends Compiler implements CompilerInterface {
*
* @var array
*/
protected $footer = array();
protected $footer = [];

/**
* Counter to keep track of nested forelse statements.
Expand All @@ -80,7 +80,7 @@ class BladeCompiler extends Compiler implements CompilerInterface {
*/
public function compile($path = null)
{
$this->footer = array();
$this->footer = [];

if ($path)
{
Expand Down Expand Up @@ -191,7 +191,7 @@ protected function compileExtensions($value)
*/
protected function compileComments($value)
{
$pattern = sprintf('/%s--((.|\s)*?)--%s/', $this->contentTags[0], $this->contentTags[1]);
$pattern = "/{$this->contentTags[0]}--((.|\s)*?)--{$this->contentTags[1]}/";

return preg_replace($pattern, '<?php /*$1*/ ?>', $value);
}
Expand Down Expand Up @@ -271,13 +271,13 @@ protected function compileStatements($value)
*/
protected function compileRawEchos($value)
{
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->rawTags[0], $this->rawTags[1]);
$pattern = "/(@)?{$this->rawTags[0]}\s*(.+?)\s*{$this->rawTags[1]}(\r?\n)?/s";

$callback = function($matches)
{
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];

return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$this->compileEchoDefaults($matches[2]).'; ?>'.$whitespace;
return $matches[1] ? substr($matches[0], 1) : '<?= '.$this->compileEchoDefaults($matches[2]).'; ?>'.$whitespace;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crynobone PHP5.4+ has <?= short tag enabled by default. And Laravel requires 5.4+, so why not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And everyone is forced to have short_open_tag as on?

I still don't see it really add any benefit, unless this changes gain some huge performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're wrong. <?= is not even considered as a short tag anymore, and is not affected by short_open_tag. See http://svn.php.net/viewvc?view=revision&revision=311260, from Rasmus Lerdorf himself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see it really add any benefit, unless this changes gain some huge performance.

Well, just as [] is not of any more benefits than array(). But Laravel has always been a modern framework, it should adapt the latest techniques whenever it can. I see quite a portion of L5 switched to [] instead of array(), ?: instead of ? $var : $val, so again, why not?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the use of non-conventional tags.

};

return preg_replace_callback($pattern, $callback, $value);
Expand All @@ -291,15 +291,15 @@ protected function compileRawEchos($value)
*/
protected function compileRegularEchos($value)
{
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->contentTags[0], $this->contentTags[1]);
$pattern = "/(@)?{$this->contentTags[0]}\s*(.+?)\s*{$this->contentTags[1]}(\r?\n)?/s";

$callback = function($matches)
{
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];

$wrapped = sprintf($this->echoFormat, $this->compileEchoDefaults($matches[2]));

return $matches[1] ? substr($matches[0], 1) : '<?php echo '.$wrapped.'; ?>'.$whitespace;
return $matches[1] ? substr($matches[0], 1) : '<?= '.$wrapped.'; ?>'.$whitespace;
};

return preg_replace_callback($pattern, $callback, $value);
Expand All @@ -313,13 +313,13 @@ protected function compileRegularEchos($value)
*/
protected function compileEscapedEchos($value)
{
$pattern = sprintf('/%s\s*(.+?)\s*%s(\r?\n)?/s', $this->escapedTags[0], $this->escapedTags[1]);
$pattern = "/{$this->escapedTags[0]}\s*(.+?)\s*{$this->escapedTags[1]}(\r?\n)?/s";

$callback = function($matches)
{
$whitespace = empty($matches[2]) ? '' : $matches[2].$matches[2];

return '<?php echo e('.$this->compileEchoDefaults($matches[1]).'); ?>'.$whitespace;
return '<?= e('.$this->compileEchoDefaults($matches[1]).'); ?>'.$whitespace;
};

return preg_replace_callback($pattern, $callback, $value);
Expand All @@ -344,7 +344,7 @@ public function compileEchoDefaults($value)
*/
protected function compileEach($expression)
{
return "<?php echo \$__env->renderEach{$expression}; ?>";
return "<?= \$__env->renderEach{$expression}; ?>";
}

/**
Expand All @@ -357,7 +357,7 @@ protected function compileInject($expression)
{
$segments = explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression));

return "<?php $".trim($segments[0])." = app('".trim($segments[1])."'); ?>";
return '<?php $'.trim($segments[0])." = app('".trim($segments[1])."'); ?>";
}

/**
Expand All @@ -368,7 +368,7 @@ protected function compileInject($expression)
*/
protected function compileYield($expression)
{
return "<?php echo \$__env->yieldContent{$expression}; ?>";
return "<?= \$__env->yieldContent{$expression}; ?>";
}

/**
Expand All @@ -379,7 +379,7 @@ protected function compileYield($expression)
*/
protected function compileShow($expression)
{
return "<?php echo \$__env->yieldSection(); ?>";
return "<?= \$__env->yieldSection(); ?>";
}

/**
Expand Down Expand Up @@ -456,7 +456,7 @@ protected function compileUnless($expression)
*/
protected function compileEndunless($expression)
{
return "<?php endif; ?>";
return '<?php endif; ?>';
}

/**
Expand All @@ -467,7 +467,7 @@ protected function compileEndunless($expression)
*/
protected function compileLang($expression)
{
return "<?php echo \\Illuminate\\Support\\Facades\\Lang::get$expression; ?>";
return "<?= \\Illuminate\\Support\\Facades\\Lang::get$expression; ?>";
}

/**
Expand All @@ -478,7 +478,7 @@ protected function compileLang($expression)
*/
protected function compileChoice($expression)
{
return "<?php echo \\Illuminate\\Support\\Facades\\Lang::choice$expression; ?>";
return "<?= \\Illuminate\\Support\\Facades\\Lang::choice$expression; ?>";
}

/**
Expand All @@ -489,7 +489,7 @@ protected function compileChoice($expression)
*/
protected function compileElse($expression)
{
return "<?php else: ?>";
return '<?php else: ?>';
}

/**
Expand Down Expand Up @@ -524,7 +524,7 @@ protected function compileForelse($expression)
{
$empty = '$__empty_' . ++$this->forelseCounter;

return "<?php {$empty} = true; foreach{$expression}: {$empty} = false; ?>";
return "<?php $empty = true; foreach{$expression}: $empty = false; ?>";
}

/**
Expand Down Expand Up @@ -559,7 +559,7 @@ protected function compileEmpty($expression)
{
$empty = '$__empty_' . $this->forelseCounter--;

return "<?php endforeach; if ({$empty}): ?>";
return "<?php endforeach; if ($empty): ?>";
}

/**
Expand All @@ -581,7 +581,7 @@ protected function compileWhile($expression)
*/
protected function compileEndwhile($expression)
{
return "<?php endwhile; ?>";
return '<?php endwhile; ?>';
}

/**
Expand All @@ -592,7 +592,7 @@ protected function compileEndwhile($expression)
*/
protected function compileEndfor($expression)
{
return "<?php endfor; ?>";
return '<?php endfor; ?>';
}

/**
Expand All @@ -603,7 +603,7 @@ protected function compileEndfor($expression)
*/
protected function compileEndforeach($expression)
{
return "<?php endforeach; ?>";
return '<?php endforeach; ?>';
}

/**
Expand All @@ -614,7 +614,7 @@ protected function compileEndforeach($expression)
*/
protected function compileEndif($expression)
{
return "<?php endif; ?>";
return '<?php endif; ?>';
}

/**
Expand All @@ -625,7 +625,7 @@ protected function compileEndif($expression)
*/
protected function compileEndforelse($expression)
{
return "<?php endif; ?>";
return '<?php endif; ?>';
}

/**
Expand All @@ -641,7 +641,7 @@ protected function compileExtends($expression)
$expression = substr($expression, 1, -1);
}

$data = "<?php echo \$__env->make($expression, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
$data = "<?= \$__env->make($expression, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";

$this->footer[] = $data;

Expand All @@ -661,7 +661,7 @@ protected function compileInclude($expression)
$expression = substr($expression, 1, -1);
}

return "<?php echo \$__env->make($expression, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
return "<?= \$__env->make($expression, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
}

/**
Expand All @@ -672,7 +672,7 @@ protected function compileInclude($expression)
*/
protected function compileStack($expression)
{
return "<?php echo \$__env->yieldContent{$expression}; ?>";
return "<?= \$__env->yieldContent{$expression}; ?>";
}

/**
Expand Down Expand Up @@ -716,7 +716,7 @@ public function extend(callable $compiler)
*/
public function createMatcher($function)
{
return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*\))/';
return "/(?<!\w)(\s*)@$function(\s*\(.*\))/";
}

/**
Expand All @@ -727,7 +727,7 @@ public function createMatcher($function)
*/
public function createOpenMatcher($function)
{
return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*)\)/';
return "/(?<!\w)(\s*)@$function(\s*\(.*)\)/";
}

/**
Expand All @@ -738,7 +738,7 @@ public function createOpenMatcher($function)
*/
public function createPlainMatcher($function)
{
return '/(?<!\w)(\s*)@'.$function.'(\s*)/';
return "/(?<!\w)(\s*)@$function(\s*)/";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Engines/CompilerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CompilerEngine extends PhpEngine {
*
* @var array
*/
protected $lastCompiled = array();
protected $lastCompiled = [];

/**
* Create a new Blade view engine instance.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/View/Engines/EngineResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class EngineResolver {
*
* @var array
*/
protected $resolvers = array();
protected $resolvers = [];

/**
* The resolved engine instances.
*
* @var array
*/
protected $resolved = array();
protected $resolved = [];

/**
* Register a new engine resolver.
Expand Down
Loading