PHP Class Twig_Environment, php-framework-benchmarks

Author: Fabien Potencier ([email protected])
Show file Open project: pmjones/php-framework-benchmarks Class Usage Examples

Protected Properties

Property Type Description
$autoReload
$baseTemplateClass
$binaryOperators
$cache
$charset
$compiler
$debug
$extensions
$filterCallbacks
$filters
$functionCallbacks
$functions
$globals
$lexer
$loadedTemplates
$loader
$parser
$parsers
$runtimeInitialized
$strictVariables
$templateClassPrefix
$tests
$unaryOperators
$visitors

Public Methods

Method Description
__construct ( Twig_LoaderInterface $loader = null, array $options = [] ) Constructor.
__construct ( Twig_LoaderInterface $loader = null, array $options = [], Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null ) Constructor.
addExtension ( Twig_ExtensionInterface $extension ) Registers an extension.
addFilter ( $name, Twig_FilterInterface $filter )
addFilter ( string $name, Twig_FilterInterface $filter ) Registers a Filter.
addFunction ( string $name, Twig_FunctionInterface $function ) Registers a Function.
addGlobal ( string $name, mixed $value ) Registers a Global.
addNodeVisitor ( Twig_NodeVisitorInterface $visitor ) Registers a Node Visitor.
addTest ( $name, Twig_TestInterface $test )
addTest ( string $name, Twig_TestInterface $test ) Registers a Test.
addTokenParser ( Twig_TokenParserInterface $parser ) Registers a Token Parser.
clearCacheFiles ( ) Clears the template cache files on the filesystem.
clearTemplateCache ( ) Clears the internal template cache.
compile ( Twig_NodeInterface $node )
compile ( Twig_NodeInterface $node ) : string Compiles a Node.
compileSource ( $source, $name )
compileSource ( string $source, string $name = null ) : string Compiles a template source code.
disableAutoReload ( ) Disables the auto_reload option.
disableDebug ( ) Disables debugging mode.
disableStrictVariables ( ) Disables the strict_variables option.
enableAutoReload ( ) Enables the auto_reload option.
enableDebug ( ) Enables debugging mode.
enableStrictVariables ( ) Enables the strict_variables option.
getBaseTemplateClass ( )
getBaseTemplateClass ( ) : string Gets the base template class for compiled templates.
getBinaryOperators ( )
getBinaryOperators ( ) : array Gets the registered binary Operators.
getCache ( )
getCache ( ) : string | false Gets the cache directory or false if cache is disabled.
getCacheFilename ( $name )
getCacheFilename ( string $name ) : string Gets the cache filename for a given template.
getCharset ( )
getCharset ( ) : string Gets the default template charset.
getCompiler ( )
getCompiler ( ) : Twig_CompilerInterface Gets the Compiler instance.
getExtension ( $name )
getExtension ( string $name ) : Twig_ExtensionInterface Gets an extension by name.
getExtensions ( )
getExtensions ( ) : array Returns all registered extensions.
getFilter ( string $name ) : Twig_Filter | false Get a filter by name.
getFilters ( )
getFunction ( string $name ) : Twig_Function | false Get a function by name.
getGlobals ( ) : array Gets the registered Globals.
getLexer ( )
getLexer ( ) : Twig_LexerInterface Gets the Lexer instance.
getLoader ( )
getLoader ( ) : Twig_LoaderInterface Gets the Loader instance.
getNodeVisitors ( )
getNodeVisitors ( ) : Twig_NodeVisitorInterface[] Gets the registered Node Visitors.
getParser ( )
getParser ( ) : Twig_ParserInterface Gets the Parser instance.
getTemplateClass ( string $name ) : string Gets the template class associated with the given string.
getTemplateClassPrefix ( ) : string Gets the template class prefix.
getTests ( )
getTests ( ) : Twig_TestInterface[] Gets the registered Tests.
getTokenParsers ( )
getTokenParsers ( ) : Twig_TokenParserInterface[] Gets the registered Token Parsers.
getUnaryOperators ( )
getUnaryOperators ( ) : array Gets the registered unary Operators.
hasExtension ( $name )
hasExtension ( string $name ) : boolean Returns true if the given extension is registered.
initRuntime ( ) Initializes the runtime environment.
isAutoReload ( )
isAutoReload ( ) : boolean Checks if the auto_reload option is enabled.
isDebug ( )
isDebug ( ) : boolean Checks if debug mode is enabled.
isStrictVariables ( )
isStrictVariables ( ) : boolean Checks if the strict_variables option is enabled.
loadTemplate ( string $name ) : Twig_TemplateInterface Loads a template by name.
parse ( Twig_TokenStream $tokens )
parse ( Twig_TokenStream $tokens ) : Twig_Node_Module Parses a token stream.
registerUndefinedFilterCallback ( $callable )
registerUndefinedFunctionCallback ( $callable )
removeExtension ( $name )
removeExtension ( string $name ) Removes an extension by name.
render ( string $name, array $context = [] ) : string Renders a template.
setAutoReload ( $autoReload )
setBaseTemplateClass ( $class )
setBaseTemplateClass ( string $class ) Sets the base template class for compiled templates.
setCache ( $cache )
setCache ( string | false $cache ) Sets the cache directory or false if cache is disabled.
setCharset ( $charset )
setCharset ( string $charset ) Sets the default template charset.
setCompiler ( Twig_CompilerInterface $compiler ) Sets the Compiler instance.
setExtensions ( array $extensions ) Registers an array of extensions.
setLexer ( Twig_LexerInterface $lexer ) Sets the Lexer instance.
setLoader ( Twig_LoaderInterface $loader ) Sets the Loader instance.
setParser ( Twig_ParserInterface $parser ) Sets the Parser instance.
tokenize ( $source, $name )
tokenize ( string $source, string $name = null ) : Twig_TokenStream Tokenizes a source code.

