mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-20 14:36:57 +00:00
minor #1609 get PHP version info once on construction (SpacePossum)
This PR was squashed before being merged into the 1.18-dev branch (closes #1609).
Discussion
----------
get PHP version info once on construction
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
Hi,
I was profiling a project and noticed that `phpversion` was called 5000 times by Twig.
This patch reduces the amount of calls without breaking anything (I hope ;) )

Commits
-------
24ff698 get PHP version info once on construction
This commit is contained in:
@@ -64,7 +64,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)');
|
||||
|
||||
// filter as an anonymous function
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))');
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/FilterInclude.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")');
|
||||
|
||||
// function as an anonymous function
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/FunctionInclude.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
|
||||
$env1 = new Twig_Environment(null, array('strict_variables' => false));
|
||||
|
||||
return array(
|
||||
array($node, "// line 1\n".(version_compare(PHP_VERSION, '5.4.0') >= 0 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env),
|
||||
array($node, "// line 1\n".(PHP_VERSION_ID >= 50400 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env),
|
||||
array($node, $this->getVariableGetter('foo', 1), $env1),
|
||||
array($self, "// line 1\n\$this"),
|
||||
array($context, "// line 1\n\$context"),
|
||||
|
||||
@@ -32,7 +32,7 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
|
||||
$tests[] = array($node, '(null === "foo")');
|
||||
|
||||
// test as an anonymous function
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
|
||||
$tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
|
||||
|
||||
protected function getEnvironment()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
return include 'PHP53/TestInclude.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRenderVariableBlockOptimizer()
|
||||
{
|
||||
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user