Skip to content

Commit 043552d

Browse files
authored
Deprecate annotations support (#2772)
* Deprecate annotations support * Reverse the inheritance chain for the annotation and attribute driver interfaces * Flip the inheritance chain between annotation and attribute drivers for the extensions * Fill in links for deprecations * Refresh PHPStan
1 parent a1c2a91 commit 043552d

File tree

34 files changed

+1551
-1401
lines changed

34 files changed

+1551
-1401
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ a release.
1818
---
1919

2020
## [Unreleased]
21+
### Deprecated
22+
- Support for `doctrine/annotations` has been deprecated and will be removed in 4.0.
23+
2124
### Fixed
2225
- Tree: Cascade remove not being triggered on entity children at `MaterializedPath::removeNode()`.
2326

phpstan-baseline.neon

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ parameters:
2121
path: src/AbstractTrackingListener.php
2222

2323
-
24-
message: "#^Access to an undefined property object\\:\\:\\$value\\.$#"
24+
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
2525
count: 1
26-
path: src/Blameable/Mapping/Driver/Annotation.php
26+
path: src/Blameable/Mapping/Driver/Attribute.php
2727

2828
-
29-
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
29+
message: "#^Property Gedmo\\\\Mapping\\\\Annotation\\\\Blameable\\:\\:\\$field \\(array\\<string\\>\\|string\\) in isset\\(\\) is not nullable\\.$#"
3030
count: 1
31-
path: src/Blameable/Mapping/Driver/Annotation.php
31+
path: src/Blameable/Mapping/Driver/Attribute.php
3232

3333
-
3434
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getFieldMapping\\(\\)\\.$#"
@@ -45,15 +45,10 @@ parameters:
4545
count: 2
4646
path: src/DoctrineExtensions.php
4747

48-
-
49-
message: "#^Access to an undefined property object\\:\\:\\$value\\.$#"
50-
count: 1
51-
path: src/IpTraceable/Mapping/Driver/Annotation.php
52-
5348
-
5449
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
5550
count: 1
56-
path: src/IpTraceable/Mapping/Driver/Annotation.php
51+
path: src/IpTraceable/Mapping/Driver/Attribute.php
5752

5853
-
5954
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getFieldMapping\\(\\)\\.$#"
@@ -223,7 +218,7 @@ parameters:
223218
-
224219
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
225220
count: 1
226-
path: src/References/Mapping/Driver/Annotation.php
221+
path: src/References/Mapping/Driver/Attribute.php
227222

228223
-
229224
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getReflectionProperty\\(\\)\\.$#"
@@ -333,7 +328,7 @@ parameters:
333328
-
334329
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
335330
count: 1
336-
path: src/Sluggable/Mapping/Driver/Annotation.php
331+
path: src/Sluggable/Mapping/Driver/Attribute.php
337332

338333
-
339334
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
@@ -413,7 +408,7 @@ parameters:
413408
-
414409
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
415410
count: 1
416-
path: src/Sortable/Mapping/Driver/Annotation.php
411+
path: src/Sortable/Mapping/Driver/Attribute.php
417412

418413
-
419414
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getFieldMapping\\(\\)\\.$#"
@@ -451,14 +446,14 @@ parameters:
451446
path: src/Sortable/SortableListener.php
452447

453448
-
454-
message: "#^Access to an undefined property object\\:\\:\\$value\\.$#"
449+
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
455450
count: 1
456-
path: src/Timestampable/Mapping/Driver/Annotation.php
451+
path: src/Timestampable/Mapping/Driver/Attribute.php
457452

458453
-
459-
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
454+
message: "#^Property Gedmo\\\\Mapping\\\\Annotation\\\\Timestampable\\:\\:\\$field \\(array\\<string\\>\\|string\\) in isset\\(\\) is not nullable\\.$#"
460455
count: 1
461-
path: src/Timestampable/Mapping/Driver/Annotation.php
456+
path: src/Timestampable/Mapping/Driver/Attribute.php
462457

463458
-
464459
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getFieldMapping\\(\\)\\.$#"
@@ -513,7 +508,7 @@ parameters:
513508
-
514509
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
515510
count: 1
516-
path: src/Translatable/Mapping/Driver/Annotation.php
511+
path: src/Translatable/Mapping/Driver/Attribute.php
517512

518513
-
519514
message: "#^Access to offset 'association' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\FieldMapping\\.$#"
@@ -628,7 +623,7 @@ parameters:
628623
-
629624
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
630625
count: 1
631-
path: src/Tree/Mapping/Driver/Annotation.php
626+
path: src/Tree/Mapping/Driver/Attribute.php
632627

633628
-
634629
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:getFieldMapping\\(\\)\\.$#"
@@ -803,7 +798,7 @@ parameters:
803798
-
804799
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
805800
count: 1
806-
path: tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php
801+
path: tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php
807802

808803
-
809804
message: "#^Instantiated class Doctrine\\\\ORM\\\\Mapping\\\\Driver\\\\AnnotationDriver not found\\.$#"

src/Blameable/Mapping/Driver/Annotation.php

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,15 @@
99

1010
namespace Gedmo\Blameable\Mapping\Driver;
1111

12-
use Gedmo\Exception\InvalidMappingException;
13-
use Gedmo\Mapping\Annotation\Blameable;
14-
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
12+
use Gedmo\Mapping\Driver\AnnotationDriverInterface;
1513

1614
/**
17-
* This is an annotation mapping driver for Blameable
18-
* behavioral extension. Used for extraction of extended
19-
* metadata from Annotations specifically for Blameable
20-
* extension.
15+
* Mapping driver for the blamable extension which reads extended metadata from annotations on a blamable class.
2116
*
22-
* @author David Buchmann <[email protected]>
17+
* @deprecated since gedmo/doctrine-extensions 3.16, will be removed in version 4.0.
2318
*
2419
* @internal
2520
*/
26-
class Annotation extends AbstractAnnotationDriver
21+
class Annotation extends Attribute implements AnnotationDriverInterface
2722
{
28-
/**
29-
* Annotation field is blameable
30-
*/
31-
public const BLAMEABLE = Blameable::class;
32-
33-
/**
34-
* List of types which are valid for blame
35-
*
36-
* @var string[]
37-
*/
38-
protected $validTypes = [
39-
'one',
40-
'string',
41-
'int',
42-
'ulid',
43-
'uuid',
44-
'ascii_string',
45-
];
46-
47-
public function readExtendedMetadata($meta, array &$config)
48-
{
49-
$class = $this->getMetaReflectionClass($meta);
50-
// property annotations
51-
foreach ($class->getProperties() as $property) {
52-
if ($meta->isMappedSuperclass && !$property->isPrivate()
53-
|| $meta->isInheritedField($property->name)
54-
|| isset($meta->associationMappings[$property->name]['inherited'])
55-
) {
56-
continue;
57-
}
58-
if ($blameable = $this->reader->getPropertyAnnotation($property, self::BLAMEABLE)) {
59-
$field = $property->getName();
60-
61-
if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
62-
throw new InvalidMappingException("Unable to find blameable [{$field}] as mapped property in entity - {$meta->getName()}");
63-
}
64-
if ($meta->hasField($field)) {
65-
if (!$this->isValidField($meta, $field)) {
66-
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a one-to-many relation in class - {$meta->getName()}");
67-
}
68-
} else {
69-
// association
70-
if (!$meta->isSingleValuedAssociation($field)) {
71-
throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}");
72-
}
73-
}
74-
if (!in_array($blameable->on, ['update', 'create', 'change'], true)) {
75-
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->getName()}");
76-
}
77-
if ('change' === $blameable->on) {
78-
if (!isset($blameable->field)) {
79-
throw new InvalidMappingException("Missing parameters on property - {$field}, field must be set on [change] trigger in class - {$meta->getName()}");
80-
}
81-
if (is_array($blameable->field) && isset($blameable->value)) {
82-
throw new InvalidMappingException('Blameable extension does not support multiple value changeset detection yet.');
83-
}
84-
$field = [
85-
'field' => $field,
86-
'trackedField' => $blameable->field,
87-
'value' => $blameable->value,
88-
];
89-
}
90-
// properties are unique and mapper checks that, no risk here
91-
$config[$blameable->on][] = $field;
92-
}
93-
}
94-
95-
return $config;
96-
}
9723
}

