Skip to content

Commit 1e91675

Browse files
committed
@annotations are deprecated (BC break)
1 parent ec1cbb3 commit 1e91675

9 files changed

+49
-43
lines changed

src/Application/UI/ComponentReflection.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class ComponentReflection extends \ReflectionClass
2626

2727

2828
/**
29-
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter] or annotation @persistent.
29+
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter].
3030
*/
3131
public function getParameters(): array
3232
{
@@ -72,7 +72,7 @@ public function getParameters(): array
7272

7373

7474
/**
75-
* Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent.
75+
* Returns array of persistent properties. They are public and have attribute #[Persistent].
7676
*/
7777
public function getPersistentParams(): array
7878
{
@@ -251,6 +251,7 @@ private static function castScalar(mixed &$val, string $type): bool
251251

252252
/**
253253
* Returns an annotation value.
254+
* @deprecated
254255
*/
255256
public static function parseAnnotation(\Reflector $ref, string $name): ?array
256257
{
@@ -268,6 +269,13 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
268269
}
269270
}
270271

272+
$alt = match ($name) {
273+
'persistent' => '#[Nette\Application\Attributes\Persistent]',
274+
'deprecated' => '#[Nette\Application\Attributes\Deprecated]',
275+
'crossOrigin' => '#[Nette\Application\Attributes\Request(sameOrigin: false)]',
276+
default => 'alternative'
277+
};
278+
trigger_error("Annotation @$name is deprecated, use $alt (used in " . Nette\Utils\Reflection::toString($ref) . ')', E_USER_DEPRECATED);
271279
return $res;
272280
}
273281

@@ -286,6 +294,7 @@ public static function getType(\ReflectionParameter|\ReflectionProperty $item):
286294