Protected Methods

Method Description
initOperators ( )
loadFilters ( ) : Twig_FilterInterface[] Gets the registered Filters.
loadFunctions ( )
writeCacheFile ( $file, $content )

Method Details

__construct() public method

Available options: * debug: When set to true, the generated templates have a __toString() method that you can use to display the generated nodes (default to false). * charset: The charset used by the templates (default to utf-8). * base_template_class: The base template class to use for generated templates (default to Twig_Template). * cache: An absolute path where to store the compiled templates, or false to disable compilation cache (default) * auto_reload: Whether to reload the template is the original source changed. If you don't provide the auto_reload option, it will be determined automatically base on the debug value. * strict_variables: Whether to ignore invalid variables in templates (default to false). * autoescape: Whether to enable auto-escaping (default to true); * optimizations: A flag that indicates which optimizations to apply (default to -1 which means that all optimizations are enabled; set it to 0 to disable)
public __construct ( Twig_LoaderInterface $loader = null, array $options = [] )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance
$options array An array of options

__construct() public method

Available options: * debug: When set to true, the generated templates have a __toString() method that you can use to display the generated nodes (default to false). * charset: The charset used by the templates (default to utf-8). * base_template_class: The base template class to use for generated templates (default to Twig_Template). * cache: An absolute path where to store the compiled templates, or false to disable compilation cache (default) * auto_reload: Whether to reload the template is the original source changed. If you don't provide the auto_reload option, it will be determined automatically base on the debug value. * strict_variables: Whether to ignore invalid variables in templates (default to false).
public __construct ( Twig_LoaderInterface $loader = null, array $options = [], Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance
$options array An array of options
$lexer Twig_LexerInterface A Twig_LexerInterface instance
$parser Twig_ParserInterface A Twig_ParserInterface instance
$compiler Twig_CompilerInterface A Twig_CompilerInterface instance

addExtension() public method

Registers an extension.
public addExtension ( Twig_ExtensionInterface $extension )
$extension Twig_ExtensionInterface A Twig_ExtensionInterface instance

addFilter() public method

public addFilter ( $name, Twig_FilterInterface $filter )
$filter Twig_FilterInterface

addFilter() public method

Registers a Filter.
public addFilter ( string $name, Twig_FilterInterface $filter )
$name string The filter name
$filter Twig_FilterInterface

addFunction() public method

Registers a Function.
public addFunction ( string $name, Twig_FunctionInterface $function )
$name string The function name
$function Twig_FunctionInterface A Twig_FunctionInterface instance

addGlobal() public method

Registers a Global.
public addGlobal ( string $name, mixed $value )
$name string The global name
$value mixed The global value

addNodeVisitor() public method

Registers a Node Visitor.
public addNodeVisitor ( Twig_NodeVisitorInterface $visitor )
$visitor Twig_NodeVisitorInterface A Twig_NodeVisitorInterface instance

addTest() public method

public addTest ( $name, Twig_TestInterface $test )
$test Twig_TestInterface

addTest() public method

Registers a Test.
public addTest ( string $name, Twig_TestInterface $test )
$name string The test name
$test Twig_TestInterface

addTokenParser() public method

Registers a Token Parser.
public addTokenParser ( Twig_TokenParserInterface $parser )
$parser Twig_TokenParserInterface A Twig_TokenParserInterface instance

clearCacheFiles() public method

Clears the template cache files on the filesystem.
public clearCacheFiles ( )

clearTemplateCache() public method

Clears the internal template cache.
public clearTemplateCache ( )

compile() public method

public compile ( Twig_NodeInterface $node )
$node Twig_NodeInterface

compile() public method

Compiles a Node.
public compile ( Twig_NodeInterface $node ) : string
$node Twig_NodeInterface A Twig_NodeInterface instance
return string The compiled PHP source code

compileSource() public method

public compileSource ( $source, $name )

compileSource() public method

Compiles a template source code.
public compileSource ( string $source, string $name = null ) : string
$source string The template source code
$name string The template name
return string The compiled PHP source code

disableAutoReload() public method

Disables the auto_reload option.
public disableAutoReload ( )

disableDebug() public method

Disables debugging mode.
public disableDebug ( )

disableStrictVariables() public method

Disables the strict_variables option.

enableAutoReload() public method

Enables the auto_reload option.
public enableAutoReload ( )

enableDebug() public method

Enables debugging mode.
public enableDebug ( )

enableStrictVariables() public method

Enables the strict_variables option.

getBaseTemplateClass() public method

getBaseTemplateClass() public method

Gets the base template class for compiled templates.
public getBaseTemplateClass ( ) : string
return string The base template class name

getBinaryOperators() public method

public getBinaryOperators ( )

getBinaryOperators() public method

Gets the registered binary Operators.
public getBinaryOperators ( ) : array
return array An array of binary operators

getCache() public method

public getCache ( )

getCache() public method

Gets the cache directory or false if cache is disabled.
public getCache ( ) : string | false
return string | false

getCacheFilename() public method

public getCacheFilename ( $name )

getCacheFilename() public method

Gets the cache filename for a given template.
public getCacheFilename ( string $name ) : string
$name string The template name
return string The cache file name

getCharset() public method

public getCharset ( )

getCharset() public method

Gets the default template charset.
public getCharset ( ) : string
return string The default charset

getCompiler() public method

public getCompiler ( )

getCompiler() public method

Gets the Compiler instance.
public getCompiler ( ) : Twig_CompilerInterface
return Twig_CompilerInterface A Twig_CompilerInterface instance

getExtension() public method

public getExtension ( $name )

getExtension() public method

Gets an extension by name.
public getExtension ( string $name ) : Twig_ExtensionInterface
$name string The extension name
return Twig_ExtensionInterface A Twig_ExtensionInterface instance

getExtensions() public method

public getExtensions ( )

getExtensions() public method

Returns all registered extensions.
public getExtensions ( ) : array
return array An array of extensions

getFilter() public method

Subclasses may override this method and load filters differently; so no list of filters is available.
public getFilter ( string $name ) : Twig_Filter | false
$name string The filter name
return Twig_Filter | false A Twig_Filter instance or false if the filter does not exists

getFilters() public method

public getFilters ( )

getFunction() public method

Subclasses may override this method and load functions differently; so no list of functions is available.
public getFunction ( string $name ) : Twig_Function | false
$name string function name
return Twig_Function | false A Twig_Function instance or false if the function does not exists

getGlobals() public method

Gets the registered Globals.
public getGlobals ( ) : array
return array An array of globals

getLexer() public method

public getLexer ( )

getLexer() public method

Gets the Lexer instance.
public getLexer ( ) : Twig_LexerInterface
return Twig_LexerInterface A Twig_LexerInterface instance

getLoader() public method

public getLoader ( )

getLoader() public method

Gets the Loader instance.
public getLoader ( ) : Twig_LoaderInterface
return Twig_LoaderInterface A Twig_LoaderInterface instance

getNodeVisitors() public method

public getNodeVisitors ( )

getNodeVisitors() public method

Gets the registered Node Visitors.
public getNodeVisitors ( ) : Twig_NodeVisitorInterface[]
return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances

getParser() public method

public getParser ( )

getParser() public method

Gets the Parser instance.
public getParser ( ) : Twig_ParserInterface
return Twig_ParserInterface A Twig_ParserInterface instance

getTemplateClass() public method

Gets the template class associated with the given string.
public getTemplateClass ( string $name ) : string
$name string The name for which to calculate the template class name
return string The template class name

getTemplateClassPrefix() public method

Gets the template class prefix.
public getTemplateClassPrefix ( ) : string
return string The template class prefix

getTests() public method

public getTests ( )

getTests() public method

Gets the registered Tests.
public getTests ( ) : Twig_TestInterface[]
return Twig_TestInterface[] An array of Twig_TestInterface instances

getTokenParsers() public method

public getTokenParsers ( )

getTokenParsers() public method

Gets the registered Token Parsers.
public getTokenParsers ( ) : Twig_TokenParserInterface[]
return Twig_TokenParserInterface[] An array of Twig_TokenParserInterface instances

getUnaryOperators() public method

public getUnaryOperators ( )

getUnaryOperators() public method

Gets the registered unary Operators.
public getUnaryOperators ( ) : array
return array An array of unary operators

hasExtension() public method

public hasExtension ( $name )

hasExtension() public method

Returns true if the given extension is registered.
public hasExtension ( string $name ) : boolean
$name string The extension name
return boolean Whether the extension is registered or not

initOperators() protected method

protected initOperators ( )

initRuntime() public method

Initializes the runtime environment.
public initRuntime ( )

isAutoReload() public method

public isAutoReload ( )

isAutoReload() public method

Checks if the auto_reload option is enabled.
public isAutoReload ( ) : boolean
return boolean true if auto_reload is enabled, false otherwise

isDebug() public method

public isDebug ( )

isDebug() public method

Checks if debug mode is enabled.
public isDebug ( ) : boolean
return boolean true if debug mode is enabled, false otherwise

isStrictVariables() public method

public isStrictVariables ( )

isStrictVariables() public method

Checks if the strict_variables option is enabled.
public isStrictVariables ( ) : boolean
return boolean true if strict_variables is enabled, false otherwise

loadFilters() protected method

Gets the registered Filters.
protected loadFilters ( ) : Twig_FilterInterface[]
return Twig_FilterInterface[] An array of Twig_FilterInterface instances

loadFunctions() protected method

protected loadFunctions ( )

loadTemplate() public method

Loads a template by name.
public loadTemplate ( string $name ) : Twig_TemplateInterface
$name string The template name
return Twig_TemplateInterface A template instance representing the given template name

parse() public method

public parse ( Twig_TokenStream $tokens )
$tokens Twig_TokenStream

parse() public method

Parses a token stream.
public parse ( Twig_TokenStream $tokens ) : Twig_Node_Module
$tokens Twig_TokenStream A Twig_TokenStream instance
return Twig_Node_Module A Node tree

registerUndefinedFilterCallback() public method

public registerUndefinedFilterCallback ( $callable )

registerUndefinedFunctionCallback() public method

public registerUndefinedFunctionCallback ( $callable )

removeExtension() public method

public removeExtension ( $name )

removeExtension() public method

Removes an extension by name.
public removeExtension ( string $name )
$name string The extension name

render() public method

Renders a template.
public render ( string $name, array $context = [] ) : string
$name string The template name
$context array An array of parameters to pass to the template
return string The rendered template

setAutoReload() public method

public setAutoReload ( $autoReload )

setBaseTemplateClass() public method

public setBaseTemplateClass ( $class )

setBaseTemplateClass() public method

Sets the base template class for compiled templates.
public setBaseTemplateClass ( string $class )
$class string The base template class name

setCache() public method

public setCache ( $cache )

setCache() public method

Sets the cache directory or false if cache is disabled.
public setCache ( string | false $cache )
$cache string | false The absolute path to the compiled templates, or false to disable cache

setCharset() public method

public setCharset ( $charset )

setCharset() public method

Sets the default template charset.
public setCharset ( string $charset )
$charset string The default charset

setCompiler() public method

Sets the Compiler instance.
public setCompiler ( Twig_CompilerInterface $compiler )
$compiler Twig_CompilerInterface A Twig_CompilerInterface instance

setExtensions() public method

Registers an array of extensions.
public setExtensions ( array $extensions )
$extensions array An array of extensions

setLexer() public method

Sets the Lexer instance.
public setLexer ( Twig_LexerInterface $lexer )
$lexer Twig_LexerInterface

setLoader() public method

Sets the Loader instance.
public setLoader ( Twig_LoaderInterface $loader )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance

setParser() public method

Sets the Parser instance.
public setParser ( Twig_ParserInterface $parser )
$parser Twig_ParserInterface

tokenize() public method

public tokenize ( $source, $name )

tokenize() public method

Tokenizes a source code.
public tokenize ( string $source, string $name = null ) : Twig_TokenStream
$source string The template source code
$name string The template name
return Twig_TokenStream A Twig_TokenStream instance

writeCacheFile() protected method

protected writeCacheFile ( $file, $content )

Property Details

$autoReload protected property

protected $autoReload

$baseTemplateClass protected property

protected $baseTemplateClass

$binaryOperators protected property

protected $binaryOperators

$cache protected property

protected $cache

$charset protected property

protected $charset

$compiler protected property

protected $compiler

$debug protected property

protected $debug

$extensions protected property

protected $extensions

$filterCallbacks protected property

protected $filterCallbacks

$filters protected property

protected $filters

$functionCallbacks protected property

protected $functionCallbacks

$functions protected property

protected $functions

$globals protected property

protected $globals

$lexer protected property

protected $lexer

$loadedTemplates protected property

protected $loadedTemplates

$loader protected property

protected $loader

$parser protected property

protected $parser

$parsers protected property

protected $parsers

$runtimeInitialized protected property

protected $runtimeInitialized

$strictVariables protected property

protected $strictVariables

$templateClassPrefix protected property

protected $templateClassPrefix

$tests protected property

protected $tests

$unaryOperators protected property

protected $unaryOperators

$visitors protected property

protected $visitors