Skip to content

Commit 754d299

Browse files
committed
removed support for PHP 7
1 parent 0f5f9c1 commit 754d299

File tree

7 files changed

+36
-71
lines changed

7 files changed

+36
-71
lines changed

src/Application/UI/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function checkRequirements($element): void
130130
$element instanceof \ReflectionMethod
131131
&& substr($element->getName(), 0, 6) === 'handle'
132132
&& !ComponentReflection::parseAnnotation($element, 'crossOrigin')
133-
&& (PHP_VERSION_ID < 80000 || !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class))
133+
&& !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class)
134134
&& !$this->getPresenter()->getHttpRequest()->isSameSite()
135135
) {
136136
$this->getPresenter()->detectedCsrf();

src/Application/UI/ComponentReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getPersistentParams(string $class = null): array
5050
foreach ($defaults as $name => $default) {
5151
$rp = new \ReflectionProperty($class, $name);
5252
if (!$rp->isStatic()
53-
&& ((PHP_VERSION_ID >= 80000 && $rp->getAttributes(Nette\Application\Attributes\Persistent::class))
53+
&& ($rp->getAttributes(Nette\Application\Attributes\Persistent::class)
5454
|| self::parseAnnotation($rp, 'persistent'))
5555
) {
5656
$params[$name] = [
@@ -283,7 +283,7 @@ public static function getParameterType(\ReflectionParameter $param): string
283283

284284
public static function getPropertyType(\ReflectionProperty $prop, $default): string
285285
{
286-
$type = PHP_VERSION_ID < 70400 ? null : $prop->getType();
286+
$type = $prop->getType();
287287
return $type
288288
? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type)
289289
: ($default === null ? 'scalar' : gettype($default));

src/Application/UI/Link.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ public function isLinkCurrent(): bool
103103
*/
104104
public function __toString(): string
105105
{
106-
try {
107-
return $this->component->link($this->destination, $this->params);
108-
109-
} catch (\Throwable $e) {
110-
if (func_num_args() || PHP_VERSION_ID >= 70400) {
111-
throw $e;
112-
}
113-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
114-
return '';
115-
}
106+
return $this->component->link($this->destination, $this->params);
116107
}
117108
}

src/Application/UI/Presenter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,7 @@ public function restoreRequest(string $key): void
11381138
public static function getPersistentComponents(): array
11391139
{
11401140
$rc = new \ReflectionClass(static::class);
1141-
$attrs = PHP_VERSION_ID >= 80000
1142-
? $rc->getAttributes(Application\Attributes\Persistent::class)
1143-
: null;
1141+
$attrs = $rc->getAttributes(Application\Attributes\Persistent::class);
11441142
return $attrs
11451143
? $attrs[0]->getArguments()
11461144
: (array) ComponentReflection::parseAnnotation($rc, 'persistent');

src/Bridges/ApplicationLatte/Template.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,7 @@ public function renderToString(string $file = null, array $params = []): string
6363
*/
6464
public function __toString(): string
6565
{
66-
try {
67-
return $this->latte->renderToString($this->file, $this->getParameters());
68-
} catch (\Throwable $e) {
69-
if (func_num_args() || PHP_VERSION_ID >= 70400) {
70-
throw $e;
71-
}
72-
trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
73-
return '';
74-
}
66+
return $this->latte->renderToString($this->file, $this->getParameters());
7567
}
7668

7769

@@ -143,7 +135,7 @@ final public function getParameters(): array
143135
{
144136
$res = [];
145137
foreach ((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
146-
if (PHP_VERSION_ID < 70400 || $prop->isInitialized($this)) {
138+
if ($prop->isInitialized($this)) {
147139
$res[$prop->getName()] = $prop->getValue($this);
148140
}
149141
}

tests/UI/ComponentReflection.combineArgs.php80.phpt

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/UI/ComponentReflection.combineArgs.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class MyPresenter
5757
public function objects(stdClass $req, ?stdClass $nullable, stdClass $opt = null)
5858
{
5959
}
60+
61+
62+
public function hintsUnion(int|array $intArray, string|array $strArray)
63+
{
64+
}
6065
}
6166

6267

@@ -252,3 +257,27 @@ test('', function () {
252257
Reflection::combineArgs($method, ['req' => [], 'opt' => null]);
253258
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.');
254259
});
260+
261+
262+
test('', function () {
263+
$method = new ReflectionMethod('MyPresenter', 'hintsUnion');
264+
265+
Assert::same([1, 'abc'], Reflection::combineArgs($method, ['intArray' => '1', 'strArray' => 'abc']));
266+
Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]]));
267+
268+
Assert::exception(function () use ($method) {
269+
Reflection::combineArgs($method, []);
270+
}, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()');
271+
272+
Assert::exception(function () use ($method) {
273+
Reflection::combineArgs($method, ['intArray' => '']);
274+
}, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.');
275+
276+
Assert::exception(function () use ($method) {
277+
Reflection::combineArgs($method, ['intArray' => null]);
278+
}, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()');
279+
280+
Assert::exception(function () use ($method) {
281+
Reflection::combineArgs($method, ['intArray' => new stdClass]);
282+
}, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.');
283+
});

0 commit comments

Comments
 (0)