\Box\BrainySmartyBC

Smarty Backward Compatibility Wrapper Class

Summary

Methods
Properties
Constants
__construct()
templateExists()
getGlobal()
enableSecurity()
setTemplateDir()
addTemplateDir()
getTemplateDir()
setPluginsDir()
addPluginsDir()
getPluginsDir()
setCompileDir()
getCompileDir()
setDefaultModifiers()
addDefaultModifiers()
getDefaultModifiers()
createTemplate()
compileAllTemplates()
clearCompiledTemplate()
fetchedTemplate()
registerPlugin()
unregisterPlugin()
registerResource()
unregisterResource()
setLeftDelimiter()
getLeftDelimiter()
setRightDelimiter()
getRightDelimiter()
fetch()
display()
assign()
assignGlobal()
getTemplateVars()
clearAssign()
clearAllAssign()
getVariable()
cloneDataFrom()
applyDataFrom()
clear_assign()
register_function()
unregister_function()
register_compiler_function()
unregister_compiler_function()
register_modifier()
unregister_modifier()
register_resource()
unregister_resource()
clear_cache()
clear_all_cache()
is_cached()
clear_all_assign()
clear_compiled_tpl()
template_exists()
get_template_vars()
get_registered_object()
trigger_error()
$default_assign_scope
$assignment_compat
$enforce_expression_modifiers
$strict_mode
$auto_literal
$force_compile
$compile_check
$use_sub_dirs
$compile_id
$safe_lookups
$left_delimiter
$right_delimiter
$security_policy
$compile_locking
$default_modifiers
$escape_html
$_version
SMARTY_VERSION
SCOPE_LOCAL
SCOPE_PARENT
SCOPE_ROOT
SCOPE_GLOBAL
COMPILECHECK_OFF
COMPILECHECK_ON
PLUGIN_FUNCTION
PLUGIN_COMPILER
PLUGIN_MODIFIER
PLUGIN_MODIFIERCOMPILER
LOOKUP_UNSAFE
LOOKUP_SAFE
LOOKUP_SAFE_WARN
ASSIGN_COMPAT
ASSIGN_NO_COMPAT
assignSingleVar()
No protected properties found
N/A
No private methods found
$template_dir
$compile_dir
$plugins_dir
N/A

Constants

SMARTY_VERSION

SMARTY_VERSION

The current version string for the current version of Brainy.

SCOPE_LOCAL

SCOPE_LOCAL

Represents local scope.

SCOPE_PARENT

SCOPE_PARENT

Represents the parent template's scope.

SCOPE_ROOT

SCOPE_ROOT

Represents the root template's scope.

SCOPE_GLOBAL

SCOPE_GLOBAL

Represents the global scope.

COMPILECHECK_OFF

COMPILECHECK_OFF

Disables checking templates of compiled files to detect changes.

COMPILECHECK_ON

COMPILECHECK_ON

Enables checking templates of compiled files to detect changes.

PLUGIN_FUNCTION

PLUGIN_FUNCTION

Represents a function plugin

PLUGIN_COMPILER

PLUGIN_COMPILER

Represents a compiler plugin

PLUGIN_MODIFIER

PLUGIN_MODIFIER

Represents a modifier plugin

PLUGIN_MODIFIERCOMPILER

PLUGIN_MODIFIERCOMPILER

Represents a modifiercompiler plugin

LOOKUP_UNSAFE

LOOKUP_UNSAFE

When used, lookups will be unsafe (default Smarty 3 behavior)

LOOKUP_SAFE

LOOKUP_SAFE

When used, lookups will be safe (default Smarty 2 behavior)

LOOKUP_SAFE_WARN

LOOKUP_SAFE_WARN

When used, lookups will be safe and a warning will be raised using trigger_error.

ASSIGN_COMPAT

ASSIGN_COMPAT

When used, assignments under SmartyBC will use the Smarty 2 assignment semantics. Assignments will preserve references to previously assigned values.

ASSIGN_NO_COMPAT

ASSIGN_NO_COMPAT

When used, assignments will always use Smarty 3 semantics, regardless of whether SmartyBC is used.

Properties

$default_assign_scope

$default_assign_scope : integer

Sets the default assignment location for a variable. By default, variables are assigned to the local scope. In some contexts, it may be desirable for variable assignment to take place in the global scope.