src/Blameable/Mapping/Driver/Attribute.php

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,95 @@
99

1010
namespace Gedmo\Blameable\Mapping\Driver;
1111

12-
use Gedmo\Mapping\Driver\AttributeDriverInterface;
12+
use Gedmo\Exception\InvalidMappingException;
13+
use Gedmo\Mapping\Annotation\Blameable;
14+
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
1315

1416
/**
15-
* This is an attribute mapping driver for Blameable
16-
* behavioral extension. Used for extraction of extended
17-
* metadata from attribute specifically for Blameable
18-
* extension.
17+
* Mapping driver for the blameable extension which reads extended metadata from attributes on a blameable class.
18+
*
19+
* @author David Buchmann <[email protected]>
1920
*
2021
* @internal
2122
*/
22-
final class Attribute extends Annotation implements AttributeDriverInterface
23+
class Attribute extends AbstractAnnotationDriver
2324
{
25+
/**
26+
* Mapping object for the blameable extension.
27+
*/
28+
public const BLAMEABLE = Blameable::class;
29+
30+
/**
31+
* List of types which are valid for blame
32+
*
33+
* @var string[]
34+
*/
35+
protected $validTypes = [
36+
'one',
37+
'string',
38+
'int',
39+
'ulid',
40+
'uuid',
41+
'ascii_string',
42+
];
43+
44+
public function readExtendedMetadata($meta, array &$config)
45+
{
46+
$class = $this->getMetaReflectionClass($meta);
47+
48+
// property annotations
49+
foreach ($class->getProperties() as $property) {
50+
if ($meta->isMappedSuperclass && !$property->isPrivate()
51+
|| $meta->isInheritedField($property->name)
52+
|| isset($meta->associationMappings[$property->name]['inherited'])
53+
) {
54+
continue;
55+
}
56+
57+
if ($blameable = $this->reader->getPropertyAnnotation($property, self::BLAMEABLE)) {
58+
\assert($blameable instanceof Blameable);
59+
60+
$field = $property->getName();
61+
62+
if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
63+
throw new InvalidMappingException("Unable to find blameable [{$field}] as mapped property in entity - {$meta->getName()}");
64+
}
65+
66+
if ($meta->hasField($field)) {
67+
if (!$this->isValidField($meta, $field)) {
68+
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a one-to-many relation in class - {$meta->getName()}");
69+
}
70+
} else {
71+
// association
72+
if (!$meta->isSingleValuedAssociation($field)) {
73+
throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}");
74+
}
75+
}
76+
77+
if (!in_array($blameable->on, ['update', 'create', 'change'], true)) {
78+
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->getName()}");
79+
}
80+
81+
if ('change' === $blameable->on) {
82+
if (!isset($blameable->field)) {
83+
throw new InvalidMappingException("Missing parameters on property - {$field}, field must be set on [change] trigger in class - {$meta->getName()}");
84+
}
85+
86+
if (is_array($blameable->field) && isset($blameable->value)) {
87+
throw new InvalidMappingException('Blameable extension does not support multiple value changeset detection yet.');
88+
}
89+
90+
$field = [
91+
'field' => $field,
92+
'trackedField' => $blameable->field,
93+
'value' => $blameable->value,
94+
];
95+
}
96+
// properties are unique and mapper checks that, no risk here
97+
$config[$blameable->on][] = $field;
98+
}
99+
}
100+
101+
return $config;
102+
}
24103
}

