Jobbuddy
Chargement...
Recherche...
Aucune correspondance
Référence de la classe Environment

Fonctions membres publiques

 __construct (LoaderInterface $loader, array $options=[])
 useYield ()
 enableDebug ()
 disableDebug ()
 isDebug ()
 enableAutoReload ()
 disableAutoReload ()
 isAutoReload ()
 enableStrictVariables ()
 disableStrictVariables ()
 isStrictVariables ()
 removeCache (string $name)
 getCache ($original=true)
 setCache ($cache)
 getTemplateClass (string $name, ?int $index=null)
 render ($name, array $context=[])
 display ($name, array $context=[])
 load ($name)
 loadTemplate (string $cls, string $name, ?int $index=null)
 createTemplate (string $template, ?string $name=null)
 isTemplateFresh (string $name, int $time)
 resolveTemplate ($names)
 setLexer (Lexer $lexer)
 tokenize (Source $source)
 setParser (Parser $parser)
 parse (TokenStream $stream)
 setCompiler (Compiler $compiler)
 compile (Node $node)
 compileSource (Source $source)
 setLoader (LoaderInterface $loader)
 getLoader ()
 setCharset (string $charset)
 getCharset ()
 hasExtension (string $class)
 addRuntimeLoader (RuntimeLoaderInterface $loader)
 getExtension (string $class)
 getRuntime (string $class)
 addExtension (ExtensionInterface $extension)
 setExtensions (array $extensions)
 getExtensions ()
 addTokenParser (TokenParserInterface $parser)
 getTokenParsers ()
 getTokenParser (string $name)
 registerUndefinedTokenParserCallback (callable $callable)
 addNodeVisitor (NodeVisitorInterface $visitor)
 getNodeVisitors ()
 addFilter (TwigFilter $filter)
 getFilter (string $name)
 registerUndefinedFilterCallback (callable $callable)
 getFilters ()
 addTest (TwigTest $test)
 getTests ()
 getTest (string $name)
 registerUndefinedTestCallback (callable $callable)
 addFunction (TwigFunction $function)
 getFunction (string $name)
 registerUndefinedFunctionCallback (callable $callable)
 getFunctions ()
 addGlobal (string $name, $value)
 getGlobals ()
 resetGlobals ()
 mergeGlobals (array $context)
 getExpressionParsers ()

Champs de données

const VERSION = '3.22.1'
const VERSION_ID = 32201
const MAJOR_VERSION = 3
const MINOR_VERSION = 22
const RELEASE_VERSION = 1
const EXTRA_VERSION = ''

Description détaillée

Stores the Twig configuration and renders templates.

Auteur
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Documentation des constructeurs et destructeur

◆ __construct()

__construct ( LoaderInterface $loader,
array $options = [] )

Constructor.

Available options:

  • debug: When set to true, it automatically set "auto_reload" to true as well (default to false).
  • charset: The charset used by the templates (default to UTF-8).
  • cache: An absolute path where to store the compiled templates, a \Twig\Cache\CacheInterface implementation, or false to disable compilation cache (default).
  • auto_reload: Whether to reload the template if the original source changed. If you don't provide the auto_reload option, it will be determined automatically based on the debug value.
  • strict_variables: Whether to ignore invalid variables in templates (default to false).
  • autoescape: Whether to enable auto-escaping (default to html):
    • false: disable auto-escaping
    • html, js: set the autoescaping to one of the supported strategies
    • name: set the autoescaping strategy based on the template name extension
    • PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
  • 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).
  • use_yield: true: forces templates to exclusively use "yield" instead of "echo" (all extensions must be yield ready) false (default): allows templates to use a mix of "yield" and "echo" calls to allow for a progressive migration Switch to "true" when possible as this will be the only supported mode in Twig 4.0

Documentation des fonctions membres

◆ addExtension()

addExtension ( ExtensionInterface $extension)
Renvoie
void

◆ addFilter()

addFilter ( TwigFilter $filter)
Renvoie
void

◆ addFunction()

addFunction ( TwigFunction $function)
Renvoie
void

