|
1 | 1 | <?php |
2 | 2 |
|
3 | | -if (class_exists('Attribute', false)) { |
4 | | - return; |
5 | | -} |
| 3 | +if (\PHP_VERSION_ID < 80000) { |
| 4 | + if (class_exists('Attribute', false)) { |
| 5 | + return; |
| 6 | + } |
| 7 | + |
| 8 | + #[Attribute(Attribute::TARGET_CLASS)] |
| 9 | + class Attribute |
| 10 | + { |
6 | 11 |
|
7 | | -#[Attribute(Attribute::TARGET_CLASS)] |
8 | | -class Attribute |
9 | | -{ |
| 12 | + /** @var int */ |
| 13 | + public $flags; |
10 | 14 |
|
11 | | - /** @var int */ |
12 | | - public $flags; |
| 15 | + /** |
| 16 | + * Marks that attribute declaration is allowed only in classes. |
| 17 | + */ |
| 18 | + const TARGET_CLASS = 1; |
13 | 19 |
|
14 | | - /** |
15 | | - * Marks that attribute declaration is allowed only in classes. |
16 | | - */ |
17 | | - const TARGET_CLASS = 1; |
| 20 | + /** |
| 21 | + * Marks that attribute declaration is allowed only in functions. |
| 22 | + */ |
| 23 | + const TARGET_FUNCTION = 1 << 1; |
18 | 24 |
|
19 | | - /** |
20 | | - * Marks that attribute declaration is allowed only in functions. |
21 | | - */ |
22 | | - const TARGET_FUNCTION = 1 << 1; |
| 25 | + /** |
| 26 | + * Marks that attribute declaration is allowed only in class methods. |
| 27 | + */ |
| 28 | + const TARGET_METHOD = 1 << 2; |
23 | 29 |
|
24 | | - /** |
25 | | - * Marks that attribute declaration is allowed only in class methods. |
26 | | - */ |
27 | | - const TARGET_METHOD = 1 << 2; |
| 30 | + /** |
| 31 | + * Marks that attribute declaration is allowed only in class properties. |
| 32 | + */ |
| 33 | + const TARGET_PROPERTY = 1 << 3; |
28 | 34 |
|
29 | | - /** |
30 | | - * Marks that attribute declaration is allowed only in class properties. |
31 | | - */ |
32 | | - const TARGET_PROPERTY = 1 << 3; |
| 35 | + /** |
| 36 | + * Marks that attribute declaration is allowed only in class constants. |
| 37 | + */ |
| 38 | + const TARGET_CLASS_CONSTANT = 1 << 4; |
33 | 39 |
|
34 | | - /** |
35 | | - * Marks that attribute declaration is allowed only in class constants. |
36 | | - */ |
37 | | - const TARGET_CLASS_CONSTANT = 1 << 4; |
| 40 | + /** |
| 41 | + * Marks that attribute declaration is allowed only in function or method parameters. |
| 42 | + */ |
| 43 | + const TARGET_PARAMETER = 1 << 5; |
38 | 44 |
|
39 | | - /** |
40 | | - * Marks that attribute declaration is allowed only in function or method parameters. |
41 | | - */ |
42 | | - const TARGET_PARAMETER = 1 << 5; |
| 45 | + /** |
| 46 | + * Marks that attribute declaration is allowed anywhere. |
| 47 | + */ |
| 48 | + const TARGET_ALL = (1 << 6) - 1; |
43 | 49 |
|
44 | | - /** |
45 | | - * Marks that attribute declaration is allowed anywhere. |
46 | | - */ |
47 | | - const TARGET_ALL = (1 << 6) - 1; |
| 50 | + /** |
| 51 | + * Notes that an attribute declaration in the same place is |
| 52 | + * allowed multiple times. |
| 53 | + */ |
| 54 | + const IS_REPEATABLE = 1 << 10; |
48 | 55 |
|
49 | | - /** |
50 | | - * Notes that an attribute declaration in the same place is |
51 | | - * allowed multiple times. |
52 | | - */ |
53 | | - const IS_REPEATABLE = 1 << 10; |
| 56 | + /** |
| 57 | + * @param int $flags A value in the form of a bitmask indicating the places |
| 58 | + * where attributes can be defined. |
| 59 | + */ |
| 60 | + public function __construct($flags = self::TARGET_ALL) |
| 61 | + { |
| 62 | + $this->flags = $flags; |
| 63 | + } |
54 | 64 |
|
55 | | - /** |
56 | | - * @param int $flags A value in the form of a bitmask indicating the places |
57 | | - * where attributes can be defined. |
58 | | - */ |
59 | | - public function __construct($flags = self::TARGET_ALL) |
60 | | - { |
61 | | - $this->flags = $flags; |
62 | 65 | } |
63 | | - |
64 | 66 | } |
0 commit comments