Skip to content

Commit

Permalink
Remove code for PHP <5.5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 1, 2015
1 parent dda085e commit 8797711
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -40,7 +40,7 @@ public static function register($mode = false)
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
}

$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true);
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);

$i = count($trace);
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Command/LintCommand.php
Expand Up @@ -196,7 +196,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
}
});

$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT);

return min($errors, 1);
}
Expand Down
Expand Up @@ -152,7 +152,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
}
});

$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT);

return min($errors, 1);
}
Expand Down
Expand Up @@ -171,12 +171,7 @@ protected function describeContainerParameter($parameter, array $options = array
private function writeData(array $data, array $options)
{
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;

if (defined('JSON_PRETTY_PRINT')) {
$flags |= JSON_PRETTY_PRINT;
}

$this->write(json_encode($data, $flags)."\n");
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -280,12 +280,10 @@ private static function getClassHierarchy(\ReflectionClass $class)

$traits = array();

if (function_exists('get_declared_traits')) {
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
$traits[] = $trait;
}
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
$traits[] = $trait;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -281,7 +281,7 @@ public function setCode($code)
throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
}

if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
if ($code instanceof \Closure) {
$r = new \ReflectionFunction($code);
if (null === $r->getClosureThis()) {
$code = \Closure::bind($code, $this);
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Expand Up @@ -295,10 +295,6 @@ public function getSetCodeBindToClosureTests()
/** @dataProvider getSetCodeBindToClosureTests */
public function testSetCodeBindToClosure($previouslyBound, $expected)
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4+ only.');
}

$code = createClosure();
if ($previouslyBound) {
$code = $code->bindTo($this);
Expand Down
Expand Up @@ -698,9 +698,7 @@ public function testThatCloningIsNotSupported()
{
$class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
$clone = $class->getMethod('__clone');
if (PHP_VERSION_ID >= 540000) {
$this->assertFalse($class->isCloneable());
}
$this->assertFalse($class->isCloneable());
$this->assertTrue($clone->isPrivate());
}
}
Expand Down
Expand Up @@ -118,10 +118,6 @@ public function testTransformDifferentTimezones()

public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
Expand Up @@ -143,10 +143,6 @@ public function testTransformWithDifferentPatterns()

public function testTransformDateTimeImmutableTimezones()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
Expand Up @@ -84,10 +84,6 @@ public function testTransform($fromTz, $toTz, $from, $to)
*/
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);

$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));
Expand Down
Expand Up @@ -97,10 +97,6 @@ public function testTransformWithDifferentTimezones()

public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');

$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');
Expand Down
Expand Up @@ -58,10 +58,6 @@ public function testTransformFromDifferentTimezone()

public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
37 changes: 5 additions & 32 deletions src/Symfony/Component/HttpFoundation/JsonResponse.php
Expand Up @@ -102,39 +102,12 @@ public function setData($data = array())
$data = json_encode($data, $this->encodingOptions);
} else {
try {
if (PHP_VERSION_ID < 50400) {
// PHP 5.3 triggers annoying warnings for some
// types that can't be serialized as JSON (INF, resources, etc.)
// but doesn't provide the JsonSerializable interface.
set_error_handler('var_dump', 0);
$data = @json_encode($data, $this->encodingOptions);
} else {
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
// objects in a new exception that needs to be removed.
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
if (PHP_VERSION_ID < 50500) {
// Clear json_last_error()
json_encode(null);
$errorHandler = set_error_handler('var_dump');
restore_error_handler();
set_error_handler(function () use ($errorHandler) {
if (JSON_ERROR_NONE === json_last_error()) {
return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args());
}
});
}

$data = json_encode($data, $this->encodingOptions);
}

if (PHP_VERSION_ID < 50500) {
restore_error_handler();
}
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
// objects in a new exception that needs to be removed.
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
$data = json_encode($data, $this->encodingOptions);
} catch (\Exception $e) {
if (PHP_VERSION_ID < 50500) {
restore_error_handler();
}
if (PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
throw $e->getPrevious() ?: $e;
}
throw $e;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -1247,6 +1247,7 @@ public static function closeOutputBuffers($targetLevel, $flush)
{
$status = ob_get_status(true);
$level = count($status);
// PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3
$flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1;

while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) {
Expand Down
Expand Up @@ -247,7 +247,7 @@ public function __destruct()

private function doDump($data, $name, $file, $line)
{
if (PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) {
if ($this->dumper instanceof CliDumper) {
$contextDumper = function ($name, $file, $line, $fileLinkFormat) {
if ($this instanceof HtmlDumper) {
if ('' !== $file) {
Expand Down
Expand Up @@ -71,11 +71,7 @@ public function testCollectDefault()
$collector->collect(new Request(), new Response());
$output = ob_get_clean();

if (PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output);
}
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
$this->assertSame(1, $collector->getDumpsCount());
$collector->serialize();
}
Expand All @@ -89,23 +85,12 @@ public function testCollectHtml()
$collector->dump($data);
$line = __LINE__ - 1;
$file = __FILE__;
if (PHP_VERSION_ID >= 50400) {
$xOutput = <<<EOTXT
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<span class=sf-dump-num>123</span>
</pre>
EOTXT;
} else {
$len = strlen("DumpDataCollectorTest.php on line {$line}:");
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" ">"<span class=sf-dump-str title="{$len} characters">DumpDataCollectorTest.php on line {$line}:</span>"
</pre>
<pre class=sf-dump id=sf-dump data-indent-pad=" "><span class=sf-dump-num>123</span>
</pre>
EOTXT;
}

ob_start();
$response = new Response();
Expand All @@ -129,10 +114,6 @@ public function testFlush()

ob_start();
$collector = null;
if (PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
}
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
}
}
Expand Up @@ -47,10 +47,7 @@ public function onAuthentication(Request $request, TokenInterface $token)
return;

case self::MIGRATE:
// Destroying the old session is broken in php 5.4.0 - 5.4.10
// See php bug #63379
$destroy = PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411;
$request->getSession()->migrate($destroy);
$request->getSession()->migrate(true);

return;

Expand Down
Expand Up @@ -39,30 +39,13 @@ public function testUnsupportedStrategy()

public function testSessionIsMigrated()
{
if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50411) {
$this->markTestSkipped('We cannot destroy the old session on PHP 5.4.0 - 5.4.10.');
}

$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));

$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
$strategy->onAuthentication($this->getRequest($session), $this->getToken());
}

public function testSessionIsMigratedWithPhp54Workaround()
{
if (PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411) {
$this->markTestSkipped('This PHP version is not affected.');
}

$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
$session->expects($this->once())->method('migrate')->with($this->equalTo(false));

$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
$strategy->onAuthentication($this->getRequest($session), $this->getToken());
}

public function testSessionIsInvalidated()
{
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
Expand Down

0 comments on commit 8797711

Please sign in to comment.