◆ addGlobal()

addGlobal ( string $name,
$value )

Registers a Global.

New globals can be added before compiling or rendering a template; but after, you can only update existing globals.

Paramètres
mixed$valueThe global value
Renvoie
void

◆ addNodeVisitor()

addNodeVisitor ( NodeVisitorInterface $visitor)
Renvoie
void

◆ addRuntimeLoader()

addRuntimeLoader ( RuntimeLoaderInterface $loader)
Renvoie
void

◆ addTest()

addTest ( TwigTest $test)
Renvoie
void

◆ addTokenParser()

addTokenParser ( TokenParserInterface $parser)
Renvoie
void

◆ compile()

compile ( Node $node)

Compiles a node and returns the PHP code.

◆ compileSource()

compileSource ( Source $source)

Compiles a template source code.

Exceptions
SyntaxErrorWhen there was an error during tokenizing, parsing or compiling

◆ createTemplate()

createTemplate ( string $template,
?string $name = null )

Creates a template from source.

This method should not be used as a generic way to load templates.

Paramètres
string$templateThe template source
string | null$nameAn optional name of the template to be used in error messages
Exceptions
LoaderErrorWhen the template cannot be found
SyntaxErrorWhen an error occurred during compilation

◆ disableAutoReload()

disableAutoReload ( )

Disables the auto_reload option.

Renvoie
void

◆ disableDebug()

disableDebug ( )

Disables debugging mode.

Renvoie
void

◆ disableStrictVariables()

disableStrictVariables ( )

Disables the strict_variables option.

Renvoie
void

◆ display()

display ( $name,
array $context = [] )

Displays a template.

Paramètres
string | TemplateWrapper$nameThe template name
Exceptions
LoaderErrorWhen the template cannot be found
SyntaxErrorWhen an error occurred during compilation
RuntimeErrorWhen an error occurred during rendering

◆ enableAutoReload()

enableAutoReload ( )

Enables the auto_reload option.

Renvoie
void

◆ enableDebug()

enableDebug ( )

Enables debugging mode.

Renvoie
void

◆ enableStrictVariables()

enableStrictVariables ( )

Enables the strict_variables option.

Renvoie
void

◆ getCache()

getCache ( $original = true)

Gets the current cache implementation.

Paramètres
bool$originalWhether to return the original cache option or the real cache instance
Renvoie
CacheInterface|string|false A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache

◆ getExtension()

getExtension ( string $class)

@template TExtension of ExtensionInterface

Paramètres
class-string<TExtension>$class
Renvoie
TExtension

◆ getExtensions()

getExtensions ( )
Renvoie
ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on)

◆ getFilters()

getFilters ( )

Gets the registered Filters.

Be warned that this method cannot return filters defined with registerUndefinedFilterCallback.

Renvoie
TwigFilter[]
Voir également
registerUndefinedFilterCallback

◆ getFunctions()

getFunctions ( )

Gets registered functions.

Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.

Renvoie
TwigFunction[]
Voir également
registerUndefinedFunctionCallback

◆ getGlobals()

getGlobals ( )
Renvoie
array<string, mixed>

◆ getNodeVisitors()

getNodeVisitors ( )
Renvoie
NodeVisitorInterface[]

◆ getRuntime()

getRuntime ( string $class)

Returns the runtime implementation of a Twig element (filter/function/tag/test).

@template TRuntime of object

Paramètres
class-string<TRuntime>$class A runtime class name
Renvoie
TRuntime The runtime implementation
Exceptions
RuntimeErrorWhen the template cannot be found

◆ getTemplateClass()

getTemplateClass ( string $name,
?int $index = null )

Gets the template class associated with the given string.

The generated template class is based on the following parameters:

  • The cache key for the given template;
  • The currently enabled extensions;
  • PHP version;
  • Twig version;
  • Options with what environment was created.
Paramètres
string$nameThe name for which to calculate the template class name
int | null$indexThe index if it is an embedded template

◆ getTests()

getTests ( )
Renvoie
TwigTest[]

◆ getTokenParsers()

getTokenParsers ( )
Renvoie
TokenParserInterface[]