287295
/**
288296
* Has class specified annotation?
297+
* @deprecated
289298
*/
290299
public function hasAnnotation(string $name): bool
291300
{
@@ -295,6 +304,7 @@ public function hasAnnotation(string $name): bool
295304

296305
/**
297306
* Returns an annotation value.
307+
* @deprecated
298308
*/
299309
public function getAnnotation(string $name): mixed
300310
{

src/Application/UI/MethodReflection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ final class MethodReflection extends \ReflectionMethod
1717
{
1818
/**
1919
* Has method specified annotation?
20+
* @deprecated
2021
*/
2122
public function hasAnnotation(string $name): bool
2223
{
24+
trigger_error(__METHOD__ . '() is deprecated', E_USER_DEPRECATED);
2325
return (bool) ComponentReflection::parseAnnotation($this, $name);
2426
}
2527

2628

2729
/**
2830
* Returns an annotation value.
31+
* @deprecated
2932
*/
3033
public function getAnnotation(string $name): mixed
3134
{
35+
trigger_error(__METHOD__ . '() is deprecated', E_USER_DEPRECATED);
3236
$res = ComponentReflection::parseAnnotation($this, $name);
3337
return $res ? end($res) : null;
3438
}

src/Application/UI/Presenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ public function restoreRequest(string $key): void
12191219

12201220
/**
12211221
* Returns array of persistent components.
1222-
* This default implementation detects components by class-level annotation @persistent(cmp1, cmp2).
1222+
* This default implementation detects components by class-level attribute #[Persistent(cmp1, cmp2)].
12231223
*/
12241224
public static function getPersistentComponents(): array
12251225
{

tests/UI/ComponentReflection.parseAnnotation.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class TestClass
3434

3535
$rc = new ReflectionClass('TestClass');
3636

37-
Assert::same(['value ="Johno\'s addendum"', 'mode=True', true, true], Reflection::parseAnnotation($rc, 'title'));
38-
Assert::null(Reflection::parseAnnotation($rc, 'public'));
39-
Assert::null(Reflection::parseAnnotation($rc, 'private'));
40-
Assert::same(['item 1'], Reflection::parseAnnotation($rc, 'components'));
41-
Assert::same([true, false, null], Reflection::parseAnnotation($rc, 'persistent'));
42-
Assert::same([true], Reflection::parseAnnotation($rc, 'renderable'));
43-
Assert::same(['loggedIn'], Reflection::parseAnnotation($rc, 'Secured\User'));
44-
Assert::null(Reflection::parseAnnotation($rc, 'missing'));
37+
Assert::same(['value ="Johno\'s addendum"', 'mode=True', true, true], @Reflection::parseAnnotation($rc, 'title'));
38+
Assert::null(@Reflection::parseAnnotation($rc, 'public'));
39+
Assert::null(@Reflection::parseAnnotation($rc, 'private'));
40+
Assert::same(['item 1'], @Reflection::parseAnnotation($rc, 'components'));
41+
Assert::same([true, false, null], @Reflection::parseAnnotation($rc, 'persistent'));
42+
Assert::same([true], @Reflection::parseAnnotation($rc, 'renderable'));
43+
Assert::same(['loggedIn'], @Reflection::parseAnnotation($rc, 'Secured\User'));
44+
Assert::null(@Reflection::parseAnnotation($rc, 'missing'));

tests/UI/Presenter.getParameters.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class OnePresenter extends Presenter
2020
public static $no1;
2121
public $no2;
2222

23-
/** @persistent */
23+
#[Persistent]
2424
public $yes1;
2525

2626
#[Persistent, Parameter]

tests/UI/Presenter.getPersistentComponents.phpt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,12 @@ class OnePresenter extends Presenter
1919
}
2020

2121

22-
/**
23-
* @persistent(a, b)
24-
*/
25-
class TwoPresenter extends Presenter
26-
{
27-
}
28-
29-
3022
#[Persistent('a', 'b')]
31-
class ThreePresenter extends Presenter
23+
class TwoPresenter extends Presenter
3224
{
3325
}
3426

3527

3628
Assert::same([], OnePresenter::getPersistentComponents());
3729

3830
Assert::same(['a', 'b'], TwoPresenter::getPersistentComponents());
39-
40-
Assert::same(['a', 'b'], ThreePresenter::getPersistentComponents());

tests/UI/Presenter.link().persistent.phpt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\Application;
10+
use Nette\Application\Attributes\Persistent;
1011
use Nette\Http;
1112
use Tester\Assert;
1213

@@ -16,13 +17,13 @@ require __DIR__ . '/../bootstrap.php';
1617

1718
trait PersistentParam1
1819
{
19-
/** @persistent */
20+
#[Persistent]
2021
public $t1;
2122
}
2223

2324
trait PersistentParam2A
2425
{
25-
/** @persistent */
26+
#[Persistent]
2627
public $t2;
2728
}
2829

@@ -33,15 +34,15 @@ trait PersistentParam2B
3334

3435
trait PersistentParam3
3536
{
36-
/** @persistent */
37+
#[Persistent]
3738
public $t3;
3839
}
3940

4041
class BasePresenter extends Application\UI\Presenter
4142
{
4243
use PersistentParam1;
4344

44-
/** @persistent */
45+
#[Persistent]
4546
public $p1;
4647
}
4748

@@ -50,7 +51,7 @@ class TestPresenter extends BasePresenter
5051
{
5152
use PersistentParam2B;
5253

53-
/** @persistent */
54+
#[Persistent]
5455
public $p2;
5556

5657

@@ -81,10 +82,10 @@ class SecondPresenter extends BasePresenter
8182
{
8283
use PersistentParam3;
8384

84-
/** @persistent */
85+
#[Persistent]
8586
public $p1 = 20;
8687

87-
/** @persistent */
88+
#[Persistent]
8889
public $p3;
8990
}
9091

@@ -97,7 +98,7 @@ class ThirdPresenter extends BasePresenter
9798

9899
class FourthPresenter extends BasePresenter
99100
{
100-
#[Application\Attributes\Persistent]
101+
#[Persistent]
101102
public $p1;
102103
}
103104

tests/UI/Presenter.link().phpt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\Application;
10+
use Nette\Application\Attributes\Persistent;
1011
use Nette\Http;
1112
use Tester\Assert;
1213

@@ -16,11 +17,11 @@ require __DIR__ . '/../bootstrap.php';
1617

1718
class TestControl extends Application\UI\Control
1819
{
19-
/** @persistent array */
20-
public $order = [];
20+
#[Persistent]
21+
public array $order = [];
2122

22-
/** @persistent int */
23-
public $round = 0;
23+
#[Persistent]
24+
public int $round = 0;
2425

2526

2627
public function handleClick($x, $y)
@@ -50,22 +51,22 @@ class TestControl extends Application\UI\Control
5051

5152
class TestPresenter extends Application\UI\Presenter
5253
{
53-
/** @persistent */
54+
#[Persistent]
5455
public $p;
5556

56-
/** @persistent */
57+
#[Persistent]
5758
public $pint = 10;
5859

59-
/** @persistent */
60+
#[Persistent]
6061
public $parr = [];
6162

62-
/** @persistent */
63+
#[Persistent]
6364
public $pbool = true;
6465

65-
/** @persistent */
66+
#[Persistent]
6667
public array $parrn;
6768

68-
/** @persistent */
69+
#[Persistent]
6970
public ?bool $pbooln = null;
7071

7172

@@ -294,7 +295,7 @@ class TestPresenter extends Application\UI\Presenter
294295

295296
class OtherPresenter extends TestPresenter
296297
{
297-
/** @persistent */
298+
#[Persistent]
298299
public $p = 20;
299300
}
300301

tests/UI/fixtures/ParamPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ParamPresenter extends Nette\Application\UI\Presenter
66
{
7-
/** @persistent */
7+
#[Nette\Application\Attributes\Persistent]
88
public $bool = true;
99

1010

0 commit comments

Comments
 (0)