4 * TTemplateControlInheritable class file.
6 * @author Schlaue-Kids.net <info@schlaue-kids.net>
7 * @link http://www.schlaue-kids.net/
8 * @copyright Copyright © 2010 Schlaue-Kids.net
9 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
11 * @package System.Web.UI
14 Prado::using('System.Web.UI.TTemplateControl');
17 * TTemplateControlInheritable class.
18 * TTemplateControlInheritable is an extension to the base class for all controls that use templates.
19 * By default, a control template is assumed to be in a file under the same
20 * directory with the control class file. They have the same file name and
21 * different extension name. For template file, the extension name is ".tpl".
22 * If a TTemplateControlInheritable is inherited it uses the base class template unless the
23 * inheriting control defines an own.
25 * @author Schlaue-Kids.net <info@schlaue-kids.net>
28 * @package System.Web.UI
31 class TTemplateControlInheritable extends TTemplateControl
36 * Creates child controls.
37 * This method is overridden to load and instantiate control template.
38 * This method should only be used by framework and control developers.
39 * Uses the controls template if available or the base class template otherwise.
42 * @throws TConfigurationException if a template control directive is invalid
44 public function createChildControls()
46 if(null === ($_template = $this->getTemplate())) {
47 return $this->doCreateChildControlsFor(get_class($this));
50 foreach($_template->getDirective() as $_name => $_value) {
51 if(!is_string($_value)) {
52 throw new TConfigurationException('templatecontrol_directive_invalid', get_class($this), $name);
55 $this->setSubProperty($_name, $_value);
58 $_template->instantiateIn($this);
62 * This method creates the cild controls for the given class
64 * @param string $parentClass The class to generate the child controls for
67 public function doCreateChildControlsFor($parentClass)
69 if(false !== ($_parentClass = get_parent_class($parentClass)) && 'TTemplateControl' != $_parentClass) {
70 $this->doCreateChildControlsFor($_parentClass);
73 $this->doTemplateForClass($parentClass);
77 * This method creates the template object for the given class
79 * @param string $p_class The class to create the template from
81 * @throws TConfigurationException if a template control directive is invalid
83 public function doTemplateForClass($parentClass)
85 if(null !== ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName($parentClass))) {
86 foreach($_template->getDirective() as $_name => $_value) {
87 if(!is_string($_value)) {
88 throw new TConfigurationException('templatecontrol_directive_invalid', get_class(this), $_name);
91 $this->setSubProperty($_name, $_value);
94 $_template->instantiateIn($this);
101 * A source template control loads its template from external storage,
102 * such as file, db, rather than from within another template.
104 * @return boolean whether the current control is a source template control
106 public function getIsSourceTemplateControl()
108 if(null !== ($_template = $this->getTemplate())) {
109 return $_template->getIsSourceTemplate();
112 return ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName(get_parent_class($this)))
113 ? $_template->getIsSourceTemplate()