src/IpTraceable/Mapping/Driver/Annotation.php

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,15 @@
99

1010
namespace Gedmo\IpTraceable\Mapping\Driver;
1111

12-
use Gedmo\Exception\InvalidMappingException;
13-
use Gedmo\Mapping\Annotation\IpTraceable;
14-
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
12+
use Gedmo\Mapping\Driver\AnnotationDriverInterface;
1513

1614
/**
17-
* This is an annotation mapping driver for IpTraceable
18-
* behavioral extension. Used for extraction of extended
19-
* metadata from Annotations specifically for IpTraceable
20-
* extension.
15+
* Mapping driver for the IP traceable extension which reads extended metadata from annotations on an IP traceable class.
2116
*
22-
* @author Pierre-Charles Bertineau <[email protected]>
17+
* @deprecated since gedmo/doctrine-extensions 3.16, will be removed in version 4.0.
2318
*
2419
* @internal
2520
*/
26-
class Annotation extends AbstractAnnotationDriver
21+
class Annotation extends Attribute implements AnnotationDriverInterface
2722
{
28-
/**
29-
* Annotation field is ipTraceable
30-
*/
31-
public const IP_TRACEABLE = IpTraceable::class;
32-
33-
/**
34-
* List of types which are valid for IP
35-
*
36-
* @var string[]
37-
*/
38-
protected $validTypes = [
39-
'string',
40-
'ascii_string',
41-
];
42-
43-
public function readExtendedMetadata($meta, array &$config)
44-
{
45-
$class = $this->getMetaReflectionClass($meta);
46-
// property annotations
47-
foreach ($class->getProperties() as $property) {
48-
if ($meta->isMappedSuperclass && !$property->isPrivate()
49-
|| $meta->isInheritedField($property->name)
50-
|| isset($meta->associationMappings[$property->name]['inherited'])
51-
) {
52-
continue;
53-
}
54-
if ($ipTraceable = $this->reader->getPropertyAnnotation($property, self::IP_TRACEABLE)) {
55-
$field = $property->getName();
56-
57-
if (!$meta->hasField($field)) {
58-
throw new InvalidMappingException("Unable to find ipTraceable [{$field}] as mapped property in entity - {$meta->getName()}");
59-
}
60-
if (!$this->isValidField($meta, $field)) {
61-
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' - {$meta->getName()}");
62-
}
63-
if (!in_array($ipTraceable->on, ['update', 'create', 'change'], true)) {
64-
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->getName()}");
65-
}
66-
if ('change' === $ipTraceable->on) {
67-
if (!isset($ipTraceable->field)) {
68-
throw new InvalidMappingException("Missing parameters on property - {$field}, field must be set on [change] trigger in class - {$meta->getName()}");
69-
}
70-
if (is_array($ipTraceable->field) && isset($ipTraceable->value)) {
71-
throw new InvalidMappingException('IpTraceable extension does not support multiple value changeset detection yet.');
72-
}
73-
$field = [
74-
'field' => $field,
75-
'trackedField' => $ipTraceable->field,
76-
'value' => $ipTraceable->value,
77-
];
78-
}
79-
// properties are unique and mapper checks that, no risk here
80-
$config[$ipTraceable->on][] = $field;
81-
}
82-
}
83-
84-
return $config;
85-
}
8623
}

0 commit comments

Comments
 (0)