Backward incompatibilities:
* The short notation of the `block` tag changed.
+ * added the lexer, parser, and compiler as arguments to the Twig_Environment constructor
* changed the cache option to only accepts an explicit path to a cache directory or false
* added a way to add token parsers, filters, and visitors without creating an extension
* added three interfaces: Twig_NodeInterface, Twig_TokenParserInterface, and Twig_FilterInterface
*/
public function __construct(Twig_Environment $env = null)
{
- $this->env = $env;
+ if (null !== $env) {
+ $this->setEnvironment($env);
+ }
}
public function setEnvironment(Twig_Environment $env)
* @param Twig_LoaderInterface $loader A Twig_LoaderInterface instance
* @param array $options An array of options
*/
- public function __construct(Twig_LoaderInterface $loader = null, $options = array())
+ public function __construct(Twig_LoaderInterface $loader = null, $options = array(), Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null)
{
if (null !== $loader) {
$this->setLoader($loader);
}
+ $this->setLexer(null !== $lexer ? $lexer : new Twig_Lexer());
+ $this->setParser(null !== $parser ? $parser : new Twig_Parser());
+ $this->setCompiler(null !== $compiler ? $compiler : new Twig_Compiler());
+
$this->debug = isset($options['debug']) ? (bool) $options['debug'] : false;
$this->trimBlocks = isset($options['trim_blocks']) ? (bool) $options['trim_blocks'] : false;
$this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8';
$this->autoReload = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug;
$this->extensions = array('core' => new Twig_Extension_Core());
$this->runtimeInitialized = false;
- if (isset($options['cache']) && $options['cache'])
- {
+ if (isset($options['cache']) && $options['cache']) {
$this->setCache($options['cache']);
}
}
public function getLexer()
{
- if (null === $this->lexer) {
- $this->lexer = new Twig_Lexer($this);
- }
-
return $this->lexer;
}
public function getParser()
{
- if (null === $this->parser) {
- $this->parser = new Twig_Parser($this);
- }
-
return $this->parser;
}
public function getCompiler()
{
- if (null === $this->compiler) {
- $this->compiler = new Twig_Compiler($this);
- }
-
return $this->compiler;
}
public function __construct(Twig_Environment $env = null, array $options = array())
{
- $this->env = $env;
+ if (null !== $env) {
+ $this->setEnvironment($env);
+ }
$this->options = array_merge(array(
'tag_comment' => array('{#', '#}'),
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-class Twig_Parser
+class Twig_Parser implements Twig_ParserInterface
{
protected $stream;
protected $extends;
public function __construct(Twig_Environment $env = null)
{
- $this->setEnvironment($env);
+ if (null !== $env) {
+ $this->setEnvironment($env);
+ }
}
public function setEnvironment(Twig_Environment $env)
{
$this->env = $env;
+ }
+ /**
+ * Converts a token stream to a node tree.
+ *
+ * @param Twig_TokenStream $stream A token stream instance
+ *
+ * @return Twig_Node_Module A node tree
+ */
+ public function parse(Twig_TokenStream $stream)
+ {
$this->handlers = array();
$this->visitors = array();
}
// node visitors
- $this->visitors = $env->getNodeVisitors();
- }
+ $this->visitors = $this->env->getNodeVisitors();
- /**
- * Converts a token stream to a node tree.
- *
- * @param Twig_TokenStream $stream A token stream instance
- *
- * @return Twig_Node_Module A node tree
- */
- public function parse(Twig_TokenStream $stream)
- {
if (null === $this->expressionParser) {
$this->expressionParser = new Twig_ExpressionParser($this);
}
*
* @return Twig_Node_Module A node tree
*/
- public function parser(Twig_TokenStream $code);
+ public function parse(Twig_TokenStream $code);
}