@@ -23,48 +23,32 @@ concrete subclasses, ``ConcreteComponent`` and ``ConcreteDecorator``.
23
23
24
24
namespace Test;
25
25
26
- /**
27
- * @Entity
28
- * @InheritanceType("SINGLE_TABLE")
29
- * @DiscriminatorColumn(name="discr", type="string")
30
- * @DiscriminatorMap({"cc" = "Test\Component\ConcreteComponent",
31
- "cd" = "Test\Decorator\ConcreteDecorator"})
32
- */
26
+ #[Entity]
27
+ #[InheritanceType('SINGLE_TABLE')]
28
+ #[DiscriminatorColumn(name: 'discr', type: 'string')]
29
+ #[DiscriminatorMap(['cc' => Component\ConcreteComponent::class,
30
+ 'cd' => Decorator\ConcreteDecorator::class])]
33
31
abstract class Component
34
32
{
35
33
36
- /**
37
- * @Id @Column(type="integer")
38
- * @GeneratedValue(strategy="AUTO")
39
- */
40
- protected $id;
34
+ #[Id, Column]
35
+ #[GeneratedValue(strategy: 'AUTO')]
36
+ protected int|null $id = null;
41
37
42
- /** @ Column(type=" string" , nullable= true) */
38
+ #[ Column(type: ' string' , nullable: true)]
43
39
protected $name;
44
40
45
- /**
46
- * Get id
47
- * @return integer $id
48
- */
49
- public function getId()
41
+ public function getId(): int|null
50
42
{
51
43
return $this->id;
52
44
}
53
45
54
- /**
55
- * Set name
56
- * @param string $name
57
- */
58
- public function setName($name)
46
+ public function setName(string $name): void
59
47
{
60
48
$this->name = $name;
61
49
}
62
50
63
- /**
64
- * Get name
65
- * @return string $name
66
- */
67
- public function getName()
51
+ public function getName(): string
68
52
{
69
53
return $this->name;
70
54
}
@@ -86,7 +70,7 @@ purpose of keeping this example simple).
86
70
87
71
use Test\Component;
88
72
89
- /** @ Entity */
73
+ #[ Entity]
90
74
class ConcreteComponent extends Component
91
75
{}
92
76
@@ -103,14 +87,11 @@ use a ``MappedSuperclass`` for this.
103
87
104
88
namespace Test;
105
89
106
- /** @ MappedSuperclass */
90
+ #[ MappedSuperclass]
107
91
abstract class Decorator extends Component
108
92
{
109
-
110
- /**
111
- * @OneToOne(targetEntity="Test\Component", cascade={"all"})
112
- * @JoinColumn(name="decorates", referencedColumnName="id")
113
- */
93
+ #[OneToOne(targetEntity: Component::class, cascade: ['all'])]
94
+ #[JoinColumn(name: 'decorates', referencedColumnName: 'id')]
114
95
protected $decorates;
115
96
116
97
/**
@@ -126,25 +107,19 @@ use a ``MappedSuperclass`` for this.
126
107
* (non-PHPdoc)
127
108
* @see Test.Component::getName()
128
109
*/
129
- public function getName()
110
+ public function getName(): string
130
111
{
131
112
return 'Decorated ' . $this->getDecorates()->getName();
132
113
}
133
114
134
- /**
135
- * the component being decorated
136
- * @return Component
137
- */
138
- protected function getDecorates()
115
+ /** the component being decorated */
116
+ protected function getDecorates(): Component
139
117
{
140
118
return $this->decorates;
141
119
}
142
120
143
- /**
144
- * sets the component being decorated
145
- * @param Component $c
146
- */
147
- protected function setDecorates(Component $c)
121
+ /** sets the component being decorated */
122
+ protected function setDecorates(Component $c): void
148
123
{
149
124
$this->decorates = $c;
150
125
}
@@ -187,27 +162,19 @@ of the getSpecial() method to its return value.
187
162
188
163
use Test\Decorator;
189
164
190
- /** @ Entity */
165
+ #[ Entity]
191
166
class ConcreteDecorator extends Decorator
192
167
{
193
168
194
- /** @ Column(type=" string" , nullable= true) */
195
- protected $special;
169
+ #[ Column(type: ' string' , nullable: true)]
170
+ protected string|null $special = null ;
196
171
197
- /**
198
- * Set special
199
- * @param string $special
200
- */
201
- public function setSpecial($special)
172
+ public function setSpecial(string|null $special): void
202
173
{
203
174
$this->special = $special;
204
175
}
205
176
206
- /**
207
- * Get special
208
- * @return string $special
209
- */
210
- public function getSpecial()
177
+ public function getSpecial(): string|null
211
178
{
212
179
return $this->special;
213
180
}
@@ -216,7 +183,7 @@ of the getSpecial() method to its return value.
216
183
* (non-PHPdoc)
217
184
* @see Test.Component::getName()
218
185
*/
219
- public function getName()
186
+ public function getName(): string
220
187
{
221
188
return '[' . $this->getSpecial()
222
189
. '] ' . parent::getName();
@@ -270,4 +237,3 @@ objects
270
237
271
238
echo $d->getName();
272
239
// prints: [Really] Decorated Test Component 2
273
-
0 commit comments