By setting this property, the default scope can be set. This affects the following:

  • The assign() method on any TemplateData instance
  • The {assign} function
  • The {capture} function (it uses assign())
  • The {include} function when assign="" is used

Type

integer

$assignment_compat

$assignment_compat : integer

SmartyBC's usage will--by default--use Smarty 2's semantics for varaible assignment. This means that if a variable is already defined, a clone of the existing variable will be made to preserve references.

If this value is changed to Brainy::ASSIGN_NO_COMPAT, Smarty 3's assignment semantics will always be used regardless of whether SmartyBC is used or not.

This is considered at compile time and not at runtime.

Type

integer

$enforce_expression_modifiers

$enforce_expression_modifiers : array<mixed,string>

This member allows the enforcement of a modifier being applied to expressions that are output. If one of the modifiers in the list is not used, a SmartyException will be raised.

Type

array<mixed,string>

$strict_mode

$strict_mode : boolean

Setting this option enables strict mode. This removes access to deprecated, unperformant, or otherwise suspect features that were previously available to Smarty templates.

Type

boolean

$auto_literal

$auto_literal : boolean

When `true`, delimiter strings will be ignored if they are surrounded by whitespace.

Type

boolean

$force_compile

$force_compile : boolean

When true, Brainy will never use the compiled versions of templates, though compiled files will continue to be generated. This overrides `Brainy::$compile_check`. Do not use this in production.

Type

boolean

$compile_check

$compile_check : boolean|integer

When `true` or `Brainy::COMPILECHECK_ON`, templates are checked for changes. If changes exist, the template will be recompiled regardless of whether it has been compiled or cached. Disabling this in production may yield performance improvements if templates do not change.

Type

boolean|integer

$use_sub_dirs

$use_sub_dirs : boolean

When true, subdirectories will be created within compile directory.

This is useful for applications with very large numbers of templates, as it minimizes the number of files in each of the directories. This does not work when PHP's safe_mode is set to on.

Type

boolean

$compile_id

$compile_id : string

Set this if you want different sets of compiled files for the same templates.

Type

string

$safe_lookups

$safe_lookups : integer

Indicates whether to perform only safe variable and member lookups.

If set to Brainy::LOOKUP_SAFE, lookups referring to missing variables or members will return a falsey value. LOOKUP_SAFE_WARN will log a warning when the member does not exist.

Type

integer

$left_delimiter

$left_delimiter : string

The left delimiter string

Type

string

$right_delimiter

$right_delimiter : string

The right delimiter string

Type

string

$security_policy

$security_policy : \Box\Brainy\Templates\Security

The Security instance to use as a security policy.

Type

\Box\Brainy\Templates\Security

$compile_locking

$compile_locking : boolean

When true, concurrent template compilation is disabled.

Type

boolean

$default_modifiers

$default_modifiers : array

default modifier

Type

array

$escape_html

$escape_html : boolean

When true, all variables will be implicitly wrapped in

htmlspecialchars({$variable}, ENT_QUOTES, 'UTF-8')

Type

boolean

$_version

$_version : string

Smarty 2 BC

Type

string

$template_dir

$template_dir : array|null

Directory that templates are stored in. See the following methods instead:

  • Brainy::setTemplateDir()
  • Brainy::getTemplateDir()
  • Brainy::addTemplateDir()

Type

array|null

$compile_dir

$compile_dir : string|null

Directory that compiled templates are stored in. See the following methods instead:

  • Brainy::setCompileDir()
  • Brainy::getCompileDir()

Type

string|null

$plugins_dir

$plugins_dir : string|array|null

Directory that plugins are stored in. See the following methods instead:

  • Brainy::setPluginsDir()
  • Brainy::getPluginsDir()
  • Brainy::addPluginsDir()

Type

string|array|null

Methods

__construct()

__construct(array  $options = array()) 

Initialize new SmartyBC object

Parameters

array $options

options to set during initialization, e.g. array( 'forceCompile' => false )

templateExists()

templateExists(string  $resource_name) : boolean

Returns whether a template with the given name exists

Parameters

string $resource_name

template name

Returns

boolean —

Whether the template exists

getGlobal()

getGlobal(string|null|void  $varname = null) : array|mixed

Returns a single or all global variables

Parameters

string|null|void $varname

variable name or null

Returns

array|mixed —

Variable value or associative array of variable values

enableSecurity()

