Permalink
Browse files

removed support for PHP 5.3

  • Loading branch information...
dg committed May 20, 2015
1 parent 2a84dff commit 88f5b5a6bb0808b98df7c476863934562a481a9b
@@ -38,15 +38,11 @@ public static function closure($callable, $m = NULL)
$callable = [$callable, '__invoke'];
}
if (PHP_VERSION_ID >= 50400) {
if (is_string($callable) && function_exists($callable)) {
$r = new \ReflectionFunction($callable);
return $r->getClosure();
} elseif (is_array($callable) && method_exists($callable[0], $callable[1])) {
$r = new \ReflectionMethod($callable[0], $callable[1]);
return $r->getClosure($callable[0]);
}
if (is_string($callable) && function_exists($callable)) {
return (new \ReflectionFunction($callable))->getClosure();
} elseif (is_array($callable) && method_exists($callable[0], $callable[1])) {
return (new \ReflectionMethod($callable[0], $callable[1]))->getClosure($callable[0]);
}
self::check($callable);
@@ -53,8 +53,7 @@ public static function from($time)
if ($time <= self::YEAR) {
$time += time();
}
$tmp = new static('@' . $time);
return $tmp->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
return (new static('@' . $time))->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
} else { // textual or NULL
return new static($time);
@@ -86,19 +86,19 @@
class Image extends Nette\Object
{
/** {@link resize()} only shrinks images */
const SHRINK_ONLY = 1;
const SHRINK_ONLY = 0b0001;
/** {@link resize()} will ignore aspect ratio */
const STRETCH = 2;
const STRETCH = 0b0010;
/** {@link resize()} fits in given area so its dimensions are less than or equal to the required dimensions */
const FIT = 0;
const FIT = 0b0000;
/** {@link resize()} fills given area so its dimensions are greater than or equal to the required dimensions */
const FILL = 4;
const FILL = 0b0100;
/** {@link resize()} fills given area exactly */
const EXACT = 8;
const EXACT = 0b1000;
/** @int image types {@link send()} */
const JPEG = IMAGETYPE_JPEG,
@@ -17,16 +17,16 @@
*/
class Json
{
const FORCE_ARRAY = 1;
const PRETTY = 2;
const FORCE_ARRAY = 0b0001;
const PRETTY = 0b0010;
/** @var array */
private static $messages = [
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_STATE_MISMATCH => 'Syntax error, malformed JSON',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
5 /*JSON_ERROR_UTF8*/ => 'Invalid UTF-8 sequence', // exists since 5.3.3, but is returned since 5.3.1
JSON_ERROR_UTF8 => 'Invalid UTF-8 sequence',
];
@@ -47,7 +47,7 @@ class Json
*/
public static function encode($value, $options = 0)
{
$flags = PHP_VERSION_ID >= 50400 ? (JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | ($options & self::PRETTY ? JSON_PRETTY_PRINT : 0)) : 0;
$flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | ($options & self::PRETTY ? JSON_PRETTY_PRINT : 0);
if (PHP_VERSION_ID < 50500) {
$json = Callback::invokeSafe('json_encode', [$value, $flags], function($message) { // needed to receive 'recursion detected' error
@@ -77,16 +77,16 @@ public static function encode($value, $options = 0)
public static function decode($json, $options = 0)
{
$json = (string) $json;
if (!preg_match('##u', $json)) {
throw new JsonException('Invalid UTF-8 sequence', 5); // workaround for PHP < 5.3.3 & PECL JSON-C
if (defined('JSON_C_VERSION') && !preg_match('##u', $json)) {
throw new JsonException('Invalid UTF-8 sequence', 5);
}
$forceArray = (bool) ($options & self::FORCE_ARRAY);
if (!$forceArray && preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#', $json)) { // workaround for json_decode fatal error when object key starts with \u0000
throw new JsonException(static::$messages[JSON_ERROR_CTRL_CHAR]);
}
$args = [$json, $forceArray, 512];
if (PHP_VERSION_ID >= 50400 && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) { // not implemented in PECL JSON-C 1.3.2 for 64bit systems
if (!defined('JSON_C_VERSION') || PHP_INT_SIZE === 4) { // not implemented in PECL JSON-C 1.3.2 for 64bit systems
$args[] = JSON_BIGINT_AS_STRING;
}
$value = call_user_func_array('json_decode', $args);
@@ -103,8 +103,7 @@ public static function extensionMethod($name, $callback = NULL)
$class = get_called_class();
} else {
list($class, $name) = explode('::', $name);
$rc = new \ReflectionClass($class);
$class = $rc->getName();
$class = (new \ReflectionClass($class))->getName();
}
if ($callback === NULL) {
return ObjectMixin::getExtensionMethod($class, $name);
@@ -130,8 +130,7 @@ public static function & get($_this, $name)
} elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) { // property getter
if ($methods[$m] === 0) {
$rm = new \ReflectionMethod($class, $m);
$methods[$m] = $rm->returnsReference();
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
if ($methods[$m] === TRUE) {
return $_this->$m();
@@ -31,12 +31,10 @@ public static function generate($length = 10, $charlist = '0-9a-z')
}, $charlist));
$chLen = strlen($charlist);
if (function_exists('openssl_random_pseudo_bytes')
&& (PHP_VERSION_ID >= 50400 || !defined('PHP_WINDOWS_VERSION_BUILD')) // slow in PHP 5.3 & Windows
) {
if (function_exists('openssl_random_pseudo_bytes')) {
$rand3 = openssl_random_pseudo_bytes($length);
}
if (empty($rand3) && function_exists('mcrypt_create_iv') && (PHP_VERSION_ID >= 50307 || !defined('PHP_WINDOWS_VERSION_BUILD'))) { // PHP bug #52523
if (empty($rand3) && function_exists('mcrypt_create_iv')) {
$rand3 = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}
if (empty($rand3) && @is_readable('/dev/urandom')) {
@@ -46,11 +46,7 @@ public static function checkEncoding($s)
public static function fixEncoding($s)
{
// removes xD800-xDFFF, x110000 and higher
if (PHP_VERSION_ID < 50400) {
return @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', $s)); // intentionally @
} else {
return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
}
return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
}
@@ -281,7 +281,7 @@ public static function isUri($value)
*/
public static function isType($type)
{
return class_exists($type) || interface_exists($type) || (PHP_VERSION_ID >= 50400 && trait_exists($type));
return class_exists($type) || interface_exists($type) || trait_exists($type);
}
@@ -140,14 +140,10 @@ test(function() { // object methods
Assert::same( 'Test::privateFun', getName(Callback::toReflection([$test, 'privateFun'])) );
Assert::same( 'Test::privateFun', getName(Callback::toReflection(Callback::closure($test, 'privateFun'))) );
if (PHP_VERSION_ID < 50400) {
Assert::same( 'Test::__call privateFun *', Callback::closure($test, 'privateFun')->__invoke('*') ); // not called!
} else {
Assert::same( 'Test::privateFun*', Callback::closure($test, 'privateFun')->__invoke('*') );
Assert::same( 'Test::privateFun*', Callback::closure($test, 'privateFun')->__invoke('*') );
Assert::same( 'Test::ref', call_user_func_array(Callback::closure($test, 'ref'), [& $res]) );
Assert::same( 'Test::ref', $res );
}
Assert::same( 'Test::ref', call_user_func_array(Callback::closure($test, 'ref'), [& $res]) );
Assert::same( 'Test::ref', $res );
});
@@ -177,11 +173,7 @@ test(function() { // static methods
Assert::same( 'Test::privateStatic', getName(Callback::toReflection('Test::privateStatic')) );
Assert::same( 'Test::privateStatic', getName(Callback::toReflection(Callback::closure('Test::privateStatic'))) );
if (PHP_VERSION_ID < 50400) {
Assert::same( 'Test::__callStatic privateStatic *', Callback::closure('Test::privateStatic')->__invoke('*') ); // not called!
} else {
Assert::same( 'Test::privateStatic*', Callback::closure('Test::privateStatic')->__invoke('*') );
}
Assert::same( 'Test::privateStatic*', Callback::closure('Test::privateStatic')->__invoke('*') );
});
@@ -52,17 +52,15 @@ Assert::exception(function() {
// default JSON_BIGINT_AS_STRING
if (PHP_VERSION_ID >= 50400) {
if (defined('JSON_C_VERSION')) {
if (PHP_INT_SIZE > 4) {
# 64-bit
Assert::same( [9223372036854775807], Json::decode('[12345678901234567890]') ); # trimmed to max 64-bit integer
} else {
# 32-bit
Assert::same( ['9223372036854775807'], Json::decode('[12345678901234567890]') ); # trimmed to max 64-bit integer
}
if (defined('JSON_C_VERSION')) {
if (PHP_INT_SIZE > 4) {
# 64-bit
Assert::same( [9223372036854775807], Json::decode('[12345678901234567890]') ); # trimmed to max 64-bit integer
} else {
Assert::same( ['12345678901234567890'], Json::decode('[12345678901234567890]') );
# 32-bit
Assert::same( ['9223372036854775807'], Json::decode('[12345678901234567890]') ); # trimmed to max 64-bit integer
}
} else {
Assert::same( ['12345678901234567890'], Json::decode('[12345678901234567890]') );
}
@@ -26,14 +26,12 @@ Assert::exception(function() {
}, 'Nette\Utils\JsonException', '%a?%ecursion detected');
if (PHP_VERSION_ID >= 50400) {
// default JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES
Assert::same( "\"/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n\"", Json::encode("/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n") );
Assert::same( '"\u2028\u2029"', Json::encode("\xe2\x80\xa8\xe2\x80\xa9") );
// default JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES
Assert::same( "\"/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n\"", Json::encode("/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n") );
Assert::same( '"\u2028\u2029"', Json::encode("\xe2\x80\xa8\xe2\x80\xa9") );
// JSON_PRETTY_PRINT
Assert::same( "[\n 1,\n 2,\n 3\n]", Json::encode([1,2,3,], Json::PRETTY) );
}
// JSON_PRETTY_PRINT
Assert::same( "[\n 1,\n 2,\n 3\n]", Json::encode([1,2,3,], Json::PRETTY) );
if (PHP_VERSION_ID >= 50500) {
@@ -34,7 +34,7 @@ Assert::exception(function() {
Assert::exception(function() {
$obj = new TestClass;
$obj->abc();
}, 'Nette\MemberAccessException', PHP_VERSION_ID != 50303 ? 'Call to undefined method parent::abc().' : 'Call to undefined static method TestClass::abc().'); // PHP bug #52713 (exclusive to PHP 5.3.3)
}, 'Nette\MemberAccessException', 'Call to undefined method parent::abc().');
// Wrong parameters count
@@ -38,12 +38,10 @@ $obj1 = new TestClass(1);
$method = $obj1->publicMethod;
Assert::same( "1 2 3", $method(2, 3) );
if (PHP_VERSION_ID >= 50400) {
$rm = new ReflectionFunction($method);
Assert::same( $obj1, $rm->getClosureThis() );
Assert::same( 'publicMethod', $rm->getName() );
Assert::same( 2, $rm->getNumberOfParameters() );
}
$rm = new ReflectionFunction($method);
Assert::same( $obj1, $rm->getClosureThis() );
Assert::same( 'publicMethod', $rm->getName() );
Assert::same( 2, $rm->getNumberOfParameters() );
Assert::exception(function() {
@@ -14,6 +14,4 @@ require __DIR__ . '/../bootstrap.php';
Assert::true( Strings::checkEncoding("\xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd") ); // UTF-8 ΕΎluΕ₯oučkΓ½
Assert::true( Strings::checkEncoding("\x01") ); // C0
Assert::false( Strings::checkEncoding("\xed\xa0\x80") ); // surrogate pairs xD800
if (PHP_VERSION_ID > 50303) {
Assert::false( Strings::checkEncoding("\xf4\x90\x80\x80") ); // out of range x110000
}
Assert::false( Strings::checkEncoding("\xf4\x90\x80\x80") ); // out of range x110000
@@ -362,12 +362,6 @@ $tests = [
],
];
if (PHP_VERSION_ID < 50400 && trim(ICONV_IMPL, '"') === 'libiconv') {
unset($tests['3 Malformed sequences']['3.2 Lonely start characters']);
}
if (PHP_VERSION_ID < 50400 && trim(ICONV_IMPL, '"') === 'libiconv') {
unset($tests['5 Illegal code positions']['5.3 Other illegal code positions']['5.3.1 U+FFFE = ef bf be']);
}
$stack = [$tests];
while ($item = array_pop($stack)) {

0 comments on commit 88f5b5a

Please sign in to comment.