View
extends View
in package
Alias
Table of Contents
- BEFORE_RENDER = 'view.before.render'
- This event will be dispatched before rendering a view.
- DEFAULTS = ['name' => '__default__', 'variables' => [], 'fileExtension' => '.phtml', 'inherit' => true, 'minify' => true, 'cache' => false, 'cacheExclude' => ['__default__'], 'cacheAsIndex' => false, 'cacheWithTimestamp' => true, 'engine' => ['enabled' => true, 'cache' => true, 'debug' => false]]
- The default values of class parameters.
- ON_CACHE = 'view.on.cache'
- This event will be dispatched when a view is cached.
- ON_CACHE_CLEAR = 'view.on.cacheClear'
- This event will be dispatched when views cache is cleared.
- $sections : array<string|int, mixed>
- Sections buffer.
- $stack : array<string|int, mixed>
- Sections stack.
- cache() : string
- Renders a view with the passed variables and cache it as HTML, subsequent calls to this function will return the cached version.
- clearCache() : void
- Deletes all cached views generated by `self::cache()`.
- include() : void
- Includes a file from the active theme directory.
- layout() : string
- Renders a theme layout with the passed variables.
- page() : string
- Renders a theme page with the passed variables.
- partial() : string
- Renders a theme partial with the passed variables.
- render() : string
- Renders a view (a Page wrapped in a Layout) with the passed variables, the Page content will be sent to `{view.defaultSectionName}` section.
- section() : void
- Pushes content to the buffer of the section with the given name.
- sectionEnd() : void
- Ends capturing buffer of the section with the given name. Works in conjunction with `self::sectionStart()`.
- sectionReset() : void
- Resets (empties) the buffer of the section with the given name.
- sectionStart() : void
- Starts capturing buffer of the section with the given name. Works in conjunction with `self::sectionEnd()`.
- yield() : string
- Returns content of the section with the given name.
- resolveCachePath() : string
- Returns a normalized path of a page from the cache directory.
- resolvePath() : string
- Returns a normalized path to a file based on OS.
Constants
BEFORE_RENDER
This event will be dispatched before rendering a view.
public
string
BEFORE_RENDER
= 'view.before.render'
This event will be passed a reference to the array that will be passed to the view as variables.
DEFAULTS
The default values of class parameters.
public
array<string|int, mixed>
DEFAULTS
= ['name' => '__default__', 'variables' => [], 'fileExtension' => '.phtml', 'inherit' => true, 'minify' => true, 'cache' => false, 'cacheExclude' => ['__default__'], 'cacheAsIndex' => false, 'cacheWithTimestamp' => true, 'engine' => ['enabled' => true, 'cache' => true, 'debug' => false]]
ON_CACHE
This event will be dispatched when a view is cached.
public
string
ON_CACHE
= 'view.on.cache'
This event will not be passed any arguments.
ON_CACHE_CLEAR
This event will be dispatched when views cache is cleared.
public
string
ON_CACHE_CLEAR
= 'view.on.cacheClear'
This event will not be passed any arguments.
Properties
$sections
Sections buffer.
protected
static array<string|int, mixed>
$sections
= []
$stack
Sections stack.
protected
static array<string|int, mixed>
$stack
= []
Methods
cache()
Renders a view with the passed variables and cache it as HTML, subsequent calls to this function will return the cached version.
public
static cache(string $page[, array<string|int, mixed> $variables = [] ][, string|null $layout = null ]) : string
This function is exactly like self::render()
but with caching capabilities.
Parameters
- $page : string
-
The name of the page.
- $variables : array<string|int, mixed> = []
-
[optional] An associative array of the variables to pass.
- $layout : string|null = null
-
[optional] The name of the Layout to use.
Return values
string —clearCache()
Deletes all cached views generated by `self::cache()`.
public
static clearCache() : void
Return values
void —include()
Includes a file from the active theme directory.
public
static include(string $file[, array<string|int, mixed>|null $variables = null ]) : void
Can also be used as a mean of extending a layout if it was put at the end of it because the compilation is done from top to bottom and from the deepest nested element to the upper most (imperative approach, there is no preprocessing).
Parameters
- $file : string
-
The path of the file starting from theme root.
- $variables : array<string|int, mixed>|null = null
-
[optional] An associative array of the variables to pass.
Return values
void —layout()
Renders a theme layout with the passed variables.
public
static layout(string $name[, array<string|int, mixed> $variables = [] ]) : string
Parameters
- $name : string
-
The name of the layout.
- $variables : array<string|int, mixed> = []
-
[optional] An associative array of the variables to pass.
Return values
string —page()
Renders a theme page with the passed variables.
public
static page(string $name[, array<string|int, mixed> $variables = [] ]) : string
Parameters
- $name : string
-
The name of the page.
- $variables : array<string|int, mixed> = []
-
[optional] An associative array of the variables to pass.
Return values
string —partial()
Renders a theme partial with the passed variables.
public
static partial(string $name[, array<string|int, mixed> $variables = [] ]) : string
Parameters
- $name : string
-
The name of the partial.
- $variables : array<string|int, mixed> = []
-
[optional] An associative array of the variables to pass.
Return values
string —render()
Renders a view (a Page wrapped in a Layout) with the passed variables, the Page content will be sent to `{view.defaultSectionName}` section.
public
static render(string $page[, array<string|int, mixed> $variables = [] ][, string|null $layout = null ]) : string
Parameters
- $page : string
-
The name of the page.
- $variables : array<string|int, mixed> = []
-
[optional] An associative array of the variables to pass.
- $layout : string|null = null
-
[optional] The name of the Layout to use.
Return values
string —section()
Pushes content to the buffer of the section with the given name.
public
static section(string $name, string $content) : void
Note that a section will not be rendered unless it's yielded.
Parameters
- $name : string
-
The name of the section.
- $content : string
-
The content of the section.
Return values
void —sectionEnd()
Ends capturing buffer of the section with the given name. Works in conjunction with `self::sectionStart()`.
public
static sectionEnd() : void
Note that a section will not be rendered unless it's yielded.
Tags
Return values
void —sectionReset()
Resets (empties) the buffer of the section with the given name.
public
static sectionReset(string $name) : void
Parameters
- $name : string
-
The name of the section.
Return values
void —sectionStart()
Starts capturing buffer of the section with the given name. Works in conjunction with `self::sectionEnd()`.
public
static sectionStart(string $name) : void
Note that a section will not be rendered unless it's yielded.
Parameters
- $name : string
-
The name of the section.
Return values
void —yield()
Returns content of the section with the given name.
public
static yield(string $name[, string $default = '' ]) : string
Parameters
- $name : string
-
The name of the section.
- $default : string = ''
-
[optional] The default value to yield if the section has no content or is an empty string.
Return values
string —resolveCachePath()
Returns a normalized path of a page from the cache directory.
private
static resolveCachePath(string $pageName) : string
Parameters
- $pageName : string
Return values
string —resolvePath()
Returns a normalized path to a file based on OS.
private
static resolvePath(string $directory, string $filename[, string|null $extension = null ]) : string
Parameters
- $directory : string
- $filename : string
- $extension : string|null = null