enableSecurity(\Box\Brainy\Templates\Security|null|void  $security_class = null) : \Box\Brainy\Brainy

Loads security class and enables security

Parameters

\Box\Brainy\Templates\Security|null|void $security_class

Throws

\Box\Brainy\Exceptions\SmartyException

when an invalid class is provided

Returns

\Box\Brainy\Brainy

The current Smarty instance for chaining

setTemplateDir()

setTemplateDir(string|array<mixed,string>  $template_dir) : \Box\Brainy\Brainy

Set template directory

Parameters

string|array<mixed,string> $template_dir

directory(s) of template sources

Returns

\Box\Brainy\Brainy

The current Smarty instance for chaining

addTemplateDir()

addTemplateDir(string|array  $template_dir, string|null  $key = null) : \Box\Brainy\Brainy

Add a directory to the list of directories where templates are stored

Parameters

string|array $template_dir

directory(s) of template sources

string|null $key

of the array element to assign the template dir to

Throws

\Box\Brainy\SmartyException

when the given template directory is not valid

Returns

\Box\Brainy\Brainy

The current Smarty instance for chaining

getTemplateDir()

getTemplateDir(integer|null  $index = null) : array|string

Get template directories

Parameters

integer|null $index

of directory to get, null to get all

Returns

array|string —

list of template directories, or directory of $index

setPluginsDir()

setPluginsDir(string|array  $plugins_dir) : \Box\Brainy\Brainy

Set plugins directory

Parameters

string|array $plugins_dir

directory(s) of plugins

Returns

\Box\Brainy\Brainy

current Smarty instance for chaining

addPluginsDir()

addPluginsDir(string|array  $plugins_dir) : \Box\Brainy\Brainy

Add a directory to the list of directories where plugins are stored

Parameters

string|array $plugins_dir

plugins folder

Returns

\Box\Brainy\Brainy

current Smarty instance for chaining

getPluginsDir()

getPluginsDir() : array<mixed,string>

Get plugin directories

Returns

array<mixed,string> —

List of plugin directories

setCompileDir()

setCompileDir(string  $compile_dir) : \Box\Brainy\Brainy

Set compile directory

Parameters

string $compile_dir

directory to store compiled templates in

Returns

\Box\Brainy\Brainy

current Smarty instance for chaining

getCompileDir()

getCompileDir() : string

Get compiled template directory

Returns

string —

Path to compiled templates

setDefaultModifiers()

setDefaultModifiers(array|string  $modifiers) : \Box\Brainy\Brainy

Set default modifiers

Parameters

array|string $modifiers

modifier or list of modifiers to set

Returns

\Box\Brainy\Brainy

current Smarty instance for chaining

addDefaultModifiers()

addDefaultModifiers(array|string  $modifiers) : \Box\Brainy\Brainy

Add default modifiers

Parameters

array|string $modifiers

modifier or list of modifiers to add

Returns

\Box\Brainy\Brainy

current Smarty instance for chaining

getDefaultModifiers()

getDefaultModifiers() : array

Get default modifiers

Returns

array —

list of default modifiers

createTemplate()

createTemplate(string  $template, mixed|void  $compile_id = null, object|null|void  $parent = null) : \Box\Brainy\Template

Creates a template object.

This creates a template object which later can be rendered by the Brainy::display() or Brainy::fetch() method.

Parameters

string $template

the resource handle of the template file

mixed|void $compile_id

compile id to be used with this template

object|null|void $parent

Parent scope to assign to the template

Returns

\Box\Brainy\Template

compileAllTemplates()

compileAllTemplates(string  $extension = '.tpl', boolean  $force_compile = false, integer  $time_limit, integer  $max_errors = null) : integer

Compile all template files

Parameters

string $extension

Optional file extension

boolean $force_compile

Optional boolean that compiles all files instead of modified files

integer $time_limit

Optional integer to specify a runtime limit in seconds for the compilation process

integer $max_errors

Optional integer to set an error limit. If more errors occur, the function will abort

Returns

integer —

number of template files recompiled

clearCompiledTemplate()

clearCompiledTemplate(string|null  $resource_name = null, string|null  $compile_id = null, integer|null  $exp_time = null) : integer

Delete a compiled template file.

This clears the compiled version of the specified template resource, or all compiled template files if one is not specified. If you pass a $compile_id only the compiled template for this specific $compile_id is cleared. If you pass an $exp_time, then only compiled templates older than $exp_time seconds are cleared, by default all compiled templates are cleared regardless of their age. This function is for advanced use only, not normally needed.

