◆ __construct()
array __construct |
( |
protected string |
$path | ) |
|
Constructor of TemplateFactory.
- Parameters
-
string | $path | the template include path |
◆ add_handler()
add_handler |
( |
string |
$extension, |
|
|
string |
$class, |
|
|
array |
$options = [] |
|
) |
| |
Registers a handler for templates with a matching extension.
- Parameters
-
string | $extension | the extension of the templates to handle |
| class-string<Template> | $class the name of the already loaded class |
array | $options | optional; an array of options which is used when constructing a new instance |
◆ find_template()
find_template |
( |
string |
$template | ) |
|
Find template given w/o extension.
- Parameters
-
string | $template | the template's filename w/o extension |
- Returns
- string|null null if there no such file could be found, a string containing the complete file name otherwise
◆ get_absolute_path()
get_absolute_path |
( |
string |
$template | ) |
|
Returns the absolute path to the template. If the given argument starts with a slash or with a protocoll, this method just returns its arguments.
- Parameters
-
string | $template | an incomplete template name |
- Returns
- string an absolute path to the incomplete template name
◆ get_extension()
get_extension |
( |
string |
$file | ) |
|
Returns the file extension if there is one.
- Parameters
-
string | $file | an possibly incomplete template file name |
- Returns
- string|null a string containing the file extension if there is one, NULL otherwise
◆ get_path()
Returns the include path of the factory
- Returns
- string the current include path
◆ get_template_file()
get_template_file |
( |
string |
$template0 | ) |
|
This method returns the absolute filename of the template
- Parameters
-
string | $template0 | a template string |
- Returns
- string an absolute filename
- Exceptions
-
◆ get_template_handler()
get_template_handler |
( |
string |
$template | ) |
|
Matches an extension to a template handler.
- Parameters
-
string | $template | the template |
- Returns
- array|null an array containing the class name and an array of options of the matched extension; or NULL if the extension did not match
◆ open()
Open a template of the given name using the factory method pattern. If a string was given, the path of the factory is searched for a matching template. If this string starts with a slash or with /+:\/\//, the string is interpreted as an absolute path. Otherwise the path of the factory will be prepended. After that the factory searches for a file extension in this string. If there is none, the directory where the template is supposed to live is searched for a file starting with the template string and a supported file extension. At last the factory instantiates a template object of the matching template class.
Examples:
$factory->open('/path/to/template') does not prepend the factory's path but searches for "template.*" in "/path/to"
$factory->open('template') prepends the factory's path and searches there for "template.*"
$factory->open('template.php') prepends the factory's path but does not search and instantiates a PHPTemplate instead
This method returns it's parameter, if it is not a string. This functionality is useful for helper methods like render_partial
- Parameters
-
Template | string | $template | A name of a template. |
- Returns
- Template the factored object
- Exceptions
-
◆ render()
render |
( |
Template|string |
$template, |
|
|
array |
$attributes = [] , |
|
|
Template|string|null |
$layout = null |
|
) |
| |
Class method to parse, render and return the presentation of a template.
- Parameters
-
Template | string | $template | A name of a template or a template |
array | $attributes | An associative array of attributes and their associated values. |
Template | string | null | $layout | A name of a layout template or a template. |
- Returns
- string A string representing the rendered presentation.
- Exceptions
-
◆ set_path()
Sets a new include path for the factory and returns the old one.
- Parameters
-
- Returns
- string the old path
◆ $handlers
Initial value:mapping of file extensions to supported template classes
The documentation for this class was generated from the following file: