Skip to content

Commit 761f013

Browse files
committed
Introduce the Revisionable extension
1 parent 93d8133 commit 761f013

File tree

99 files changed

+5978
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5978
-70
lines changed

phpstan-baseline.neon

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,49 @@ parameters:
286286
path: src/References/ReferencesListener.php
287287

288288
-
289-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:extractIdentifier\\(\\)\\.$#"
290-
count: 2
291-
path: src/References/ReferencesListener.php
289+
message: "#^Method Gedmo\\\\Revisionable\\\\Document\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<object\\>\\.$#"
290+
count: 1
291+
path: src/Revisionable/Document/Revision.php
292292

293293
-
294-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getIdentifier\\(\\)\\.$#"
294+
message: "#^Unable to resolve the template type T in call to method Doctrine\\\\ORM\\\\EntityManagerInterface\\:\\:getReference\\(\\)$#"
295295
count: 1
296-
path: src/References/ReferencesListener.php
296+
path: src/Revisionable/Entity/Repository/RevisionRepository.php
297297

298298
-
299-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getSingleReference\\(\\)\\.$#"
299+
message: "#^Method Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<object\\>\\.$#"
300300
count: 1
301-
path: src/References/ReferencesListener.php
301+
path: src/Revisionable/Entity/Revision.php
302+
303+
-
304+
message: "#^Access to offset 'isOwningSide' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
305+
count: 1
306+
path: src/Revisionable/Mapping/Driver/Attribute.php
307+
308+
-
309+
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$associationMappings\\.$#"
310+
count: 1
311+
path: src/Revisionable/Mapping/Driver/Xml.php
312+
313+
-
314+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\>\\:\\:setFieldValue\\(\\)\\.$#"
315+
count: 1
316+
path: src/Revisionable/RevisionableListener.php
317+
318+
-
319+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
320+
count: 4
321+
path: src/Revisionable/RevisionableListener.php
322+
323+
-
324+
message: "#^Method Gedmo\\\\Revisionable\\\\RevisionableListener\\:\\:getRevisionClass\\(\\) should return class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\> but returns class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<object\\>\\>\\.$#"
325+
count: 1
326+
path: src/Revisionable/RevisionableListener.php
327+
328+
-
329+
message: "#^Method Gedmo\\\\Tool\\\\WrapperInterface\\<Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\>\\:\\:getIdentifier\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
330+
count: 2
331+
path: src/Revisionable/RevisionableListener.php
302332

303333
-
304334
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getReflectionProperty\\(\\)\\.$#"
@@ -400,11 +430,6 @@ parameters:
400430
count: 1
401431
path: src/SoftDeleteable/Query/TreeWalker/SoftDeleteableWalker.php
402432

403-
-
404-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getDateValue\\(\\)\\.$#"
405-
count: 1
406-
path: src/SoftDeleteable/SoftDeleteableListener.php
407-
408433
-
409434
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
410435
count: 1
@@ -465,26 +490,11 @@ parameters:
465490
count: 1
466491
path: src/Timestampable/Mapping/Driver/Yaml.php
467492

468-
-
469-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
470-
count: 1
471-
path: src/Tool/Wrapper/EntityWrapper.php
472-
473-
-
474-
message: "#^Parameter \\#2 \\$em of class Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper constructor expects Doctrine\\\\ORM\\\\EntityManagerInterface, Doctrine\\\\Persistence\\\\ObjectManager given\\.$#"
475-
count: 1
476-
path: src/Tool/Wrapper/EntityWrapper.php
477-
478493
-
479494
message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$identifier\\.$#"
480495
count: 1
481496
path: src/Tool/Wrapper/MongoDocumentWrapper.php
482497

483-
-
484-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
485-
count: 2
486-
path: src/Tool/Wrapper/MongoDocumentWrapper.php
487-
488498
-
489499
message: "#^Call to function property_exists\\(\\) with \\$this\\(Gedmo\\\\Translatable\\\\Hydrator\\\\ORM\\\\ObjectHydrator\\) and '_em' will always evaluate to false\\.$#"
490500
count: 1
@@ -865,6 +875,36 @@ parameters:
865875
count: 1
866876
path: tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php
867877