Parameters

string|null $resource_name

template name

string|null $compile_id

compile id

integer|null $exp_time

expiration time

Returns

integer —

number of template files deleted

fetchedTemplate()

fetchedTemplate(string  $templatePath) : void

A stub function that is called whenever a template is included. This is included to allow implementers to detect when a template was included by Brainy.

Parameters

string $templatePath

The path to the included template

registerPlugin()

registerPlugin(string  $type, string  $tag, callable  $callback) : \Box\Brainy\Brainy

Registers plugin to be used in templates

Parameters

string $type

plugin type

string $tag

name of template tag

callable $callback

PHP callback to register

Throws

\Box\Brainy\SmartyException

when the plugin tag is invalid

Returns

\Box\Brainy\Brainy

Self-reference to facilitate chaining

unregisterPlugin()

unregisterPlugin(string  $type, string  $tag) : \Box\Brainy\Brainy

Unregister Plugin

Parameters

string $type

of plugin

string $tag

name of plugin

Returns

\Box\Brainy\Brainy

Self-reference to facilitate chaining

registerResource()

registerResource(string  $type, \Box\Brainy\Resources\Resource|array<mixed,\Box\Brainy\Resources\Resource>  $callback) : \Box\Brainy\Brainy

Registers a resource to fetch a template

Parameters

string $type

name of resource type

\Box\Brainy\Resources\Resource|array<mixed,\Box\Brainy\Resources\Resource> $callback

Instance of \Box\Brainy\Resources\Resource, or array of callbacks to handle resource (deprecated)

Returns

\Box\Brainy\Brainy

Self-reference to facilitate chaining

unregisterResource()

unregisterResource(string  $type) : \Box\Brainy\Brainy

Unregisters a resource

Parameters

string $type

name of resource type

Returns

\Box\Brainy\Brainy

Self-reference to facilitate chaining

setLeftDelimiter()

setLeftDelimiter(string  $delim) 

Sets the left delimiter

Parameters

string $delim

getLeftDelimiter()

getLeftDelimiter() : string

Gets the left delimiter

Returns

string

setRightDelimiter()

setRightDelimiter(string  $delim) 

Sets the right delimiter

Parameters

string $delim

getRightDelimiter()

getRightDelimiter() : string

Gets the right delimiter

Returns

string

fetch()

fetch() : string

Proxy to fetch() on a template

Returns

string

display()

display() : string

Proxy to display() on a template

Returns

string

assign()

assign(array|string  $var, mixed|null|void  $value = null, integer|void  $scope = -1) : \Box\Brainy\Templates\TemplateData

Assigns $value to the variable in $var. If an associative array is passed as the only parameter, it is a mapping of variables to assign to the values to assign to them.

Parameters

array|string $var

the template variable name(s)

mixed|null|void $value

the value to assign

integer|void $scope

the scope to associate with the Smarty_Variable instance

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

assignGlobal()

assignGlobal(string  $varname, mixed  $value = null) : \Box\Brainy\Templates\TemplateData

Assigns a global Smarty variable to the global scope.

Parameters

string $varname

the global variable name

mixed $value

the value to assign

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

getTemplateVars()

getTemplateVars(string  $varname = null, \Box\Brainy\Templates\TemplateData  $ptr = null, boolean  $search_parents = true) : string|array

Returns a single or all assigned template variables

Parameters

string $varname

Name of variable to process, or null to return all

\Box\Brainy\Templates\TemplateData $ptr

Optional reference to data object

boolean $search_parents

Whether to include results from parent scopes

Returns

string|array —

variable value or or array of variables

clearAssign()

clearAssign(string|array<mixed,string>  $varName) : \Box\Brainy\Templates\TemplateData

Clear the given assigned template variable.

Parameters

string|array<mixed,string> $varName

The template variable(s) to clear

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

clearAllAssign()

clearAllAssign() : \Box\Brainy\Templates\TemplateData

Clear all the assigned template variables.

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData instance for chaining

getVariable()

getVariable(string  $variable, \Box\Brainy\Templates\TemplateData|null  $_ptr = null, boolean  $search_parents = true, boolean  $error_enable = true) : mixed

Return the contents of an assigned variable.

Parameters

string $variable

the name of the Smarty variable

