2015-10-18 04:46:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-10-21 02:02:42 +02:00
|
|
|
* Inheritance Runtime Methods processBlock, endChild, init
|
2015-10-18 04:46:05 +02:00
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage PluginsInternal
|
|
|
|
* @author Uwe Tews
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
class Smarty_Internal_Runtime_Inheritance
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State machine
|
|
|
|
* - 0 idle next extends will create a new inheritance tree
|
|
|
|
* - 1 processing child template
|
|
|
|
* - 2 wait for next inheritance template
|
|
|
|
* - 3 assume parent template, if child will loaded goto state 1
|
|
|
|
* a call to a sub template resets the state to 0
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $state = 0;
|
|
|
|
|
|
|
|
/**
|
2015-12-27 04:02:21 +01:00
|
|
|
* Array of root child {block} objects
|
2015-10-18 04:46:05 +02:00
|
|
|
*
|
2015-12-27 04:02:21 +01:00
|
|
|
* @var Smarty_Internal_Block[]
|
2015-10-18 04:46:05 +02:00
|
|
|
*/
|
2015-12-27 04:02:21 +01:00
|
|
|
public $childRoot = array();
|
2015-10-18 04:46:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* inheritance template nesting level
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $inheritanceLevel = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* inheritance template index
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $tplIndex = - 1;
|
|
|
|
|
2016-01-27 04:51:02 +01:00
|
|
|
/**
|
|
|
|
* current block nesting level
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $blockNesting = 0;
|
|
|
|
|
2015-10-18 04:46:05 +02:00
|
|
|
/**
|
2015-12-27 04:02:21 +01:00
|
|
|
* Array of source template names
|
2015-10-18 04:46:05 +02:00
|
|
|
* - key template index
|
|
|
|
*
|
2015-12-27 04:02:21 +01:00
|
|
|
* @var string[]
|
2015-10-18 04:46:05 +02:00
|
|
|
*/
|
2015-12-27 04:02:21 +01:00
|
|
|
public $templateResource = array();
|
2015-10-18 04:46:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize 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())
|
|
|
|
{
|
2015-12-27 04:02:21 +01:00
|
|
|
// if called while executing parent template it must be a sub-template with new inheritance root
|
|
|
|
if ($initChild && $this->state == 3) {
|
2015-10-24 05:02:24 +02:00
|
|
|
$tpl->ext->_inheritance = new Smarty_Internal_Runtime_Inheritance();
|
|
|
|
$tpl->ext->_inheritance->init($tpl, $initChild, $blockNames);
|
2015-10-18 04:46:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// start of child sub template(s)
|
|
|
|
if ($initChild) {
|
|
|
|
$this->state = 1;
|
|
|
|
if (!$this->inheritanceLevel) {
|
|
|
|
//grab any output of child templates
|
|
|
|
ob_start();
|
|
|
|
}
|
|
|
|
$this->inheritanceLevel ++;
|
|
|
|
}
|
|
|
|
// in parent state {include} will not increment template index
|
|
|
|
if ($this->state != 3) {
|
|
|
|
$this->tplIndex ++;
|
2015-12-27 04:02:21 +01:00
|
|
|
$this->templateResource[ $this->tplIndex ] = $tpl->template_resource;
|
2015-10-18 04:46:05 +02:00
|
|
|
}
|
|
|
|
// if state was waiting for parent change state to parent
|
|
|
|
if ($this->state == 2) {
|
|
|
|
$this->state = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 template object of caller
|
|
|
|
*/
|
|
|
|
public function endChild(Smarty_Internal_Template $tpl)
|
|
|
|
{
|
|
|
|
$this->inheritanceLevel --;
|
|
|
|
if (!$this->inheritanceLevel) {
|
|
|
|
ob_end_clean();
|
|
|
|
$this->state = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|