Parser
extends View
in package
Class for parsing pseudo-vars
Table of Contents
- $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|int, mixed>
- Data that is made available to the Views.
- $dataContexts : array<string|int, 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.
- $loader : FileLocator
- 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<string|int, mixed>
- Stores extracted noparse blocks.
- $performanceData : array<string|int, mixed>
- Cache stats about our performance here, when CI_DEBUG = true
- $plugins : array<string|int, mixed>
- Stores any plugins registered at run-time.
- $renderVars : array<string|int, mixed>
- The render variables
- $saveData : bool
- Whether data should be saved between renders.
- $sections : array<string|int, mixed>
- Holds the sections and their data.
- $sectionStack : array<string|int, string>
- The name of the current section being rendered, if any.
- $tempData : mixed
- Merge savedData and userData
- $viewPath : string
- The base directory to look in for our Views.
- $viewsCount : int
- Number of loaded views
- __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|int, mixed>
- Returns the current data that will be displayed in the view.
- getPerformanceData() : array<string|int, mixed>
- 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() : mixed
- 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.
- 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.
- 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() : mixed
- 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|int, mixed>
- Parse a tag pair
- parsePlugins() : string
- Scans the template for any parser plugins, and attempts to execute them.
- parseSingle() : array<string|int, mixed>
- Parse a single key/value, extracting it
- prepareReplacement() : string
- Callback used during parse() to apply any filters to the value.
- 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
Tags
$data
Data that is made available to the Views.
protected
array<string|int, mixed>
$data
= []
$dataContexts
Stores the context for each data element when set by `setData` so the context is respected.
protected
array<string|int, 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.
$loader
Instance of FileLocator for when we need to attempt to find a view that's not in standard place.
protected
FileLocator
$loader
$logger
Logger instance.
protected
LoggerInterface
$logger
$noparseBlocks
Stores extracted noparse blocks.
protected
array<string|int, mixed>
$noparseBlocks
= []
$performanceData
Cache stats about our performance here, when CI_DEBUG = true
protected
array<string|int, mixed>
$performanceData
= []
$plugins
Stores any plugins registered at run-time.
protected
array<string|int, mixed>
$plugins
= []
$renderVars
The render variables
protected
array<string|int, mixed>
$renderVars
= []
$saveData
Whether data should be saved between renders.
protected
bool
$saveData
$sections
Holds the sections and their data.
protected
array<string|int, mixed>
$sections
= []
$sectionStack
The name of the current section being rendered, if any.
protected
array<string|int, string>
$sectionStack
= []
$tempData
Merge savedData and userData
protected
mixed
$tempData
= null
$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 $viewPath = null ][, mixed $loader = null ][, bool $debug = null ][, LoggerInterface $logger = null ]) : mixed
Parameters
- $config : View
- $viewPath : string = null
- $loader : mixed = null
- $debug : bool = null
- $logger : LoggerInterface = null
Return values
mixed —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
$this —endSection()
Captures the last section
public
endSection() : void
Tags
Return values
void —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
string —extend()
Specifies that the current view should extend an existing layout.
public
extend(string $layout) : void
Parameters
- $layout : string
Return values
void —getData()
Returns the current data that will be displayed in the view.
public
getData() : array<string|int, mixed>
Return values
array<string|int, mixed> —getPerformanceData()
Returns the performance data that might have been collected during the execution. Used primarily in the Debug Toolbar.
public
getPerformanceData() : array<string|int, mixed>
Return values
array<string|int, mixed> —include()
Used within layout views to include additional views.
public
include(string $view[, array<string|int, mixed>|null $options = null ][, bool $saveData = true ]) : string
Parameters
- $view : string
- $options : array<string|int, mixed>|null = null
- $saveData : bool = true
Return values
string —insertNoparse()
Re-inserts the noparsed contents back into the template.
public
insertNoparse(string $template) : string
Parameters
- $template : string
Return values
string —removePlugin()
Removes a plugin from the available plugins.
public
removePlugin(string $alias) : $this
Parameters
- $alias : string
Return values
$this —render()
Parse a template
public
render(string $view[, array<string|int, mixed> $options = null ][, bool $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
- $options : array<string|int, mixed> = null
- $saveData : bool = null
Return values
string —renderSection()
Renders a section's contents.
public
renderSection(string $sectionName) : mixed
Parameters
- $sectionName : string
Return values
mixed —renderString()
Parse a String
public
renderString(string $template[, array<string|int, mixed> $options = null ][, bool $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|int, mixed> = null
- $saveData : bool = null
Return values
string —resetData()
Removes all of the view data from the system.
public
resetData() : RendererInterface
Return values
RendererInterface —section()
Starts holds content for a section within the layout.
public
section(string $name) : void
Parameters
- $name : string
-
Section name
Return values
void —setData()
Sets several pieces of view data at once.
public
setData([array<string|int, mixed> $data = [] ][, string $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|int, mixed> = []
- $context : string = null
-
The context to escape it for: html, css, js, url, raw If 'raw', no escaping will happen
Return values
RendererInterface —setDelimiters()
Over-ride the substitution field delimiters.
public
setDelimiters([string $leftDelimiter = '{' ][, string $rightDelimiter = '}' ]) : RendererInterface
Parameters
- $leftDelimiter : string = '{'
- $rightDelimiter : string = '}'
Return values
RendererInterface —setVar()
Sets a single piece of view data.
public
setVar(string $name[, mixed $value = null ][, string $context = null ]) : RendererInterface
Parameters
- $name : string
- $value : mixed = null
- $context : string = null
-
The context to escape it for: html, css, js, url If null, no escaping will happen
Return values
RendererInterface —shouldAddEscaping()
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|string —applyFilters()
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<string|int, mixed> $filters) : string
Parameters
- $replace : string
- $filters : array<string|int, mixed>
Return values
string —extractNoparse()
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
string —logPerformance()
Logs performance data for rendering a view.
protected
logPerformance(float $start, float $end, string $view) : void
Parameters
- $start : float
- $end : float
- $view : string
Return values
void —objectToArray()
Converts an object to an array, respecting any toArray() methods on an object.
protected
objectToArray(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —parse()
Parse a template
protected
parse(string $template[, array<string|int, mixed> $data = [] ][, array<string|int, 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|int, mixed> = []
- $options : array<string|int, mixed> = null
-
Future options
Return values
string —parseComments()
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
string —parseConditionals()
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
string —parsePair()
Parse a tag pair
protected
parsePair(string $variable, array<string|int, mixed> $data, string $template) : array<string|int, mixed>
Parses tag pairs: {some_tag} string... {/some_tag}
Parameters
- $variable : string
- $data : array<string|int, mixed>
- $template : string
Return values
array<string|int, mixed> —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
string —parseSingle()
Parse a single key/value, extracting it
protected
parseSingle(string $key, string $val) : array<string|int, mixed>
Parameters
- $key : string
- $val : string
Return values
array<string|int, mixed> —prepareReplacement()
Callback used during parse() to apply any filters to the value.
protected
prepareReplacement(array<string|int, mixed> $matches, string $replace[, bool $escape = true ]) : string
Parameters
- $matches : array<string|int, mixed>
- $replace : string
- $escape : bool = true
Return values
string —replaceSingle()
Handles replacing a pseudo-variable with the actual content. Will double-check for escaping brackets.
protected
replaceSingle(mixed $pattern, string $content, string $template[, bool $escape = false ]) : string
Parameters
- $pattern : mixed
- $content : string
- $template : string
- $escape : bool = false