Skip to content

Commit 334430d

Browse files
committed
removed PHP < 7 support
1 parent 490dad8 commit 334430d

File tree

6 files changed

+8
-79
lines changed

6 files changed

+8
-79
lines changed

src/Utils/Html.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,8 @@ public function __toString()
559559
try {
560560
return $this->render();
561561
} catch (\Throwable $e) {
562-
} catch (\Exception $e) {
562+
trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
563563
}
564-
trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
565564
}
566565

567566

src/Utils/Image.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,7 @@ public function crop($left, $top, $width, $height)
390390
{
391391
list($r['x'], $r['y'], $r['width'], $r['height'])
392392
= static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
393-
if (PHP_VERSION_ID > 50611) { // PHP bug #67447
394-
$this->image = imagecrop($this->image, $r);
395-
} else {
396-
$newImage = static::fromBlank($r['width'], $r['height'], self::RGB(0, 0, 0, 127))->getImageResource();
397-
imagecopy($newImage, $this->image, 0, 0, $r['x'], $r['y'], $r['width'], $r['height']);
398-
$this->image = $newImage;
399-
}
393+
$this->image = imagecrop($this->image, $r);
400394
return $this;
401395
}
402396

@@ -574,9 +568,6 @@ public function __toString()
574568
try {
575569
return $this->toString();
576570
} catch (\Throwable $e) {
577-
} catch (\Exception $e) {
578-
}
579-
if (isset($e)) {
580571
if (func_num_args()) {
581572
throw $e;
582573
}

src/Utils/Json.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,7 @@ public static function encode($value, $options = 0)
5555
public static function decode($json, $options = 0)
5656
{
5757
$forceArray = (bool) ($options & self::FORCE_ARRAY);
58-
$flags = JSON_BIGINT_AS_STRING;
59-
60-
if (PHP_VERSION_ID < 70000) {
61-
$json = (string) $json;
62-
if ($json === '') {
63-
throw new JsonException('Syntax error');
64-
} elseif (!$forceArray && preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#', $json)) {
65-
throw new JsonException('The decoded property name is invalid'); // fatal error when object key starts with \u0000
66-
} elseif (defined('JSON_C_VERSION') && !preg_match('##u', $json)) {
67-
throw new JsonException('Invalid UTF-8 sequence', 5);
68-
} elseif (defined('JSON_C_VERSION') && PHP_INT_SIZE === 8) {
69-
$flags &= ~JSON_BIGINT_AS_STRING; // not implemented in PECL JSON-C 1.3.2 for 64bit systems
70-
}
71-
}
72-
73-
$value = json_decode($json, $forceArray, 512, $flags);
58+
$value = json_decode($json, $forceArray, 512, JSON_BIGINT_AS_STRING);
7459
if ($error = json_last_error()) {
7560
throw new JsonException(json_last_error_msg(), $error);
7661
}

src/Utils/Random.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,8 @@ public static function generate($length = 10, $charlist = '0-9a-z')
3737
}
3838

3939
$res = '';
40-
if (PHP_VERSION_ID >= 70000) {
41-
for ($i = 0; $i < $length; $i++) {
42-
$res .= $charlist[random_int(0, $chLen - 1)];
43-
}
44-
return $res;
45-
}
46-
47-
$bytes = '';
48-
if (function_exists('openssl_random_pseudo_bytes')) {
49-
$bytes = (string) openssl_random_pseudo_bytes($length, $secure);
50-
if (!$secure) {
51-
$bytes = '';
52-
}
53-
}
54-
if (strlen($bytes) < $length && function_exists('mcrypt_create_iv')) {
55-
$bytes = (string) mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
56-
}
57-
if (strlen($bytes) < $length && !defined('PHP_WINDOWS_VERSION_BUILD') && is_readable('/dev/urandom')) {
58-
$bytes = (string) file_get_contents('/dev/urandom', FALSE, NULL, -1, $length);
59-
}
60-
if (strlen($bytes) < $length) {
61-
$rand3 = md5(serialize($_SERVER), TRUE);
62-
$charlist = str_shuffle($charlist);
63-
for ($i = 0; $i < $length; $i++) {
64-
if ($i % 5 === 0) {
65-
list($rand1, $rand2) = explode(' ', microtime());
66-
$rand1 += lcg_value();
67-
}
68-
$rand1 *= $chLen;
69-
$res .= $charlist[($rand1 + $rand2 + ord($rand3[$i % strlen($rand3)])) % $chLen];
70-
$rand1 -= (int) $rand1;
71-
}
72-
return $res;
73-
}
74-
7540
for ($i = 0; $i < $length; $i++) {
76-
$res .= $charlist[($i + ord($bytes[$i])) % $chLen];
41+
$res .= $charlist[random_int(0, $chLen - 1)];
7742
}
7843
return $res;
7944
}

src/Utils/Reflection.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function isBuiltinType($type)
3838
*/
3939
public static function getReturnType(\ReflectionFunctionAbstract $func)
4040
{
41-
if (PHP_VERSION_ID >= 70000 && $func->hasReturnType()) {
41+
if ($func->hasReturnType()) {
4242
$type = (string) $func->getReturnType();
4343
return strtolower($type) === 'self' ? $func->getDeclaringClass()->getName() : $type;
4444
}
@@ -50,20 +50,9 @@ public static function getReturnType(\ReflectionFunctionAbstract $func)
5050
*/
5151
public static function getParameterType(\ReflectionParameter $param)
5252
{
53-
if (PHP_VERSION_ID >= 70000) {
54-
$type = $param->hasType() ? (string) $param->getType() : NULL;
53+
if ($param->hasType()) {
54+
$type = (string) $param->getType();
5555
return strtolower($type) === 'self' ? $param->getDeclaringClass()->getName() : $type;
56-
} elseif ($param->isArray() || $param->isCallable()) {
57-
return $param->isArray() ? 'array' : 'callable';
58-
} else {
59-
try {
60-
return ($ref = $param->getClass()) ? $ref->getName() : NULL;
61-
} catch (\ReflectionException $e) {
62-
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
63-
return $m[1];
64-
}
65-
throw $e;
66-
}
6756
}
6857
}
6958

tests/Utils/Json.decode().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Assert::exception(function () {
3737

3838
Assert::exception(function () {
3939
Json::decode('{}}');
40-
}, Nette\Utils\JsonException::class, PHP_VERSION_ID < 70000 ? 'State mismatch (invalid or malformed JSON)' : 'Syntax error');
40+
}, Nette\Utils\JsonException::class, 'Syntax error');
4141

4242

4343
Assert::exception(function () {

0 commit comments

Comments
 (0)