PhpTemplate
extends Template
in package
Template class
Table of Contents
Constants
- Dummy = 'dummy'
Properties
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Magic getter method
- Create() : Template
- Static constructor
- DispatchEvent() : object|null
- Dispatches an event.
- HandleEvent() : self
- Adds an event handler.
- Insert() : string
- Runs code in a dummy template.
- RemoveHandler() : self
- Removes an event handler.
- Render() : string
- Renders the template.
- RenderCode() : mixed
- Renders code in the template.
- Run() : string
- Runs template based on the current template's directory path.
Constants
Dummy
public
mixed
Dummy
= 'dummy'
Properties
$file read-only
public
string
$file
The file path of the template.
$path read-only
public
string
$path
The directory path of the template.
$_file
The path to the template file.
protected
string
$_file
Methods
__construct()
Constructor
public
__construct(mixed $file) : mixed
Initializes a new instance of the PhpTemplate class.
Parameters
- $file : mixed
-
The template file.
__get()
Magic getter method
public
__get(string $prop) : mixed
Retrieves the value of a property.
Parameters
- $prop : string
-
The property name.
Tags
Return values
mixed —The value of the property.
Create()
Static constructor
public
static Create(mixed $file) : Template
Creates a new instance of the Template class.
Parameters
- $file : mixed
-
The template file.
Return values
Template —The created template instance.
DispatchEvent()
Dispatches an event.
public
DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
- $event : string|Event
-
The event object or its name.
- $args : mixed = null
-
Additional arguments to pass to the event handlers.
- $async : bool = false
-
Whether to dispatch the event asynchronously.
Return values
object|null —The event object with updated arguments, or null if the event does not exist.
HandleEvent()
Adds an event handler.
public
HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
- $ename : array<string|int, mixed>|string
-
The event name or an array of event names.
- $listener : mixed
-
The event handler.
Return values
selfInsert()
Runs code in a dummy template.
public
Insert(string $file[, mixed $args = [] ]) : string
Parameters
- $file : string
- $args : mixed = []
-
The arguments for the code.
Return values
string —The rendered output.
RemoveHandler()
Removes an event handler.
public
RemoveHandler(string $ename, mixed $listener) : self
Parameters
- $ename : string
-
The event name.
- $listener : mixed
-
The event handler to remove.
Return values
selfRender()
Renders the template.
public
Render([mixed $args = null ]) : string
Parameters
- $args : mixed = null
-
Additional arguments for rendering.
Tags
Return values
string —The rendered output.
RenderCode()
Renders code in the template.
public
RenderCode(string $code, mixed $args) : mixed
Parameters
- $code : string
-
The code to render.
- $args : mixed
-
The arguments for the code.
Return values
mixed —The rendered output.
Run()
Runs template based on the current template's directory path.
public
static Run(string $code, mixed $args) : string
Parameters
- $code : string
- $args : mixed
-
Additional arguments for rendering.
Return values
string —The rendered output.