diff options
author | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
commit | eab8a101e7a3fcbb41e01a574985e06c5a3775de (patch) | |
tree | 60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php | |
parent | 7f38be342c1495aeca418286c15c25c18ac9e142 (diff) |
Updating Smarty
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php')
-rw-r--r-- | lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php b/lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php index 36e8ab3..6392d4c 100644 --- a/lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php +++ b/lib/smarty3/sysplugins/smarty_internal_runtime_inheritance.php @@ -6,11 +6,9 @@ * @package Smarty * @subpackage PluginsInternal * @author Uwe Tews - * **/ class Smarty_Internal_Runtime_Inheritance { - /** * State machine * - 0 idle next extends will create a new inheritance tree @@ -42,11 +40,10 @@ class Smarty_Internal_Runtime_Inheritance * * @var int */ - public $tplIndex = - 1; + public $tplIndex = -1; /** * Array of template source objects - * - key template index * * @var Smarty_Template_Source[] */ @@ -65,19 +62,17 @@ class Smarty_Internal_Runtime_Inheritance * @param \Smarty_Internal_Template $tpl template object of caller * @param bool $initChild if true init for child template * @param array $blockNames outer level block name - * */ public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = array()) { // if called while executing parent template it must be a sub-template with new inheritance root - if ($initChild && $this->state == 3 && (strpos($tpl->template_resource, 'extendsall') === false)) { + if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) { $tpl->inheritance = new Smarty_Internal_Runtime_Inheritance(); $tpl->inheritance->init($tpl, $initChild, $blockNames); return; } - $this->tplIndex ++; + ++$this->tplIndex; $this->sources[ $this->tplIndex ] = $tpl->source; - // start of child sub template(s) if ($initChild) { $this->state = 1; @@ -85,12 +80,12 @@ class Smarty_Internal_Runtime_Inheritance //grab any output of child templates ob_start(); } - $this->inheritanceLevel ++; + ++$this->inheritanceLevel; // $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart'); // $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd'); } // if state was waiting for parent change state to parent - if ($this->state == 2) { + if ($this->state === 2) { $this->state = 3; } } @@ -99,33 +94,58 @@ class Smarty_Internal_Runtime_Inheritance * End of child template(s) * - if outer level is reached flush output buffer and switch to wait for parent template state * + * @param \Smarty_Internal_Template $tpl + * @param null|string $template optional name of inheritance parent template + * @param null|string $uid uid of inline template + * @param null|string $func function call name of inline template + * + * @throws \Exception + * @throws \SmartyException */ - public function endChild() + public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null) { - $this->inheritanceLevel --; + --$this->inheritanceLevel; if (!$this->inheritanceLevel) { ob_end_clean(); $this->state = 2; } + if (isset($template) && (($tpl->parent->_isTplObj() && $tpl->parent->source->type !== 'extends') + || $tpl->smarty->extends_recursion) + ) { + $tpl->_subTemplateRender( + $template, + $tpl->cache_id, + $tpl->compile_id, + $tpl->caching ? 9999 : 0, + $tpl->cache_lifetime, + array(), + 2, + false, + $uid, + $func + ); + } } /** * Smarty_Internal_Block constructor. - * - if outer level {block} of child template ($state == 1) save it as child root block + * - if outer level {block} of child template ($state === 1) save it as child root block * - otherwise process inheritance and render * * @param \Smarty_Internal_Template $tpl * @param $className * @param string $name * @param int|null $tplIndex index of outer level {block} if nested + * + * @throws \SmartyException */ public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null) { - $block = new $className($name, $tplIndex ? $tplIndex : $this->tplIndex); + $block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex); if (isset($this->childRoot[ $name ])) { $block->child = $this->childRoot[ $name ]; } - if ($this->state == 1) { + if ($this->state === 1) { $this->childRoot[ $name ] = $block; return; } @@ -145,9 +165,11 @@ class Smarty_Internal_Runtime_Inheritance * * @throws \SmartyException */ - public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, - Smarty_Internal_Block $parent = null) - { + public function process( + Smarty_Internal_Template $tpl, + Smarty_Internal_Block $block, + Smarty_Internal_Block $parent = null + ) { if ($block->hide && !isset($block->child)) { return; } @@ -156,7 +178,7 @@ class Smarty_Internal_Runtime_Inheritance } $block->parent = $parent; if ($block->append && !$block->prepend && isset($parent)) { - $this->callParent($tpl, $block); + $this->callParent($tpl, $block, '\'{block append}\''); } if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) { $this->callBlock($block, $tpl); @@ -164,10 +186,10 @@ class Smarty_Internal_Runtime_Inheritance $this->process($tpl, $block->child, $block); } if ($block->prepend && isset($parent)) { - $this->callParent($tpl, $block); + $this->callParent($tpl, $block, '{block prepend}'); if ($block->append) { - if ($block->callsChild || !isset($block->child) || - ($block->child->hide && !isset($block->child->child)) + if ($block->callsChild || !isset($block->child) + || ($block->child->hide && !isset($block->child->child)) ) { $this->callBlock($block, $tpl); } else { @@ -179,10 +201,13 @@ class Smarty_Internal_Runtime_Inheritance } /** - * Render child on {$smarty.block.child} + * Render child on \$smarty.block.child * * @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Block $block + * + * @return null|string block content + * @throws \SmartyException */ public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block) { @@ -192,23 +217,27 @@ class Smarty_Internal_Runtime_Inheritance } /** - * Render parent on {$smarty.block.parent} or {block append/prepend} * + * Render parent block on \$smarty.block.parent or {block append/prepend} * * @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Block $block + * @param string $tag * + * @return null|string block content * @throws \SmartyException */ - public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block) + public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $tag) { if (isset($block->parent)) { $this->callBlock($block->parent, $tpl); } else { - throw new SmartyException("inheritance: illegal {\$smarty.block.parent} or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); + throw new SmartyException("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); } } /** + * render block + * * @param \Smarty_Internal_Block $block * @param \Smarty_Internal_Template $tpl */ |