Skip to content

Commit

Permalink
Template: blocks initialization moved to BlockMacrosRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 28, 2016
1 parent 273a3f8 commit 87a79a9
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Latte/Macros/BlockMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function finalize()
}
$compiler->addProperty('blocks', array_merge_recursive($functions, $this->blockTypes));

$prolog = 'Latte\Macros\BlockMacrosRuntime::initialize($this)';
$prolog = 'Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)';
if (!$this->namedBlocks) {
$epilog = 'if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return;';
}
Expand Down
7 changes: 6 additions & 1 deletion src/Latte/Macros/BlockMacrosRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ class BlockMacrosRuntime
/**
* @return void
*/
public static function initialize(Latte\Template $template)
public static function initialize(Latte\Template $template, \stdClass $blocks)
{
foreach ($template->blocks as $name => $info) {
$blocks->blocks[$name][] = [$template, $info[0]];
self::checkType($info[1], $blocks->types, $name);
}

if ($template->params['_l']->extends = $template->getExtends()) {
ob_start(function () {});
}
Expand Down
7 changes: 0 additions & 7 deletions src/Latte/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class Template
/** @var Filters */
protected $filters;

/** @var array */
protected $blocks = [];


public function __construct(Engine $engine, Filters $filters, $name)
{
Expand Down Expand Up @@ -77,10 +74,6 @@ public function initialize($contentType)
} else {
$block = new \stdClass;
}
foreach ($this->blocks as $name => $info) {
$block->blocks[$name][] = [$this, $info[0]];
Macros\BlockMacrosRuntime::checkType($info[1], $block->types, $name);
}

// global storage
if (!isset($this->params['_g'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.defineblock.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.dynamicblock.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
$var = 10 ?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.general.html.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Template%a% extends Latte\Template
list($_b, $_g, $_l) = $this->initialize('html')
;
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.general.xhtml.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Template%a% extends Latte\Template
list($_b, $_g, $_l) = $this->initialize('xhtml')
;
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.includeblock.inc.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return;
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.inheritance.child1.child.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template ?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Template%a% extends Latte\Template
list($_b, $_g, $_l) = $this->initialize('html')
;
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template
extract(['class' => NULL, 'namespace' => NULL, 'top' => TRUE], EXTR_SKIP) ?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.inheritance.child2.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template ?>

Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.inheritance.child5.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template ?>

Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.inheritance.child6.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Template%a% extends Latte\Template
{
%A%
// prolog Latte\Macros\BlockMacros
Latte\Macros\BlockMacrosRuntime::initialize($this)
Latte\Macros\BlockMacrosRuntime::initialize($this, $_b)
;
// main template ?>
This should be erased
Expand Down

0 comments on commit 87a79a9

Please sign in to comment.