Class TTemplate
TTemplate implements PRADO template parsing logic.
A TTemplate object represents a parsed PRADO control template. It can instantiate the template as child controls of a specified control. The template format is like HTML, with the following special tags introduced, - component tags: a component tag represents the configuration of a component.
The tag name is in the format of com:ComponentType, where ComponentType is the component class name. Component tags must be well-formed. Attributes of the component tag are treated as either property initial values, event handler attachment, or regular tag attributes. - property tags: property tags are used to set large block of attribute values.
The property tag name is in the format of <prop:AttributeName> where AttributeName can be a property name, an event name or a regular tag attribute name. - group subproperty tags: subproperties of a common property can be configured using
<prop:MainProperty SubProperty1="Value1" SubProperty2="Value2" .../> - directive: directive specifies the property values for the template owner.
It is in the format of <%@ property name-value pairs %>; - expressions: They are in the formate of <%= PHP expression %> and <%% PHP statements %>
- comments: There are two kinds of comments, regular HTML comments and special template comments.
The former is in the format of <!-- comments -->, which will be treated as text strings. The latter is in the format of <!-- comments --!>, which will be stripped out. Tags other than the above are not required to be well-formed. A TTemplate object represents a parsed PRADO template. To instantiate the template for a particular control, call instantiateIn($control), which will create and intialize all components specified in the template and set their parent as $control.
| Constructor Summary |
| public |
Constructor.
|
| Method Summary |
|
protected
void
|
Configures a property of a non-control component.
|
|
protected
void
|
Configures a property/event of a control.
|
|
protected
void
|
Configures an event for a control.
|
|
protected
void
|
Configures a simple property for a component.
|
|
protected
void
|
Configures a subproperty for a component.
|
|
string
|
|
|
array
|
|
|
string
|
|
|
array
|
|
|
boolean
|
|
|
array
|
|
|
string
|
|
|
protected
void
|
Handles template parsing exception.
|
|
void
|
Instantiates the template.
|
|
protected
void
|
Parses a template string.
|
|
protected
array
|
Parses a single attribute.
|
|
protected
array
|
Parses the attributes of a tag from a string.
|
|
protected
void
|
|
|
protected
string
|
Preprocesses the template string by including external templates
|
|
protected
void
|
|
| Methods Inherited From TComponent |
|
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
| Constant Summary |
| int
|
CONFIG_ASSET |
|
| int
|
CONFIG_DATABIND |
Different configurations of component property/event/attribute
|
| int
|
CONFIG_EXPRESSION |
|
| int
|
CONFIG_LOCALIZATION |
|
| int
|
CONFIG_PARAMETER |
|
| int
|
CONFIG_TEMPLATE |
|
| string
|
REGEX_RULES |
'<!--.*?--!>' - template comments
'<!--.*?-->' - HTML comments '<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>' - component tags '<\/?prop:([\w\.]+)\s*>' - property tags '<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>' - directives '<%[%#~\/\\$=\\[](.*?)%>' - expressions '<prop:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/>' - group subproperty tags
|
| Constructor Details |
__construct
Constructor.
The template will be parsed after construction.
|
| Method Details |
configureComponent
| protected void configureComponent |
(TComponent $component , string $name , mixed $value ) |
Configures a property of a non-control component.
| Input |
| TComponent | $component | component to be configured |
| string | $name | property name |
| mixed | $value | property initial value |
| Output |
| Exception |
|
configureControl
| protected void configureControl |
(TControl $control , string $name , mixed $value ) |
Configures a property/event of a control.
| Input |
| TControl | $control | control to be configured |
| string | $name | property name |
| mixed | $value | property initial value |
| Output |
| Exception |
|
configureEvent
| protected void configureEvent |
(TControl $control , string $name , string $value , TControl $contextControl ) |
Configures an event for a control.
| Input |
| TControl | $control | control to be configured |
| string | $name | event name |
| string | $value | event handler |
| TControl | $contextControl | context control |
| Output |
| Exception |
|
configureProperty
| protected void configureProperty |
(TComponent $component , string $name , mixed $value ) |
Configures a simple property for a component.
| Input |
| TComponent | $component | component to be configured |
| string | $name | property name |
| mixed | $value | property initial value |
| Output |
| Exception |
|
configureSubProperty
| protected void configureSubProperty |
(TComponent $component , string $name , mixed $value ) |
Configures a subproperty for a component.
| Input |
| TComponent | $component | component to be configured |
| string | $name | subproperty name |
| mixed | $value | subproperty initial value |
| Output |
| Exception |
|
getContextPath
| public string getContextPath |
() |
| Output |
|
string
| context directory path |
| Exception |
|
getDirective
| public array getDirective |
() |
| Output |
|
array
| name-value pairs declared in the directive |
| Exception |
|
getHashCode
| public string getHashCode |
() |
| Output |
|
string
| hash code that can be used to identify the template |
| Exception |
|
getIncludedFiles
| public array getIncludedFiles |
() |
| Output |
|
array
| list of included external template files |
| Exception |
|
getIsSourceTemplate
| public boolean getIsSourceTemplate |
() |
| Output |
|
boolean
| whether this template is a source template, i.e., this template is loaded from some external storage rather than from within another template. |
| Exception |
|
getItems
| Output |
|
array
| the parsed template |
| Exception |
|
getTemplateFile
| public string getTemplateFile |
() |
| Output |
|
string
| template file path if available, null otherwise. |
| Exception |
|
handleException
| protected void handleException |
(Exception $e , int $line , string $input ) |
Handles template parsing exception.
This method rethrows the exception caught during template parsing. It adjusts the error location by giving out correct error line number and source file.
| Input |
| Exception | $e | template exception |
| int | $line | line number |
| string | $input | template string if no source file is used |
| Output |
| Exception |
|
instantiateIn
Instantiates the template.
Content in the template will be instantiated as components and text strings and passed to the specified parent control.
| Input |
| TControl | $tplControl | the control who owns the template |
| TControl | $parentControl | the control who will become the root parent of the controls on the template. If null, it uses the template control. |
| Output |
| Exception |
|
parse
| protected void parse |
(string $input ) |
Parses a template string.
This template parser recognizes five types of data: regular string, well-formed component tags, well-formed property tags, directives, and expressions. The parsing result is returned as an array. Each array element can be of three types: - a string, 0: container index; 1: string content;
- a component tag, 0: container index; 1: component type; 2: attributes (name=>value pairs)
If a directive is found in the template, it will be parsed and can be retrieved via getDirective, which returns an array consisting of name-value pairs in the directive.Note, attribute names are treated as case-insensitive and will be turned into lower cases. Component and directive types are case-sensitive. Container index is the index to the array element that stores the container object. If an object has no container, its container index is -1.
| Input |
| string | $input | the template string |
| Output |
| Exception |
| throws | TConfigurationException if a parsing error is encountered |
|
parseAttribute
| protected array parseAttribute |
(string $value ) |
Parses a single attribute.
| Input |
| string | $value | the string to be parsed. |
| Output |
|
array
| attribute initialization |
| Exception |
|
parseAttributes
| protected array parseAttributes |
(string $str , mixed $offset ) |
Parses the attributes of a tag from a string.
| Input |
| string | $str | the string to be parsed. |
| mixed | $offset | |
| Output |
|
array
| attribute values indexed by names. |
| Exception |
|
parseTemplateProperty
| protected void parseTemplateProperty |
(mixed $content , mixed $offset ) |
| Input |
| mixed | $content | |
| mixed | $offset | |
| Output |
| Exception |
|
preprocess
| protected string preprocess |
(string $input ) |
Preprocesses the template string by including external templates
| Input |
| string | $input | template string |
| Output |
|
string
| expanded template string |
| Exception |
|
validateAttributes
| protected void validateAttributes |
(mixed $type , mixed $attributes ) |
| Input |
| mixed | $type | |
| mixed | $attributes | |
| Output |
| Exception |
|
| Constant Details |
CONFIG_ASSET
|
CONFIG_DATABIND
Different configurations of component property/event/attribute
|
CONFIG_EXPRESSION
|
CONFIG_LOCALIZATION
|
CONFIG_PARAMETER
|
CONFIG_TEMPLATE
|
REGEX_RULES
'<!--.*?--!>' - template comments
'<!--.*?-->' - HTML comments '<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>' - component tags '<\/?prop:([\w\.]+)\s*>' - property tags '<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>' - directives '<%[%#~\/\\$=\\[](.*?)%>' - expressions '<prop:([\w\.]+)((?:\s*[\w\.]+=\'.*?\'|\s*[\w\.]+=".*?"|\s*[\w\.]+=<%.*?%>)*)\s*\/>' - group subproperty tags
Type:
string
Value:
'/<!--.*?--!>|<!---.*?--->|<\/?com:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/?>|<\/?prop:([\w\.]+)\s*>|<%@\s*((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?")*)\s*%>|<%[%#~\/\\$=\\[](.*?)%>|<prop:([\w\.]+)((?:\s*[\w\.]+\s*=\s*\'.*?\'|\s*[\w\.]+\s*=\s*".*?"|\s*[\w\.]+\s*=\s*<%.*?%>)*)\s*\/>/msS'
|
|