Bump Twig to v2, refit code
This commit is contained in:
parent
59d1e7736c
commit
2b5709adb9
|
|
@ -3,8 +3,7 @@ Changelog can be found here: http://octobercms.com/changelog
|
|||
### Breaking changes Laravel 5.5
|
||||
|
||||
- Database queries now return Collections instead of arrays!
|
||||
- Twig has been updated to v2.0
|
||||
- `pluck()` should be renamed to `value()`
|
||||
- `getRelatedIds()` called from BelongsToMany is renamed to `allRelatedIds()`
|
||||
- `Mail::pretend()` has been removed, use `Config::set('mail.driver', 'log');` instead
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
|
||||
/**
|
||||
* Represents a component node
|
||||
|
|
@ -12,7 +11,7 @@ use Twig_NodeInterface;
|
|||
*/
|
||||
class ComponentNode extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $nodes, $paramNames, $lineno, $tag = 'component')
|
||||
public function __construct(Twig_Node $nodes, $paramNames, $lineno, $tag = 'component')
|
||||
{
|
||||
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
|
||||
}
|
||||
|
|
@ -35,7 +34,7 @@ class ComponentNode extends Twig_Node
|
|||
}
|
||||
|
||||
$compiler
|
||||
->write("echo \$this->env->getExtension('CMS')->componentFunction(")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->componentFunction(")
|
||||
->subcompile($this->getNode('nodes')->getNode(0))
|
||||
->write(", \$context['__cms_component_params']")
|
||||
->write(");\n")
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class ComponentTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
|
||||
/**
|
||||
* Represents a content node
|
||||
|
|
@ -12,7 +11,7 @@ use Twig_NodeInterface;
|
|||
*/
|
||||
class ContentNode extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $nodes, $paramNames, $lineno, $tag = 'content')
|
||||
public function __construct(Twig_Node $nodes, $paramNames, $lineno, $tag = 'content')
|
||||
{
|
||||
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
|
||||
}
|
||||
|
|
@ -37,7 +36,7 @@ class ContentNode extends Twig_Node
|
|||
}
|
||||
|
||||
$compiler
|
||||
->write("echo \$this->env->getExtension('CMS')->contentFunction(")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->contentFunction(")
|
||||
->subcompile($this->getNode('nodes')->getNode(0))
|
||||
->write(", \$context['__cms_content_params']")
|
||||
->write(");\n")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ContentTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class DefaultTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
use Twig_Node_Expression;
|
||||
|
||||
/**
|
||||
|
|
@ -13,7 +12,7 @@ use Twig_Node_Expression;
|
|||
*/
|
||||
class FlashNode extends Twig_Node
|
||||
{
|
||||
public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = 'flash')
|
||||
public function __construct($name, Twig_Node $body, $lineno, $tag = 'flash')
|
||||
{
|
||||
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class FlashTokenParser extends Twig_TokenParser
|
|||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class FrameworkTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php namespace Cms\Twig;
|
||||
|
||||
use Event;
|
||||
use Twig_Source;
|
||||
use Twig_LoaderInterface;
|
||||
use Cms\Contracts\CmsObject;
|
||||
use System\Twig\Loader as LoaderBase;
|
||||
|
|
@ -37,10 +38,10 @@ class Loader extends LoaderBase implements Twig_LoaderInterface
|
|||
* Returns the Twig content string.
|
||||
* This step is cached internally by Twig.
|
||||
*/
|
||||
public function getSource($name)
|
||||
public function getSourceContext($name)
|
||||
{
|
||||
if (!$this->validateCmsObject($name)) {
|
||||
return parent::getSource($name);
|
||||
return parent::getSourceContext($name);
|
||||
}
|
||||
|
||||
$content = $this->obj->getTwigContent();
|
||||
|
|
@ -52,7 +53,7 @@ class Loader extends LoaderBase implements Twig_LoaderInterface
|
|||
|
||||
Event::fire('cms.template.processTwigContent', [$this->obj, $dataHolder]);
|
||||
|
||||
return $dataHolder->content;
|
||||
return new Twig_Source($dataHolder->content, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class PageNode extends Twig_Node
|
|||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('CMS')->pageFunction();\n")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->pageFunction();\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class PageTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
|
||||
/**
|
||||
* Represents a partial node
|
||||
|
|
@ -12,7 +11,7 @@ use Twig_NodeInterface;
|
|||
*/
|
||||
class PartialNode extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $nodes, $paramNames, $lineno, $tag = 'partial')
|
||||
public function __construct(Twig_Node $nodes, $paramNames, $lineno, $tag = 'partial')
|
||||
{
|
||||
parent::__construct(['nodes' => $nodes], ['names' => $paramNames], $lineno, $tag);
|
||||
}
|
||||
|
|
@ -35,7 +34,7 @@ class PartialNode extends Twig_Node
|
|||
}
|
||||
|
||||
$compiler
|
||||
->write("echo \$this->env->getExtension('CMS')->partialFunction(")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->partialFunction(")
|
||||
->subcompile($this->getNode('nodes')->getNode(0))
|
||||
->write(", \$context['__cms_partial_params']")
|
||||
->write(");\n")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class PartialTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
|
||||
/**
|
||||
* Represents a placeholder node
|
||||
|
|
@ -53,10 +52,10 @@ class PlaceholderNode extends Twig_Node
|
|||
|
||||
$compiler->addDebugInfo($this);
|
||||
if (!$isText) {
|
||||
$compiler->write("echo \$this->env->getExtension('CMS')->displayBlock(");
|
||||
$compiler->write("echo \$this->env->getExtension('Cms\Twig\Extension')->displayBlock(");
|
||||
}
|
||||
else {
|
||||
$compiler->write("echo twig_escape_filter(\$this->env, \$this->env->getExtension('CMS')->displayBlock(");
|
||||
$compiler->write("echo twig_escape_filter(\$this->env, \$this->env->getExtension('Cms\Twig\Extension')->displayBlock(");
|
||||
}
|
||||
|
||||
$compiler
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class PlaceholderTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use Twig_Node;
|
||||
use Twig_Compiler;
|
||||
use Twig_NodeInterface;
|
||||
|
||||
/**
|
||||
* Represents a put node
|
||||
|
|
@ -12,7 +11,7 @@ use Twig_NodeInterface;
|
|||
*/
|
||||
class PutNode extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_NodeInterface $body, $name, $endType, $lineno, $tag = 'put')
|
||||
public function __construct(Twig_Node $body, $name, $endType, $lineno, $tag = 'put')
|
||||
{
|
||||
parent::__construct(['body' => $body], ['name' => $name, 'endType' => $endType], $lineno, $tag);
|
||||
}
|
||||
|
|
@ -26,7 +25,7 @@ class PutNode extends Twig_Node
|
|||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('CMS')->startBlock(")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->startBlock(")
|
||||
->raw("'".$this->getAttribute('name')."'")
|
||||
->write(");\n")
|
||||
;
|
||||
|
|
@ -37,7 +36,7 @@ class PutNode extends Twig_Node
|
|||
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('CMS')->endBlock(")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->endBlock(")
|
||||
->raw($isOverwrite ? 'false' : 'true')
|
||||
->write(");\n")
|
||||
;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class PutTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ class ScriptsNode extends Twig_Node
|
|||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('CMS')->assetsFunction('js');\n")
|
||||
->write("echo \$this->env->getExtension('CMS')->displayBlock('scripts');\n")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->assetsFunction('js');\n")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->displayBlock('scripts');\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ScriptsTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ class StylesNode extends Twig_Node
|
|||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('CMS')->assetsFunction('css');\n")
|
||||
->write("echo \$this->env->getExtension('CMS')->displayBlock('styles');\n")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->assetsFunction('css');\n")
|
||||
->write("echo \$this->env->getExtension('Cms\Twig\Extension')->displayBlock('styles');\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class StylesTokenParser extends Twig_TokenParser
|
|||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Twig_Token $token A Twig_Token instance
|
||||
* @return Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use App;
|
||||
use File;
|
||||
use Twig_Source;
|
||||
use Twig_LoaderInterface;
|
||||
use Exception;
|
||||
|
||||
|
|
@ -49,9 +50,9 @@ class Loader implements Twig_LoaderInterface
|
|||
return $this->cache[$name] = $path;
|
||||
}
|
||||
|
||||
public function getSource($name)
|
||||
public function getSourceContext($name)
|
||||
{
|
||||
return File::get($this->findTemplate($name));
|
||||
return new Twig_Source(File::get($this->findTemplate($name)), $name);
|
||||
}
|
||||
|
||||
public function getCacheKey($name)
|
||||
|
|
|
|||
Loading…
Reference in New Issue