Parser
extends View
in package
uses
ViewDecoratorTrait
Class for parsing pseudo-vars
Tags
Table of Contents
Properties
- $leftDelimiter : string
- Left delimiter character for pseudo vars
- $rightDelimiter : string
- Right delimiter character for pseudo vars
- $config : View
- $currentSection : string|null
- The name of the current section being rendered, if any.
- $data : array<string, mixed>
- Saved Data.
- $dataContexts : array<string, mixed>
- Stores the context for each data element when set by `setData` so the context is respected.
- $debug : bool
- Should we store performance info?
- $layout : string|null
- The name of the layout being used, if any.
- $leftConditionalDelimiter : string
- Left delimiter characters for conditionals
- $loader : FileLocatorInterface
- Instance of FileLocator for when we need to attempt to find a view that's not in standard place.
- $logger : LoggerInterface
- Logger instance.
- $noparseBlocks : array<int, string>
- Stores extracted noparse blocks.
- $performanceData : array<int, array{start: float, end: float, view: string}>
- Cache stats about our performance here, when CI_DEBUG = true
- $plugins : array<string, callable|array<int, string>|string>
- Stores any plugins registered at run-time.
- $renderVars : array<string, mixed>
- Data for rendering including Caching and Debug Toolbar data.
- $rightConditionalDelimiter : string
- Right delimiter characters for conditionals
- $saveData : bool
- Whether data should be saved between renders.
- $sections : array<string, array<int, string>>
- Holds the sections and their data.
- $sectionStack : array<int, string>
- The name of the current section being rendered, if any.
- $tempData : array<string, mixed>|null
- Data for the variables that are available in the Views.
- $viewPath : string
- The base directory to look in for our Views.
- $viewsCount : int
- Number of loaded views
Methods
- __construct() : mixed
- Constructor
- addPlugin() : $this
- Makes a new plugin available during the parsing of the template.
- endSection() : void
- Captures the last section
- excerpt() : string
- Extract first bit of a long string and add ellipsis
- extend() : void
- Specifies that the current view should extend an existing layout.
- getData() : array<string, mixed>
- Returns the current data that will be displayed in the view.
- getPerformanceData() : array<int, array{start: float, end: float, view: string}>
- Returns the performance data that might have been collected during the execution. Used primarily in the Debug Toolbar.
- include() : string
- Used within layout views to include additional views.
- insertNoparse() : string
- Re-inserts the noparsed contents back into the template.
- removePlugin() : $this
- Removes a plugin from the available plugins.
- render() : string
- Parse a template
- renderSection() : void
- Renders a section's contents.
- renderString() : string
- Parse a String
- resetData() : RendererInterface
- Removes all of the view data from the system.
- section() : void
- Starts holds content for a section within the layout.
- setConditionalDelimiters() : RendererInterface
- Over-ride the substitution conditional delimiters.
- setData() : RendererInterface
- Sets several pieces of view data at once.
- setDelimiters() : RendererInterface
- Over-ride the substitution field delimiters.
- setVar() : RendererInterface
- Sets a single piece of view data.
- shouldAddEscaping() : false|string
- Checks the placeholder the view provided to see if we need to provide any autoescaping.
- applyFilters() : string
- Given a set of filters, will apply each of the filters in turn to $replace, and return the modified string.
- decorateOutput() : string
- Runs the generated output through any declared view decorators.
- extractNoparse() : string
- Extracts noparse blocks, inserting a hash in its place so that those blocks of the page are not touched by parsing.
- logPerformance() : void
- Logs performance data for rendering a view.
- objectToArray() : array<string, mixed>|bool|float|int|string|null
- Converts an object to an array, respecting any toArray() methods on an object.
- parse() : string
- Parse a template
- parseComments() : string
- Removes any comments from the file. Comments are wrapped in {# #} symbols:
- parseConditionals() : string
- Parses any conditionals in the code, removing blocks that don't pass so we don't try to parse it later.
- parsePair() : array<string, string>
- Parse a tag pair
- parsePlugins() : string
- Scans the template for any parser plugins, and attempts to execute them.
- parseSingle() : array<string, string>
- Parse a single key/value, extracting it
- prepareReplacement() : string
- Callback used during parse() to apply any filters to the value.
- prepareTemplateData() : void
- replaceSingle() : string
- Handles replacing a pseudo-variable with the actual content. Will double-check for escaping brackets.
Properties
$leftDelimiter
Left delimiter character for pseudo vars
public
string
$leftDelimiter
= '{'
$rightDelimiter
Right delimiter character for pseudo vars
public
string
$rightDelimiter
= '}'
$config
protected
View
$config
$currentSection
The name of the current section being rendered, if any.
protected
string|null
$currentSection
$data
Saved Data.
protected
array<string, mixed>
$data
= []
$dataContexts
Stores the context for each data element when set by `setData` so the context is respected.
protected
array<string, mixed>
$dataContexts
= []
$debug
Should we store performance info?
protected
bool
$debug
= false
$layout
The name of the layout being used, if any.
protected
string|null
$layout
Set by the extend
method used within views.
$leftConditionalDelimiter
Left delimiter characters for conditionals
protected
string
$leftConditionalDelimiter
= '{'
$loader
Instance of FileLocator for when we need to attempt to find a view that's not in standard place.
protected
FileLocatorInterface
$loader
$logger
Logger instance.
protected
LoggerInterface
$logger
$noparseBlocks
Stores extracted noparse blocks.
protected
array<int, string>
$noparseBlocks
= []
$performanceData
Cache stats about our performance here, when CI_DEBUG = true
protected
array<int, array{start: float, end: float, view: string}>
$performanceData
= []
$plugins
Stores any plugins registered at run-time.
protected
array<string, callable|array<int, string>|string>
$plugins
= []
Tags
$renderVars
Data for rendering including Caching and Debug Toolbar data.
protected
array<string, mixed>
$renderVars
= []
$rightConditionalDelimiter
Right delimiter characters for conditionals
protected
string
$rightConditionalDelimiter
= '}'
$saveData
Whether data should be saved between renders.
protected
bool
$saveData
$sections
Holds the sections and their data.
protected
array<string, array<int, string>>
$sections
= []
$sectionStack
The name of the current section being rendered, if any.
protected
array<int, string>
$sectionStack
= []
$tempData
Data for the variables that are available in the Views.
protected
array<string, mixed>|null
$tempData
$viewPath
The base directory to look in for our Views.
protected
string
$viewPath
$viewsCount
Number of loaded views
protected
int
$viewsCount
= 0
Methods
__construct()
Constructor
public
__construct(View $config[, string|null $viewPath = null ][, FileLocatorInterface|null $loader = null ][, bool|null $debug = null ][, LoggerInterface|null $logger = null ]) : mixed
Parameters
- $config : View
- $viewPath : string|null = null
- $loader : FileLocatorInterface|null = null
- $debug : bool|null = null
- $logger : LoggerInterface|null = null
addPlugin()
Makes a new plugin available during the parsing of the template.
public
addPlugin(string $alias, callable $callback[, bool $isPair = false ]) : $this
Parameters
- $alias : string
- $callback : callable
- $isPair : bool = false
Return values
$thisendSection()
Captures the last section
public
endSection() : void
Tags
excerpt()
Extract first bit of a long string and add ellipsis
public
excerpt(string $string[, int $length = 20 ]) : string
Parameters
- $string : string
- $length : int = 20
Return values
stringextend()
Specifies that the current view should extend an existing layout.
public
extend(string $layout) : void
Parameters
- $layout : string
getData()
Returns the current data that will be displayed in the view.
public
getData() : array<string, mixed>
Return values
array<string, mixed>getPerformanceData()
Returns the performance data that might have been collected during the execution. Used primarily in the Debug Toolbar.
public
getPerformanceData() : array<int, array{start: float, end: float, view: string}>
Return values
array<int, array{start: float, end: float, view: string}>include()
Used within layout views to include additional views.
public
include(string $view[, array<string, mixed>|null $options = null ][, bool $saveData = true ]) : string
Parameters
- $view : string
- $options : array<string, mixed>|null = null
- $saveData : bool = true
Return values
stringinsertNoparse()
Re-inserts the noparsed contents back into the template.
public
insertNoparse(string $template) : string
Parameters
- $template : string
Return values
stringremovePlugin()
Removes a plugin from the available plugins.
public
removePlugin(string $alias) : $this
Parameters
- $alias : string
Return values
$thisrender()
Parse a template
public
render(string $view[, array<string, mixed>|null $options = null ][, bool|null $saveData = null ]) : string
Parses pseudo-variables contained in the specified template view, replacing them with any data that has already been set.
Parameters
- $view : string
-
File name of the view source
- $options : array<string, mixed>|null = null
-
Reserved for 3rd-party uses since it might be needed to pass additional info to other template engines.
- $saveData : bool|null = null
-
If true, saves data for subsequent calls, if false, cleans the data after displaying, if null, uses the config setting.
Return values
stringrenderSection()
Renders a section's contents.
public
renderSection(string $sectionName[, bool $saveData = false ]) : void
Parameters
- $sectionName : string
- $saveData : bool = false
-
If true, saves data for subsequent calls, if false, cleans the data after displaying.
renderString()
Parse a String
public
renderString(string $template[, array<string, mixed>|null $options = null ][, bool|null $saveData = null ]) : string
Parses pseudo-variables contained in the specified string, replacing them with any data that has already been set.
Parameters
- $template : string
- $options : array<string, mixed>|null = null
-
Reserved for 3rd-party uses since it might be needed to pass additional info to other template engines.
- $saveData : bool|null = null
-
If true, saves data for subsequent calls, if false, cleans the data after displaying, if null, uses the config setting.
Return values
stringresetData()
Removes all of the view data from the system.
public
resetData() : RendererInterface
Return values
RendererInterfacesection()
Starts holds content for a section within the layout.
public
section(string $name) : void
Parameters
- $name : string
-
Section name
setConditionalDelimiters()
Over-ride the substitution conditional delimiters.
public
setConditionalDelimiters([string $leftDelimiter = '{' ][, string $rightDelimiter = '}' ]) : RendererInterface
Parameters
- $leftDelimiter : string = '{'
- $rightDelimiter : string = '}'
Return values
RendererInterfacesetData()
Sets several pieces of view data at once.
public
setData([array<string, mixed> $data = [] ][, non-empty-string|null $context = null ]) : RendererInterface
In the Parser, we need to store the context here so that the variable is correctly handled within the parsing itself, and contexts (including raw) are respected.
Parameters
- $data : array<string, mixed> = []
- $context : non-empty-string|null = null
-
The context to escape it for. If 'raw', no escaping will happen.
Tags
Return values
RendererInterfacesetDelimiters()
Over-ride the substitution field delimiters.
public
setDelimiters([string $leftDelimiter = '{' ][, string $rightDelimiter = '}' ]) : RendererInterface
Parameters
- $leftDelimiter : string = '{'
- $rightDelimiter : string = '}'
Return values
RendererInterfacesetVar()
Sets a single piece of view data.
public
setVar(string $name[, mixed $value = null ][, non-empty-string|null $context = null ]) : RendererInterface
Parameters
- $name : string
- $value : mixed = null
- $context : non-empty-string|null = null
-
The context to escape it for. If 'raw', no escaping will happen.
Tags
Return values
RendererInterfaceshouldAddEscaping()
Checks the placeholder the view provided to see if we need to provide any autoescaping.
public
shouldAddEscaping(string $key) : false|string
Parameters
- $key : string
Return values
false|stringapplyFilters()
Given a set of filters, will apply each of the filters in turn to $replace, and return the modified string.
protected
applyFilters(string $replace, array<int, string> $filters) : string
Parameters
- $replace : string
- $filters : array<int, string>
Return values
stringdecorateOutput()
Runs the generated output through any declared view decorators.
protected
decorateOutput(string $html) : string
Parameters
- $html : string
Return values
stringextractNoparse()
Extracts noparse blocks, inserting a hash in its place so that those blocks of the page are not touched by parsing.
protected
extractNoparse(string $template) : string
Parameters
- $template : string
Return values
stringlogPerformance()
Logs performance data for rendering a view.
protected
logPerformance(float $start, float $end, string $view) : void
Parameters
- $start : float
- $end : float
- $view : string
objectToArray()
Converts an object to an array, respecting any toArray() methods on an object.
protected
objectToArray(array<string, mixed>|bool|float|int|object|string|null $value) : array<string, mixed>|bool|float|int|string|null
Parameters
- $value : array<string, mixed>|bool|float|int|object|string|null
Return values
array<string, mixed>|bool|float|int|string|nullparse()
Parse a template
protected
parse(string $template[, array<string, mixed> $data = [] ][, array<string, mixed> $options = null ]) : string
Parses pseudo-variables contained in the specified template, replacing them with the data in the second param
Parameters
- $template : string
- $data : array<string, mixed> = []
- $options : array<string, mixed> = null
-
Future options
Return values
stringparseComments()
Removes any comments from the file. Comments are wrapped in {# #} symbols:
protected
parseComments(string $template) : string
{# This is a comment #}
Parameters
- $template : string
Return values
stringparseConditionals()
Parses any conditionals in the code, removing blocks that don't pass so we don't try to parse it later.
protected
parseConditionals(string $template) : string
Valid conditionals:
- if
- elseif
- else
Parameters
- $template : string
Return values
stringparsePair()
Parse a tag pair
protected
parsePair(string $variable, array<string, mixed> $data, string $template) : array<string, string>
Parses tag pairs: {some_tag} string... {/some_tag}
Parameters
- $variable : string
- $data : array<string, mixed>
- $template : string
Return values
array<string, string>parsePlugins()
Scans the template for any parser plugins, and attempts to execute them.
protected
parsePlugins(string $template) : string
Plugins are delimited by {+ ... +}
Parameters
- $template : string
Return values
stringparseSingle()
Parse a single key/value, extracting it
protected
parseSingle(string $key, string $val) : array<string, string>
Parameters
- $key : string
- $val : string
Return values
array<string, string>prepareReplacement()
Callback used during parse() to apply any filters to the value.
protected
prepareReplacement(array<int, string> $matches, string $replace[, bool $escape = true ]) : string
Parameters
- $matches : array<int, string>
- $replace : string
- $escape : bool = true
Return values
stringprepareTemplateData()
protected
prepareTemplateData(bool $saveData) : void
Parameters
- $saveData : bool
replaceSingle()
Handles replacing a pseudo-variable with the actual content. Will double-check for escaping brackets.
protected
replaceSingle(array<string|int, mixed>|string $pattern, string $content, string $template[, bool $escape = false ]) : string
Parameters
- $pattern : array<string|int, mixed>|string
- $content : string
- $template : string
- $escape : bool = false