Skip to content

Commit 5f4b76b

Browse files
authored
Merge pull request #10126 from greg0ire/migrate-docs-to-attributes
Modernize documentation code
2 parents 119c378 + 794777b commit 5f4b76b

24 files changed

+754
-945
lines changed

docs/en/cookbook/decorator-pattern.rst

+27-61
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,32 @@ concrete subclasses, ``ConcreteComponent`` and ``ConcreteDecorator``.
2323
2424
namespace Test;
2525
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])]
3331
abstract class Component
3432
{
3533
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;
4137
42-
/** @Column(type="string", nullable=true) */
38+
#[Column(type: 'string', nullable: true)]
4339
protected $name;
4440
45-
/**
46-
* Get id
47-
* @return integer $id
48-
*/
49-
public function getId()
41+
public function getId(): int|null
5042
{
5143
return $this->id;
5244
}
5345
54-
/**
55-
* Set name
56-
* @param string $name
57-
*/
58-
public function setName($name)
46+
public function setName(string $name): void
5947
{
6048
$this->name = $name;
6149
}
6250
63-
/**
64-
* Get name
65-
* @return string $name
66-
*/
67-
public function getName()
51+
public function getName(): string
6852
{
6953
return $this->name;
7054
}
@@ -86,7 +70,7 @@ purpose of keeping this example simple).
8670
8771
use Test\Component;
8872
89-
/** @Entity */
73+
#[Entity]
9074
class ConcreteComponent extends Component
9175
{}
9276
@@ -103,14 +87,11 @@ use a ``MappedSuperclass`` for this.
10387
10488
namespace Test;
10589
106-
/** @MappedSuperclass */
90+
#[MappedSuperclass]
10791
abstract class Decorator extends Component
10892
{
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')]
11495
protected $decorates;
11596
11697
/**
@@ -126,25 +107,19 @@ use a ``MappedSuperclass`` for this.
126107
* (non-PHPdoc)
127108
* @see Test.Component::getName()
128109
*/
129-
public function getName()
110+
public function getName(): string
130111
{
131112
return 'Decorated ' . $this->getDecorates()->getName();
132113
}
133114
134-
/**
135-
* the component being decorated
136-
* @return Component
137-
*/
138-
protected function getDecorates()
115+
/** the component being decorated */
116+
protected function getDecorates(): Component
139117
{
140118
return $this->decorates;
141119
}
142120
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
148123
{
149124
$this->decorates = $c;
150125
}
@@ -187,27 +162,19 @@ of the getSpecial() method to its return value.
187162
188163
use Test\Decorator;
189164
190-
/** @Entity */
165+
#[Entity]
191166
class ConcreteDecorator extends Decorator
192167
{
193168
194-
/** @Column(type="string", nullable=true) */
195-
protected $special;
169+
#[Column(type: 'string', nullable: true)]
170+
protected string|null $special = null;
196171
197-
/**
198-
* Set special
199-
* @param string $special
200-
*/
201-
public function setSpecial($special)
172+
public function setSpecial(string|null $special): void
202173
{
203174
$this->special = $special;
204175
}
205176
206-
/**
207-
* Get special
208-
* @return string $special
209-
*/
210-
public function getSpecial()
177+
public function getSpecial(): string|null
211178
{
212179
return $this->special;
213180
}
@@ -216,7 +183,7 @@ of the getSpecial() method to its return value.
216183
* (non-PHPdoc)
217184
* @see Test.Component::getName()
218185
*/
219-
public function getName()
186+
public function getName(): string
220187
{
221188
return '[' . $this->getSpecial()
222189
. '] ' . parent::getName();
@@ -270,4 +237,3 @@ objects
270237
271238
echo $d->getName();
272239
// prints: [Really] Decorated Test Component 2
273-

docs/en/cookbook/working-with-datetime.rst

+16-13
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ these comparisons are always made **BY REFERENCE**. That means the following cha
1515
.. code-block:: php
1616
1717
<?php
18-
/** @Entity */
18+
19+
use DateTime;
20+
21+
#[Entity]
1922
class Article
2023
{
21-
/** @Column(type="datetime") */
22-
private $updated;
24+
#[Column(type='datetime')]
25+
private DateTime $updated;
2326
24-
public function setUpdated()
27+
public function setUpdated(): void
2528
{
2629
// will NOT be saved in the database
2730
$this->updated->modify("now");
@@ -33,12 +36,14 @@ The way to go would be:
3336
.. code-block:: php
3437
3538
<?php
39+
use DateTime;
40+
3641
class Article
3742
{
38-
public function setUpdated()
43+
public function setUpdated(): void
3944
{
4045
// WILL be saved in the database
41-
$this->updated = new \DateTime("now");
46+
$this->updated = new DateTime("now");
4247
}
4348
}
4449
@@ -84,16 +89,14 @@ the UTC time at the time of the booking and the timezone the event happened in.
8489
8590
namespace DoctrineExtensions\DBAL\Types;
8691
92+
use DateTimeZone;
8793
use Doctrine\DBAL\Platforms\AbstractPlatform;
8894
use Doctrine\DBAL\Types\ConversionException;
8995
use Doctrine\DBAL\Types\DateTimeType;
9096
9197
class UTCDateTimeType extends DateTimeType
9298
{
93-
/**
94-
* @var \DateTimeZone
95-
*/
96-
private static $utc;
99+
private static DateTimeZone $utc;
97100
98101
public function convertToDatabaseValue($value, AbstractPlatform $platform)
99102
{
@@ -126,10 +129,10 @@ the UTC time at the time of the booking and the timezone the event happened in.
126129
127130
return $converted;
128131
}
129-
130-
private static function getUtc(): \DateTimeZone
132+
133+
private static function getUtc(): DateTimeZone
131134
{
132-
return self::$utc ?: self::$utc = new \DateTimeZone('UTC');
135+
return self::$utc ??= new DateTimeZone('UTC');
133136
}
134137
}
135138

docs/en/reference/advanced-configuration.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ There are currently 5 available implementations:
119119
- ``Doctrine\ORM\Mapping\Driver\YamlDriver``
120120
- ``Doctrine\ORM\Mapping\Driver\DriverChain``
121121

122-
Throughout the most part of this manual the AnnotationDriver is
123-
used in the examples. For information on the usage of the XmlDriver
124-
or YamlDriver please refer to the dedicated chapters
125-
``XML Mapping`` and ``YAML Mapping``.
122+
Throughout the most part of this manual the AttributeDriver is
123+
used in the examples. For information on the usage of the
124+
AnnotationDriver, XmlDriver or YamlDriver please refer to the dedicated
125+
chapters ``Annotation Reference``, ``XML Mapping`` and ``YAML Mapping``.
126126

127127
The annotation driver can be configured with a factory method on
128128
the ``Doctrine\ORM\Configuration``:

0 commit comments

Comments
 (0)