Skip to content

Commit d1b04a4

Browse files
committed
@annotations are deprecated (BC break)
1 parent 5743f06 commit d1b04a4

8 files changed

+47
-44
lines changed

src/Application/UI/ComponentReflection.php

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

2929

3030
/**
31-
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter] or annotation @persistent.
31+
* Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter].
3232
* @return array<string, array{def: mixed, type: string, since: ?string}>
3333
*/
3434
public function getParameters(): array
@@ -75,7 +75,7 @@ public function getParameters(): array
7575

7676

7777
/**
78-
* Returns array of persistent properties. They are public and have attribute #[Persistent] or annotation @persistent.
78+
* Returns array of persistent properties. They are public and have attribute #[Persistent].
7979
* @return array<string, array{def: mixed, type: string, since: string}>
8080
*/
8181
public function getPersistentParams(): array
@@ -189,6 +189,7 @@ public function getSignalMethod(string $signal): ?\ReflectionMethod
189189

190190
/**
191191
* Returns an annotation value.
192+
* @deprecated
192193
*/
193194
public static function parseAnnotation(\Reflector $ref, string $name): ?array
194195
{
@@ -206,12 +207,20 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
206207
}
207208
}
208209

210+
$alt = match ($name) {
211+
'persistent' => '#[Nette\Application\Attributes\Persistent]',
212+
'deprecated' => '#[Nette\Application\Attributes\Deprecated]',
213+
'crossOrigin' => '#[Nette\Application\Attributes\Request(sameOrigin: false)]',
214+
default => 'alternative'
215+
};
216+
trigger_error("Annotation @$name is deprecated, use $alt (used in " . Nette\Utils\Reflection::toString($ref) . ')', E_USER_DEPRECATED);
209217
return $res;
210218
}
211219

212220

213221
/**
214222
* Has class specified annotation?
223+
* @deprecated
215224
*/
216225
public function hasAnnotation(string $name): bool
217226
{
@@ -221,6 +230,7 @@ public function hasAnnotation(string $name): bool
221230

222231
/**
223232
* Returns an annotation value.
233+
* @deprecated
224234
*/
225235
public function getAnnotation(string $name): mixed
226236
{

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
}

tests/UI/ComponentReflection.getParameters().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OnePresenter extends Presenter
1616
public static $no1;
1717
public $no2;
1818

19-
/** @persistent */
19+
#[Persistent]
2020
public $yes1;
2121

2222
#[Persistent, Parameter]

tests/UI/ComponentReflection.getPersistentComponents().phpt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ class NonePresenter extends Presenter
1414
}
1515

1616

17-
/**
18-
* @persistent(a, b)
19-
*/
20-
class AnnotationPresenter extends Presenter
21-
{
22-
}
23-
24-
2517
#[Persistent('a', 'b')]
2618
class AttributePresenter extends Presenter
2719
{
@@ -39,11 +31,6 @@ class MethodPresenter extends AttributePresenter
3931

4032
Assert::same([], NonePresenter::getReflection()->getPersistentComponents());
4133

42-
Assert::same([
43-
'a' => ['since' => AnnotationPresenter::class],
44-
'b' => ['since' => AnnotationPresenter::class],
45-
], AnnotationPresenter::getReflection()->getPersistentComponents());
46-
4734
Assert::same([
4835
'a' => ['since' => AttributePresenter::class],
4936
'b' => ['since' => AttributePresenter::class],

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.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)