Skip to content

Commit 5b3b1cb

Browse files
committed
Introduce the Revisionable extension
1 parent 7779be6 commit 5b3b1cb

File tree

91 files changed

+5962
-33
lines changed

Some content is hidden

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

91 files changed

+5962
-33
lines changed

phpstan-baseline.neon

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,51 @@ parameters:
280280
count: 1
281281
path: src/References/ReferencesListener.php
282282

283+
-
284+
message: "#^Method Gedmo\\\\Revisionable\\\\Document\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<object\\>\\.$#"
285+
count: 1
286+
path: src/Revisionable/Document/Revision.php
287+
288+
-
289+
message: "#^Unable to resolve the template type T in call to method Doctrine\\\\ORM\\\\EntityManagerInterface\\:\\:getReference\\(\\)$#"
290+
count: 1
291+
path: src/Revisionable/Entity/Repository/RevisionRepository.php
292+
293+
-
294+
message: "#^Method Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<object\\>\\.$#"
295+
count: 1
296+
path: src/Revisionable/Entity/Revision.php
297+
298+
-
299+
message: "#^Access to offset 'isOwningSide' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
300+
count: 1
301+
path: src/Revisionable/Mapping/Driver/Attribute.php
302+
303+
-
304+
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$associationMappings\\.$#"
305+
count: 1
306+
path: src/Revisionable/Mapping/Driver/Xml.php
307+
308+
-
309+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\>\\:\\:setFieldValue\\(\\)\\.$#"
310+
count: 1
311+
path: src/Revisionable/RevisionableListener.php
312+
313+
-
314+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
315+
count: 4
316+
path: src/Revisionable/RevisionableListener.php
317+
318+
-
319+
message: "#^Method Gedmo\\\\Revisionable\\\\RevisionableListener\\:\\:getRevisionClass\\(\\) should return class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\> but returns class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<object\\>\\>\\.$#"
320+
count: 1
321+
path: src/Revisionable/RevisionableListener.php
322+
323+
-
324+
message: "#^Method Gedmo\\\\Tool\\\\WrapperInterface\\<Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\>\\:\\:getIdentifier\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
325+
count: 2
326+
path: src/Revisionable/RevisionableListener.php
327+
283328
-
284329
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getReflectionProperty\\(\\)\\.$#"
285330
count: 2
@@ -440,26 +485,11 @@ parameters:
440485
count: 1
441486
path: src/Timestampable/Mapping/Driver/Yaml.php
442487

443-
-
444-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
445-
count: 1
446-
path: src/Tool/Wrapper/EntityWrapper.php
447-
448-
-
449-
message: "#^Parameter \\#2 \\$em of class Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper constructor expects Doctrine\\\\ORM\\\\EntityManagerInterface, Doctrine\\\\Persistence\\\\ObjectManager given\\.$#"
450-
count: 1
451-
path: src/Tool/Wrapper/EntityWrapper.php
452-
453488
-
454489
message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$identifier\\.$#"
455490
count: 1
456491
path: src/Tool/Wrapper/MongoDocumentWrapper.php
457492

458-
-
459-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
460-
count: 2
461-
path: src/Tool/Wrapper/MongoDocumentWrapper.php
462-
463493
-
464494
message: "#^Call to function property_exists\\(\\) with \\$this\\(Gedmo\\\\Translatable\\\\Hydrator\\\\ORM\\\\ObjectHydrator\\) and '_em' will always evaluate to false\\.$#"
465495
count: 1
@@ -840,6 +870,36 @@ parameters:
840870
count: 1
841871
path: tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php
842872

873+
-
874+
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\\>\\.$#"
875+
count: 1
876+
path: tests/Gedmo/Revisionable/Fixture/Document/CommentRevision.php
877+
878+
-
879+
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\\>\\.$#"
880+
count: 1
881+
path: tests/Gedmo/Revisionable/Fixture/Entity/CommentRevision.php
882+
883+
-
884+
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Revisionable\\\\Document\\\\Revision\\>\\:\\:getRevisions\\(\\)\\.$#"
885+
count: 1
886+
path: tests/Gedmo/Revisionable/RevisionableDocumentTest.php
887+
888+
-
889+
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\\.$#"
890+
count: 1
891+
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php
892+
893+
-
894+
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\\.$#"
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\\>\\:\\:revert\\(\\) 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+
843903
-
844904
message: "#^Method Gedmo\\\\Tests\\\\Sluggable\\\\Fixture\\\\Doctrine\\\\FakeFilter\\:\\:addFilterConstraint\\(\\) has parameter \\$targetTableAlias with no type specified\\.$#"
845905
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
@@ -34,6 +34,11 @@
3434
* @phpstan-extends MappedEventSubscriber<TConfig, TEventAdapter>
3535
*
3636
* @author Gediminas Morkevicius <[email protected]>
37+
*
38+
* @template TConfig of array
39+
* @template TEventAdapter of AdapterInterface
40+
*
41+
* @extends MappedEventSubscriber<TConfig, TEventAdapter>
3742
*/
3843
abstract class AbstractTrackingListener extends MappedEventSubscriber
3944
{

src/Blameable/BlameableListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*
2323
* @author Gediminas Morkevicius <[email protected]>
2424
*
25+
* @extends AbstractTrackingListener<array, BlameableAdapter>
26+
*
2527
* @final since gedmo/doctrine-extensions 3.11
2628
*/
2729
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*
2424
* @author Pierre-Charles Bertineau <[email protected]>
2525
*
26+
* @extends AbstractTrackingListener<array, IpTraceableAdapter>
27+
*
2628
* @final since gedmo/doctrine-extensions 3.11
2729
*/
2830
class IpTraceableListener extends AbstractTrackingListener
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
*

src/Mapping/MappedEventSubscriber.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
* @phpstan-template TEventAdapter of AdapterInterface
4545
*
4646
* @author Gediminas Morkevicius <[email protected]>
47+
*
48+
* @template TConfig of array
49+
* @template TEventAdapter of AdapterInterface
4750
*/
4851
abstract class MappedEventSubscriber implements EventSubscriber
4952
{

0 commit comments

Comments
 (0)