From d2f846b45306d88387ee81e694e925d4ac643fa4 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 23 Nov 2014 21:10:39 +0100 Subject: [PATCH] compare version using PHP_VERSION_ID This continues the work started in #12497 on the `2.3` branch. --- .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- .../Tests/Console/Descriptor/JsonDescriptorTest.php | 2 +- .../Tests/DependencyInjection/ConfigurationTest.php | 2 +- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 6 +++--- src/Symfony/Component/ExpressionLanguage/Parser.php | 2 +- .../Tests/TokenStorage/NativeSessionTokenStorageTest.php | 2 +- .../Csrf/TokenStorage/NativeSessionTokenStorage.php | 2 +- .../Translation/Tests/Dumper/JsonFileDumperTest.php | 2 +- .../Tests/Validator/LegacyValidator2Dot5ApiTest.php | 2 +- .../Tests/Validator/LegacyValidatorLegacyApiTest.php | 2 +- .../Component/Validator/Tests/ValidatorBuilderTest.php | 4 ++-- src/Symfony/Component/Validator/ValidatorBuilder.php | 4 ++-- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 6bc5e555fc..d430e302fc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -474,7 +474,7 @@ class Configuration implements ConfigurationInterface // API version already during container configuration // (to adjust service classes etc.) // See https://github.com/symfony/symfony/issues/11580 - $v['validation']['api'] = version_compare(PHP_VERSION, '5.3.9', '<') + $v['validation']['api'] = PHP_VERSION_ID < 50309 ? '2.4' : '2.5-bc'; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php index 5d6dafe46b..7f7a0ae15c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php @@ -17,7 +17,7 @@ class JsonDescriptorTest extends AbstractDescriptorTest { protected function setUp() { - if (version_compare(phpversion(), '5.4.0', '<')) { + if (PHP_VERSION_ID < 50400) { $this->markTestSkipped('Test skipped on PHP 5.3 as JSON_PRETTY_PRINT does not exist.'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index f2778fbd6a..8e40ee11fe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -129,7 +129,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'static_method' => array('loadValidatorMetadata'), 'translation_domain' => 'validators', 'strict_email' => false, - 'api' => version_compare(PHP_VERSION, '5.3.9', '<') ? '2.4' : '2.5-bc', + 'api' => PHP_VERSION_ID < 50309 ? '2.4' : '2.5-bc', ), 'annotations' => array( 'cache' => 'file', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index a05cb21bb4..07a337abd1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -280,7 +280,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals(array(new Reference('validator.mapping.cache.apc')), $calls[5][1]); $this->assertSame('setApiVersion', $calls[6][0]); - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->assertEquals(array(Validation::API_VERSION_2_4), $calls[6][1]); } else { $this->assertEquals(array(Validation::API_VERSION_2_5_BC), $calls[6][1]); @@ -433,7 +433,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertSame('setApiVersion', $calls[5][0]); // no cache, no annotations - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]); } else { $this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]); @@ -457,7 +457,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertSame('setApiVersion', $calls[5][0]); // no cache, no annotations - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]); } else { $this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]); diff --git a/src/Symfony/Component/ExpressionLanguage/Parser.php b/src/Symfony/Component/ExpressionLanguage/Parser.php index e08568ceef..3e769c6d4f 100644 --- a/src/Symfony/Component/ExpressionLanguage/Parser.php +++ b/src/Symfony/Component/ExpressionLanguage/Parser.php @@ -336,7 +336,7 @@ class Parser $node = new Node\GetAttrNode($node, $arg, $arguments, $type); } elseif ('[' === $token->value) { - if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && version_compare(PHP_VERSION, '5.4.0', '<')) { + if ($node instanceof Node\GetAttrNode && Node\GetAttrNode::METHOD_CALL === $node->attributes['type'] && PHP_VERSION_ID < 50400) { throw new SyntaxError('Array calls on a method call is only supported on PHP 5.4+', $token->cursor); } diff --git a/src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php b/src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php index 724806c881..7ae27790e5 100644 --- a/src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php +++ b/src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php @@ -51,7 +51,7 @@ class NativeSessionTokenStorageTest extends \PHPUnit_Framework_TestCase public function testStoreTokenInClosedSessionWithExistingSessionId() { - if (version_compare(PHP_VERSION, '5.4', '<')) { + if (PHP_VERSION_ID < 50400) { $this->markTestSkipped('This test requires PHP 5.4 or later.'); } diff --git a/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php b/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php index af5931b40b..bb1a417ad5 100644 --- a/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php +++ b/src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php @@ -108,7 +108,7 @@ class NativeSessionTokenStorage implements TokenStorageInterface private function startSession() { - if (version_compare(PHP_VERSION, '5.4', '>=')) { + if (PHP_VERSION_ID >= 50400) { if (PHP_SESSION_NONE === session_status()) { session_start(); } diff --git a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php index acd2087fdb..697cd939f6 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/JsonFileDumperTest.php @@ -18,7 +18,7 @@ class JsonFileDumperTest extends \PHPUnit_Framework_TestCase { public function testDump() { - if (version_compare(PHP_VERSION, '5.4.0', '<')) { + if (PHP_VERSION_ID < 50400) { $this->markTestIncomplete('PHP below 5.4 doesn\'t support JSON pretty printing'); } diff --git a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php index 7a00da6419..3e1e442f75 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php @@ -21,7 +21,7 @@ class LegacyValidator2Dot5ApiTest extends Abstract2Dot5ApiTest { protected function setUp() { - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->markTestSkipped('Not supported prior to PHP 5.3.9'); } diff --git a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php index f803c636b9..3f02a5af71 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php @@ -21,7 +21,7 @@ class LegacyValidatorLegacyApiTest extends AbstractLegacyApiTest { protected function setUp() { - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->markTestSkipped('Not supported prior to PHP 5.3.9'); } diff --git a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php index ed914d1394..ba184f7c78 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php @@ -112,7 +112,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase public function testDefaultApiVersion() { - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { // Old implementation on PHP < 5.3.9 $this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator()); } else { @@ -135,7 +135,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase public function testSetApiVersion24And25() { - if (version_compare(PHP_VERSION, '5.3.9', '<')) { + if (PHP_VERSION_ID < 50309) { $this->markTestSkipped('Not supported prior to PHP 5.3.9'); } diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index ba6fa0c805..b4489f4c2b 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -325,7 +325,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface )); } - if (version_compare(PHP_VERSION, '5.3.9', '<') && $apiVersion === Validation::API_VERSION_2_5_BC) { + if (PHP_VERSION_ID < 50309 && $apiVersion === Validation::API_VERSION_2_5_BC) { throw new InvalidArgumentException(sprintf( 'The Validator API that is compatible with both Symfony 2.4 '. 'and Symfony 2.5 can only be used on PHP 5.3.9 and higher. '. @@ -385,7 +385,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface $apiVersion = $this->apiVersion; if (null === $apiVersion) { - $apiVersion = version_compare(PHP_VERSION, '5.3.9', '<') + $apiVersion = PHP_VERSION_ID < 50309 ? Validation::API_VERSION_2_4 : Validation::API_VERSION_2_5_BC; }