-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- compile {block} tag code and its processing into classes
- Loading branch information
Showing
6 changed files
with
203 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
/** | ||
* Smarty {block} tag class | ||
* | ||
* @package Smarty | ||
* @subpackage PluginsInternal | ||
* @author Uwe Tews | ||
*/ | ||
class Smarty_Internal_Block | ||
{ | ||
/** | ||
* Block name | ||
* | ||
* @var string | ||
*/ | ||
public $name = ''; | ||
|
||
/** | ||
* Hide attribute | ||
* | ||
* @var bool | ||
*/ | ||
public $hide = false; | ||
|
||
/** | ||
* Append attribute | ||
* | ||
* @var bool | ||
*/ | ||
public $append = false; | ||
|
||
/** | ||
* prepend attribute | ||
* | ||
* @var bool | ||
*/ | ||
public $prepend = false; | ||
|
||
/** | ||
* Block calls {$smarty.block.child} | ||
* | ||
* @var bool | ||
*/ | ||
public $callsChild = false; | ||
|
||
/** | ||
* Inheritance child block | ||
* | ||
* @var Smarty_Internal_Block|null | ||
*/ | ||
public $child = null; | ||
|
||
/** | ||
* Inheritance calling parent block | ||
* | ||
* @var Smarty_Internal_Block|null | ||
*/ | ||
public $parent = null; | ||
|
||
/** | ||
* Inheritance Template index | ||
* | ||
* @var int | ||
*/ | ||
public $tplIndex = 0; | ||
|
||
/** | ||
* Smarty_Internal_Block constructor. | ||
* | ||
* @param \Smarty_Internal_Template $_smarty_tpl | ||
* | ||
*/ | ||
public function __construct(Smarty_Internal_Template $_smarty_tpl) | ||
{ | ||
$this->tplIndex = $_smarty_tpl->ext->_inheritance->tplIndex; | ||
if (isset($_smarty_tpl->ext->_inheritance->blockParameter[ $this->name ])) { | ||
$this->child = $_smarty_tpl->ext->_inheritance->blockParameter[ $this->name ]; | ||
} | ||
if ($_smarty_tpl->ext->_inheritance->state == 1) { | ||
$_smarty_tpl->ext->_inheritance->blockParameter[ $this->name ] = $this; | ||
return; | ||
} | ||
$this->process($_smarty_tpl); | ||
} | ||
|
||
/** | ||
* Goto child block or render this | ||
* | ||
* @param \Smarty_Internal_Template $_smarty_tpl | ||
* @param \Smarty_Internal_Block|null $parent | ||
*/ | ||
public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Internal_Block $parent = null) { | ||
if ($this->hide && !isset($this->child)) { | ||
return; | ||
} | ||
if (isset($this->child) && $this->child->hide && !isset($this->child->child)) { | ||
$this->child = null; | ||
} | ||
$this->parent = $parent; | ||
if ($this->append && !$this->prepend && isset($parent)) { | ||
$this->callParent($_smarty_tpl); | ||
} | ||
if ($this->callsChild || !isset($this->child) || ($this->child->hide && !isset($this->child->child))) { | ||
$this->callBlock($_smarty_tpl); | ||
} else { | ||
$this->child->process($_smarty_tpl, $this); | ||
} | ||
if ($this->prepend && isset($parent)) { | ||
$this->callParent($_smarty_tpl); | ||
if ($this->append) { | ||
if ($this->callsChild || !isset($this->child) || ($this->child->hide && !isset($this->child->child))) { | ||
$this->callBlock($_smarty_tpl); | ||
} else { | ||
$this->child->process($_smarty_tpl, $this); | ||
} | ||
} | ||
} | ||
$this->parent = null; | ||
} | ||
|
||
/** | ||
* Compiled block code overloaded by {block} class | ||
* | ||
* @param \Smarty_Internal_Template $_smarty_tpl | ||
*/ | ||
public function callBlock(Smarty_Internal_Template $_smarty_tpl) { | ||
} | ||
|
||
/** | ||
* Render child on {$smarty.block.child} | ||
* | ||
* @param \Smarty_Internal_Template $_smarty_tpl | ||
*/ | ||
public function callChild (Smarty_Internal_Template $_smarty_tpl) { | ||
if (isset($this->child)) { | ||
$this->child->process($_smarty_tpl, $this); | ||
} | ||
} | ||
|
||
/** | ||
* Render parent on {$smarty.block.parent} or {block append/prepend} * | ||
* | ||
* @param \Smarty_Internal_Template $_smarty_tpl | ||
* | ||
* @throws \SmartyException | ||
*/ | ||
public function callParent (Smarty_Internal_Template $_smarty_tpl) { | ||
if (isset($this->parent)) { | ||
$this->parent->callBlock($_smarty_tpl, $this->parent->parent); | ||
} else { | ||
throw new SmartyException("inheritance: illegal {\$smarty.block.parent} or {block append/prepend} used in parent template '{$_smarty_tpl->ext->_inheritance->compiledFilePath[$this->tplIndex]}' block '{$this->name}'"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
For a
string
resource type, the$compiler->template->source->name
contains the entire template contents, which can lead to parse errors and other problems. I've submitted an issue, see #157.