Box\Brainy\Templates\TemplateBase::__construct PHP Method

__construct() public method

public __construct ( Box\Brainy\Brainy $brainyInstance, boolean | void $useRootScope = false )
$brainyInstance Box\Brainy\Brainy
$useRootScope boolean | void Whether to clone data from the root scope
    public function __construct(Brainy $brainyInstance, $useRootScope = false)
    {
        $this->smarty =& $brainyInstance;
        if ($useRootScope || Brainy::$default_assign_scope === Brainy::SCOPE_ROOT) {
            $this->tpl_vars =& $brainyInstance->tpl_vars;
        } else {
            $this->cloneDataFrom($brainyInstance);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Create template data object
  *
  * Some of the global Smarty settings copied to template scope
  * It load the required template resources and cacher plugins
  *
  * @param string    $tplResource  template resource string
  * @param Brainy    $brainy       Brainy instance
  * @param Template  $parent       back pointer to parent object with variables or null
  * @param mixed     $compileID    compile id or null
  * @param bool|void $suppressData Prevents data from being copied into the variable scope
  */
 public function __construct($tplResource, $brainy, $parent = null, $compileID = null, $suppressData = false)
 {
     if ($parent === null || !$suppressData) {
         parent::__construct($brainy);
     } else {
         // Copied from the TemplateBase constructor
         $this->smarty = $brainy;
     }
     $this->compile_id = $compileID ?: $this->smarty->compile_id;
     $this->parent = $parent;
     // Template resource
     $this->template_resource = $tplResource;
     $this->smarty->fetchedTemplate($tplResource);
     $this->source = \Box\Brainy\Resources\Resource::source($this, $brainy, $this->template_resource);
     $this->compiled = $this->source->getCompiled($this);
     if (!$suppressData && $this->parent) {
         if (is_array($this->parent)) {
             $this->applyDataFrom($this->parent, false);
         } else {
             $this->cloneDataFrom($this->parent, false);
         }
     }
 }