◆ isAutoReload()

isAutoReload ( )

Checks if the auto_reload option is enabled.

Renvoie
bool true if auto_reload is enabled, false otherwise

◆ isDebug()

isDebug ( )

Checks if debug mode is enabled.

Renvoie
bool true if debug mode is enabled, false otherwise

◆ isStrictVariables()

isStrictVariables ( )

Checks if the strict_variables option is enabled.

Renvoie
bool true if strict_variables is enabled, false otherwise

◆ isTemplateFresh()

isTemplateFresh ( string $name,
int $time )

Returns true if the template is still fresh.

Besides checking the loader for freshness information, this method also checks if the enabled extensions have not changed.

Paramètres
int$timeThe last modification time of the cached template

◆ load()

load ( $name)

Loads a template.

Paramètres
string | TemplateWrapper$nameThe template name
Exceptions
LoaderErrorWhen the template cannot be found
RuntimeErrorWhen a previously generated cache is corrupted
SyntaxErrorWhen an error occurred during compilation

◆ loadTemplate()

loadTemplate ( string $cls,
string $name,
?int $index = null )

Loads a template internal representation.

This method is for internal use only and should never be called directly.

Paramètres
string$nameThe template name
int | null$indexThe index if it is an embedded template
Exceptions
LoaderErrorWhen the template cannot be found
RuntimeErrorWhen a previously generated cache is corrupted
SyntaxErrorWhen an error occurred during compilation

◆ mergeGlobals()

mergeGlobals ( array $context)
Obsolète
since Twig 3.14

◆ parse()

parse ( TokenStream $stream)

Converts a token stream to a node tree.

Exceptions
SyntaxErrorWhen the token stream is syntactically or semantically wrong

◆ registerUndefinedFilterCallback()

registerUndefinedFilterCallback ( callable $callable)
Paramètres
callable(string)(TwigFilter|false) $callable

◆ registerUndefinedFunctionCallback()

registerUndefinedFunctionCallback ( callable $callable)
Paramètres
callable(string)(TwigFunction|false) $callable

◆ registerUndefinedTestCallback()

registerUndefinedTestCallback ( callable $callable)
Paramètres
callable(string)(TwigTest|false) $callable

◆ registerUndefinedTokenParserCallback()

registerUndefinedTokenParserCallback ( callable $callable)
Paramètres
callable(string)(TokenParserInterface|false) $callable

◆ render()

render ( $name,
array $context = [] )

Renders a template.

Paramètres
string | TemplateWrapper$nameThe template name
Exceptions
LoaderErrorWhen the template cannot be found
SyntaxErrorWhen an error occurred during compilation
RuntimeErrorWhen an error occurred during rendering

◆ resolveTemplate()

resolveTemplate ( $names)

Tries to load a template consecutively from an array.

Similar to load() but it also accepts instances of \Twig\TemplateWrapper and an array of templates where each is tried to be loaded.

Paramètres
string|TemplateWrapper|array<string|TemplateWrapper>$names A template or an array of templates to try consecutively
Exceptions
LoaderErrorWhen none of the templates can be found
SyntaxErrorWhen an error occurred during compilation

◆ setCache()

setCache ( $cache)

Sets the current cache implementation.

Paramètres
CacheInterface | string | false$cacheA Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache
Renvoie
void

◆ setCharset()

setCharset ( string $charset)
Renvoie
void

◆ setCompiler()

setCompiler ( Compiler $compiler)
Renvoie
void

◆ setExtensions()

setExtensions ( array $extensions)
Paramètres
ExtensionInterface[]$extensionsAn array of extensions
Renvoie
void

◆ setLexer()

setLexer ( Lexer $lexer)
Renvoie
void

◆ setLoader()

setLoader ( LoaderInterface $loader)
Renvoie
void

◆ setParser()

setParser ( Parser $parser)
Renvoie
void

◆ tokenize()

tokenize ( Source $source)
Exceptions
SyntaxErrorWhen the code is syntactically wrong

La documentation de cette classe a été générée à partir du fichier suivant :