mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-01 21:17:21 +00:00
Add return type isTraitable
This commit is contained in:
committed by
Fabien Potencier
parent
d379eef2aa
commit
bb8b9c197c
+13
-8
@@ -115,7 +115,7 @@ final class ModuleNode extends Node
|
|||||||
$parent = $this->getNode('parent');
|
$parent = $this->getNode('parent');
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->write("protected function doGetParent(array \$context)\n", "{\n")
|
->write("protected function doGetParent(array \$context): bool|string|Template|TemplateWrapper\n", "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->addDebugInfo($parent)
|
->addDebugInfo($parent)
|
||||||
->write('return ')
|
->write('return ')
|
||||||
@@ -160,7 +160,9 @@ final class ModuleNode extends Node
|
|||||||
->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n")
|
->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n")
|
||||||
->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n")
|
->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n")
|
||||||
->write("use Twig\Source;\n")
|
->write("use Twig\Source;\n")
|
||||||
->write("use Twig\Template;\n\n")
|
->write("use Twig\Template;\n")
|
||||||
|
->write("use Twig\TemplateWrapper;\n")
|
||||||
|
->write("\n")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$compiler
|
$compiler
|
||||||
@@ -170,8 +172,11 @@ final class ModuleNode extends Node
|
|||||||
->raw(" extends Template\n")
|
->raw(" extends Template\n")
|
||||||
->write("{\n")
|
->write("{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("private \$source;\n")
|
->write("private Source \$source;\n")
|
||||||
->write("private \$macros = [];\n\n")
|
->write("/**\n")
|
||||||
|
->write(" * @var array<string, Template>\n")
|
||||||
|
->write(" */\n")
|
||||||
|
->write("private array \$macros = [];\n\n")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +382,7 @@ final class ModuleNode extends Node
|
|||||||
->write("/**\n")
|
->write("/**\n")
|
||||||
->write(" * @codeCoverageIgnore\n")
|
->write(" * @codeCoverageIgnore\n")
|
||||||
->write(" */\n")
|
->write(" */\n")
|
||||||
->write("public function getTemplateName()\n", "{\n")
|
->write("public function getTemplateName(): string\n", "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write('return ')
|
->write('return ')
|
||||||
->repr($this->getSourceContext()->getName())
|
->repr($this->getSourceContext()->getName())
|
||||||
@@ -434,7 +439,7 @@ final class ModuleNode extends Node
|
|||||||
->write("/**\n")
|
->write("/**\n")
|
||||||
->write(" * @codeCoverageIgnore\n")
|
->write(" * @codeCoverageIgnore\n")
|
||||||
->write(" */\n")
|
->write(" */\n")
|
||||||
->write("public function isTraitable()\n", "{\n")
|
->write("public function isTraitable(): bool\n", "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("return false;\n")
|
->write("return false;\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
@@ -448,7 +453,7 @@ final class ModuleNode extends Node
|
|||||||
->write("/**\n")
|
->write("/**\n")
|
||||||
->write(" * @codeCoverageIgnore\n")
|
->write(" * @codeCoverageIgnore\n")
|
||||||
->write(" */\n")
|
->write(" */\n")
|
||||||
->write("public function getDebugInfo()\n", "{\n")
|
->write("public function getDebugInfo(): array\n", "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write(\sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
|
->write(\sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
|
||||||
->outdent()
|
->outdent()
|
||||||
@@ -459,7 +464,7 @@ final class ModuleNode extends Node
|
|||||||
protected function compileGetSourceContext(Compiler $compiler)
|
protected function compileGetSourceContext(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->write("public function getSourceContext()\n", "{\n")
|
->write("public function getSourceContext(): Source\n", "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write('return new Source(')
|
->write('return new Source(')
|
||||||
->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '')
|
->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '')
|
||||||
|
|||||||
+6
-10
@@ -52,24 +52,20 @@ abstract class Template
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the template name.
|
* Returns the template name.
|
||||||
*
|
|
||||||
* @return string The template name
|
|
||||||
*/
|
*/
|
||||||
abstract public function getTemplateName();
|
abstract public function getTemplateName(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns debug information about the template.
|
* Returns debug information about the template.
|
||||||
*
|
*
|
||||||
* @return array Debug information
|
* @return array<int, int> Debug information
|
||||||
*/
|
*/
|
||||||
abstract public function getDebugInfo();
|
abstract public function getDebugInfo(): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about the original template source code.
|
* Returns information about the original template source code.
|
||||||
*
|
|
||||||
* @return Source
|
|
||||||
*/
|
*/
|
||||||
abstract public function getSourceContext();
|
abstract public function getSourceContext(): Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent template.
|
* Returns the parent template.
|
||||||
@@ -107,12 +103,12 @@ abstract class Template
|
|||||||
return $this->parents[$parent];
|
return $this->parents[$parent];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doGetParent(array $context)
|
protected function doGetParent(array $context): bool|string|self|TemplateWrapper
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTraitable()
|
public function isTraitable(): bool
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-22
@@ -23,6 +23,8 @@ use Twig\Node\Node;
|
|||||||
use Twig\Node\SetNode;
|
use Twig\Node\SetNode;
|
||||||
use Twig\Node\TextNode;
|
use Twig\Node\TextNode;
|
||||||
use Twig\Source;
|
use Twig\Source;
|
||||||
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
use Twig\Test\NodeTestCase;
|
use Twig\Test\NodeTestCase;
|
||||||
|
|
||||||
class ModuleTest extends NodeTestCase
|
class ModuleTest extends NodeTestCase
|
||||||
@@ -73,12 +75,16 @@ use Twig\Sandbox\SecurityNotAllowedFilterError;
|
|||||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||||
use Twig\Source;
|
use Twig\Source;
|
||||||
use Twig\Template;
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
/* foo.twig */
|
/* foo.twig */
|
||||||
class __TwigTemplate_%x extends Template
|
class __TwigTemplate_%x extends Template
|
||||||
{
|
{
|
||||||
private \$source;
|
private Source \$source;
|
||||||
private \$macros = [];
|
/**
|
||||||
|
* @var array<string, Template>
|
||||||
|
*/
|
||||||
|
private array \$macros = [];
|
||||||
|
|
||||||
public function __construct(Environment \$env)
|
public function __construct(Environment \$env)
|
||||||
{
|
{
|
||||||
@@ -103,7 +109,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getTemplateName()
|
public function getTemplateName(): string
|
||||||
{
|
{
|
||||||
return "foo.twig";
|
return "foo.twig";
|
||||||
}
|
}
|
||||||
@@ -111,12 +117,12 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getDebugInfo()
|
public function getDebugInfo(): array
|
||||||
{
|
{
|
||||||
return array ( 38 => 1,);
|
return array ( 42 => 1,);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext()
|
public function getSourceContext(): Source
|
||||||
{
|
{
|
||||||
return new Source("", "foo.twig", "");
|
return new Source("", "foo.twig", "");
|
||||||
}
|
}
|
||||||
@@ -145,12 +151,16 @@ use Twig\Sandbox\SecurityNotAllowedFilterError;
|
|||||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||||
use Twig\Source;
|
use Twig\Source;
|
||||||
use Twig\Template;
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
/* foo.twig */
|
/* foo.twig */
|
||||||
class __TwigTemplate_%x extends Template
|
class __TwigTemplate_%x extends Template
|
||||||
{
|
{
|
||||||
private \$source;
|
private Source \$source;
|
||||||
private \$macros = [];
|
/**
|
||||||
|
* @var array<string, Template>
|
||||||
|
*/
|
||||||
|
private array \$macros = [];
|
||||||
|
|
||||||
public function __construct(Environment \$env)
|
public function __construct(Environment \$env)
|
||||||
{
|
{
|
||||||
@@ -162,7 +172,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doGetParent(array \$context)
|
protected function doGetParent(array \$context): bool|string|Template|TemplateWrapper
|
||||||
{
|
{
|
||||||
// line 1
|
// line 1
|
||||||
return "layout.twig";
|
return "layout.twig";
|
||||||
@@ -181,7 +191,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getTemplateName()
|
public function getTemplateName(): string
|
||||||
{
|
{
|
||||||
return "foo.twig";
|
return "foo.twig";
|
||||||
}
|
}
|
||||||
@@ -189,7 +199,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function isTraitable()
|
public function isTraitable(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -197,12 +207,12 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getDebugInfo()
|
public function getDebugInfo(): array
|
||||||
{
|
{
|
||||||
return array ( 44 => 1, 42 => 2, 35 => 1,);
|
return array ( 48 => 1, 46 => 2, 39 => 1,);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext()
|
public function getSourceContext(): Source
|
||||||
{
|
{
|
||||||
return new Source("", "foo.twig", "");
|
return new Source("", "foo.twig", "");
|
||||||
}
|
}
|
||||||
@@ -236,12 +246,16 @@ use Twig\Sandbox\SecurityNotAllowedFilterError;
|
|||||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||||
use Twig\Source;
|
use Twig\Source;
|
||||||
use Twig\Template;
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
/* foo.twig */
|
/* foo.twig */
|
||||||
class __TwigTemplate_%x extends Template
|
class __TwigTemplate_%x extends Template
|
||||||
{
|
{
|
||||||
private \$source;
|
private Source \$source;
|
||||||
private \$macros = [];
|
/**
|
||||||
|
* @var array<string, Template>
|
||||||
|
*/
|
||||||
|
private array \$macros = [];
|
||||||
|
|
||||||
public function __construct(Environment \$env)
|
public function __construct(Environment \$env)
|
||||||
{
|
{
|
||||||
@@ -253,7 +267,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doGetParent(array \$context)
|
protected function doGetParent(array \$context): bool|string|Template|TemplateWrapper
|
||||||
{
|
{
|
||||||
// line 2
|
// line 2
|
||||||
return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
|
return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
|
||||||
@@ -271,7 +285,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getTemplateName()
|
public function getTemplateName(): string
|
||||||
{
|
{
|
||||||
return "foo.twig";
|
return "foo.twig";
|
||||||
}
|
}
|
||||||
@@ -279,7 +293,7 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function isTraitable()
|
public function isTraitable(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -287,12 +301,12 @@ class __TwigTemplate_%x extends Template
|
|||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function getDebugInfo()
|
public function getDebugInfo(): array
|
||||||
{
|
{
|
||||||
return array ( 44 => 2, 42 => 4, 35 => 2,);
|
return array ( 48 => 2, 46 => 4, 39 => 2,);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext()
|
public function getSourceContext(): Source
|
||||||
{
|
{
|
||||||
return new Source("{{ foo }}", "foo.twig", "");
|
return new Source("{{ foo }}", "foo.twig", "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Twig\Sandbox\SecurityError;
|
|||||||
use Twig\Sandbox\SecurityPolicy;
|
use Twig\Sandbox\SecurityPolicy;
|
||||||
use Twig\Source;
|
use Twig\Source;
|
||||||
use Twig\Template;
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
class TemplateTest extends TestCase
|
class TemplateTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -443,22 +444,22 @@ class TemplateForTest extends Template
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateName()
|
public function getTemplateName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDebugInfo()
|
public function getDebugInfo() : array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext()
|
public function getSourceContext() : Source
|
||||||
{
|
{
|
||||||
return new Source('', $this->getTemplateName());
|
return new Source('', $this->getTemplateName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doGetParent(array $context)
|
protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user