878+
-
879+
message: "#^Method Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Document\\\\CommentRevision\\:\\:createRevision\\(\\) should return Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Document\\\\CommentRevision\\<T of Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Document\\\\Comment\\> but returns Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Document\\\\CommentRevision\\<Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Document\\\\Comment\\>\\.$#"
880+
count: 1
881+
path: tests/Gedmo/Revisionable/Fixture/Document/CommentRevision.php
882+
883+
-
884+
message: "#^Method Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision\\:\\:createRevision\\(\\) should return Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision\\<T of Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\Comment\\> but returns Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision\\<Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\Comment\\>\\.$#"
885+
count: 1
886+
path: tests/Gedmo/Revisionable/Fixture/Entity/CommentRevision.php
887+
888+
-
889+
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Revisionable\\\\Document\\\\Revision\\>\\:\\:getRevisions\\(\\)\\.$#"
890+
count: 1
891+
path: tests/Gedmo/Revisionable/RevisionableDocumentTest.php
892+
893+
-
894+
message: "#^Parameter \\#1 \\$entity of method Gedmo\\\\Revisionable\\\\Entity\\\\Repository\\\\RevisionRepository\\<Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\>\\:\\:getRevisions\\(\\) expects Gedmo\\\\Revisionable\\\\Entity\\\\Revision, Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\Address given\\.$#"
895+
count: 1
896+
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php
897+
898+
-
899+
message: "#^Parameter \\#1 \\$entity of method Gedmo\\\\Revisionable\\\\Entity\\\\Repository\\\\RevisionRepository\\<Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision\\>\\:\\:getRevisions\\(\\) expects Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision, Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\Comment given\\.$#"
900+
count: 1
901+
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php
902+
903+
-
904+
message: "#^Parameter \\#1 \\$entity of method Gedmo\\\\Revisionable\\\\Entity\\\\Repository\\\\RevisionRepository\\<Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision\\>\\:\\:revert\\(\\) expects Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\CommentRevision, Gedmo\\\\Tests\\\\Revisionable\\\\Fixture\\\\Entity\\\\Comment given\\.$#"
905+
count: 1
906+
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php
907+
868908
-
869909
message: "#^Method Gedmo\\\\Tests\\\\Sluggable\\\\Fixture\\\\Doctrine\\\\FakeFilter\\:\\:addFilterConstraint\\(\\) has parameter \\$targetTableAlias with no type specified\\.$#"
870910
count: 1

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<testsuite name="Loggable Extension">
4545
<directory suffix="Test.php">./tests/Gedmo/Loggable/</directory>
4646
</testsuite>
47+
<testsuite name="Revisionable Extension">
48+
<directory suffix="Test.php">./tests/Gedmo/Revisionable/</directory>
49+
</testsuite>
4750
<testsuite name="Sortable Extension">
4851
<directory suffix="Test.php">./tests/Gedmo/Sortable/</directory>
4952
</testsuite>

schemas/orm/doctrine-extensions-mapping-2-2.xsd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<xs:element name="tree-closure" type="gedmo:tree-closure"/>
2828
<xs:element name="tree-path" type="gedmo:tree-path"/>
2929
<xs:element name="loggable" type="gedmo:loggable"/>
30+
<xs:element name="revisionable" type="gedmo:revisionable"/>
3031
<xs:element name="soft-deleteable" type="gedmo:soft-deleteable"/>
3132
<xs:element name="uploadable" type="gedmo:uploadable"/>
3233
<xs:element name="reference" type="gedmo:reference"/>
@@ -92,6 +93,10 @@
9293
<xs:attribute name="log-entry-class" type="xs:string" use="optional" />
9394
</xs:complexType>
9495

96+
<xs:complexType name="revisionable">
97+
<xs:attribute name="revision-class" type="xs:string" use="optional" />
98+
</xs:complexType>
99+
95100
<xs:complexType name="slug">
96101
<xs:sequence>
97102
<xs:element name="handler" type="gedmo:handler" minOccurs="0" maxOccurs="unbounded"/>