\Box\Brainy\Templates\TemplateData|null $_ptr

Optional reference to the data object

boolean $search_parents

Whether to search in the parent scope

boolean $error_enable

Whether to raise an error when the variable is not found.

Returns

mixed —

The contents of the variable.

cloneDataFrom()

cloneDataFrom(\Box\Brainy\Templates\TemplateData  $source, boolean|void  $override = true) : void

Copies each variable from the source into this object, creating new `Variable` objects along the way.

Parameters

\Box\Brainy\Templates\TemplateData $source
boolean|void $override

Whether to override existing values

applyDataFrom()

applyDataFrom(array  $source, boolean|void  $override = true) : void

Applies all of the data to the current object

Parameters

array $source
boolean|void $override

Whether to override existing values

clear_assign()

clear_assign(string  $tpl_var) 

clear the given assigned template variable.

Parameters

string $tpl_var

the template variable to clear

register_function()

register_function(string  $function, string  $function_impl, boolean  $cacheable = true, mixed  $cache_attrs = null) 

Registers custom function to be used in templates

Parameters

string $function

the name of the template function

string $function_impl

the name of the PHP function to register

boolean $cacheable
mixed $cache_attrs

unregister_function()

unregister_function(string  $function) 

Unregisters custom function

Parameters

string $function

name of template function

register_compiler_function()

register_compiler_function(string  $function, string  $function_impl, boolean  $cacheable = true) 

Registers compiler function

Parameters

string $function

name of template function

string $function_impl

name of PHP function to register

boolean $cacheable

unregister_compiler_function()

unregister_compiler_function(string  $function) 

Unregisters compiler function

Parameters

string $function

name of template function

register_modifier()

register_modifier(string  $modifier, string  $modifier_impl) 

Registers modifier to be used in templates

Parameters

string $modifier

name of template modifier

string $modifier_impl

name of PHP function to register

unregister_modifier()

unregister_modifier(string  $modifier) 

Unregisters modifier

Parameters

string $modifier

name of template modifier

register_resource()

register_resource(string  $type, array  $functions) 

Registers a resource to fetch a template

Parameters

string $type

name of resource

array $functions

array of functions to handle resource

unregister_resource()

unregister_resource(string  $type) 

Unregisters a resource

Parameters

string $type

name of resource

clear_cache()

clear_cache(string  $tpl_file = null, string  $cache_id = null, string  $compile_id = null, string  $exp_time = null) : boolean

clear cached content for the given template and cache id

Parameters

string $tpl_file

name of template file

string $cache_id

name of cache_id

string $compile_id

name of compile_id

string $exp_time

expiration time

Returns

boolean

clear_all_cache()

clear_all_cache(string  $exp_time = null) : boolean

clear the entire contents of cache (all templates)

Parameters

string $exp_time

expire time

Returns

boolean

is_cached()

is_cached(string  $tpl_file, string  $cache_id = null, string  $compile_id = null) : boolean

test to see if valid cache exists for this template

Parameters

string $tpl_file

name of template file

string $cache_id
string $compile_id

Returns

boolean

clear_all_assign()

clear_all_assign() 

clear all the assigned template variables.

clear_compiled_tpl()

clear_compiled_tpl(string  $tpl_file = null, string  $compile_id = null, string  $exp_time = null) : boolean

clears compiled version of specified template resource, or all compiled template files if one is not specified.

This function is for advanced use only, not normally needed.

Parameters

string $tpl_file
string $compile_id
string $exp_time

Returns

boolean —

results of {@link smarty_core_rm_auto()}

template_exists()

template_exists(string  $tpl_file) : boolean

Checks whether requested template exists.

Parameters

string $tpl_file

Returns

boolean

get_template_vars()

get_template_vars(string  $name = null) : array

Returns an array containing template variables

Parameters

string $name

Returns

array

get_registered_object()

get_registered_object(string  $name) : object

return a reference to a registered object

Parameters

string $name

Returns

object

trigger_error()

trigger_error(string  $error_msg, integer  $error_type = E_USER_WARNING) 

trigger Smarty error

Parameters

string $error_msg
integer $error_type

assignSingleVar()

assignSingleVar(string  $var, mixed  $value, integer  $scope = -1) : void

Assigns $value to the variale $var.

Parameters

string $var

the template variable name

mixed $value

the value to assign

integer $scope

the scope to associate with the Smarty_Variable