src/AbstractTrackingListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
* The AbstractTrackingListener provides generic functions for all listeners.
2929
*
3030
* @author Gediminas Morkevicius <[email protected]>
31+
*
32+
* @template TConfig of array
33+
* @template TEventAdapter of AdapterInterface
34+
*
35+
* @extends MappedEventSubscriber<TConfig, TEventAdapter>
3136
*/
3237
abstract class AbstractTrackingListener extends MappedEventSubscriber
3338
{

src/Blameable/BlameableListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Doctrine\Persistence\Mapping\ClassMetadata;
1313
use Gedmo\AbstractTrackingListener;
14+
use Gedmo\Blameable\Mapping\Event\BlameableAdapter;
1415
use Gedmo\Exception\InvalidArgumentException;
1516

1617
/**
@@ -19,6 +20,8 @@
1920
*
2021
* @author Gediminas Morkevicius <[email protected]>
2122
*
23+
* @extends AbstractTrackingListener<array, BlameableAdapter>
24+
*
2225
* @final since gedmo/doctrine-extensions 3.11
2326
*/
2427
class BlameableListener extends AbstractTrackingListener

src/DoctrineExtensions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static function registerMappingIntoDriverChainORM(MappingDriverChain $dri
4141
$paths = [
4242
__DIR__.'/Translatable/Entity',
4343
__DIR__.'/Loggable/Entity',
44+
__DIR__.'/Revisionable/Entity',
4445
__DIR__.'/Tree/Entity',
4546
];
4647

@@ -62,6 +63,7 @@ public static function registerAbstractMappingIntoDriverChainORM(MappingDriverCh
6263
$paths = [
6364
__DIR__.'/Translatable/Entity/MappedSuperclass',
6465
__DIR__.'/Loggable/Entity/MappedSuperclass',
66+
__DIR__.'/Revisionable/Entity/MappedSuperclass',
6567
__DIR__.'/Tree/Entity/MappedSuperclass',
6668
];
6769

@@ -83,6 +85,7 @@ public static function registerMappingIntoDriverChainMongodbODM(MappingDriverCha
8385
$paths = [
8486
__DIR__.'/Translatable/Document',
8587
__DIR__.'/Loggable/Document',
88+
__DIR__.'/Revisionable/Document',
8689
];
8790

8891
if (\PHP_VERSION_ID >= 80000) {
@@ -103,6 +106,7 @@ public static function registerAbstractMappingIntoDriverChainMongodbODM(MappingD
103106
$paths = [
104107
__DIR__.'/Translatable/Document/MappedSuperclass',
105108
__DIR__.'/Loggable/Document/MappedSuperclass',
109+
__DIR__.'/Revisionable/Document/MappedSuperclass',
106110
];
107111

108112
if (\PHP_VERSION_ID >= 80000) {

src/IpTraceable/IpTraceableListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Persistence\Mapping\ClassMetadata;
1313
use Gedmo\AbstractTrackingListener;
1414
use Gedmo\Exception\InvalidArgumentException;
15+
use Gedmo\IpTraceable\Mapping\Event\IpTraceableAdapter;
1516
use Gedmo\Mapping\Event\AdapterInterface;
1617

1718
/**
@@ -20,6 +21,8 @@
2021
*
2122
* @author Pierre-Charles Bertineau <[email protected]>
2223
*
24+
* @extends AbstractTrackingListener<array, IpTraceableAdapter>
25+
*
2326
* @final since gedmo/doctrine-extensions 3.11
2427
*/
2528
class IpTraceableListener extends AbstractTrackingListener

src/Loggable/LoggableListener.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
* versioned?: string[],
3636
* }
3737
*
38-
* @phpstan-method LoggableConfiguration getConfiguration(ObjectManager $objectManager, $class)
38+
* @template T of Loggable|object
3939
*
40-
* @method LoggableAdapter getEventAdapter(EventArgs $args)
41-
*
42-
* @phpstan-template T of Loggable|object
40+
* @phpstan-extends MappedEventSubscriber<LoggableConfiguration, LoggableAdapter>
4341
*/
4442
class LoggableListener extends MappedEventSubscriber
4543
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Doctrine Behavioral Extensions package.
5+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace Gedmo\Mapping\Annotation;
11+
12+
use Doctrine\Common\Annotations\Annotation;
13+
use Doctrine\Deprecations\Deprecation;
14+
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
15+
use Gedmo\Revisionable\RevisionInterface;
16+
17+
/**
18+
* Revisionable annotation for the revisionable behavioral extension
19+
*
20+
* @phpstan-template T of RevisionInterface
21+
*
22+
* @Annotation
23+
*
24+
* @NamedArgumentConstructor
25+
*
26+
* @Target("CLASS")
27+
*
28+
* @author Gediminas Morkevicius <[email protected]>
29+
*/
30+
#[\Attribute(\Attribute::TARGET_CLASS)]
31+
final class Revisionable implements GedmoAnnotation
32+
{
33+
use ForwardCompatibilityTrait;
34+
35+
/**
36+
* @phpstan-var class-string<T>|null
37+
*/
38+
public ?string $revisionClass;
39+
40+
/**
41+
* @param array<string, mixed> $data
42+
*
43+
* @phpstan-param class-string<T>|null $revisionClass
44+
*/
45+
public function __construct(array $data = [], ?string $revisionClass = null)
46+
{
47+
if ([] !== $data) {
48+
Deprecation::trigger(
49+
'gedmo/doctrine-extensions',
50+
'https://github.com/doctrine-extensions/DoctrineExtensions/pull/2357',
51+
'Passing an array as first argument to "%s()" is deprecated. Use named arguments instead.',
52+
__METHOD__
53+
);
54+
55+
$args = func_get_args();
56+
57+
$this->revisionClass = $this->getAttributeValue($data, 'revisionClass', $args, 1, $revisionClass);
58+
59+
return;
60+
}
61+
62+
$this->revisionClass = $revisionClass;
63+
}
64+
}

src/Mapping/Annotation/Versioned.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
1414

1515
/**
16-
* Versioned annotation for Loggable behavioral extension
16+
* Versioned annotation for use with the Loggable and Revisionable extensions
1717
*
1818
* @Annotation
1919
*

0 commit comments

Comments
 (0)