Skip to content

Commit

Permalink
Introduce the Revisionable extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Oct 7, 2024
1 parent 7779be6 commit 5b3b1cb
Show file tree
Hide file tree
Showing 91 changed files with 5,962 additions and 33 deletions.
90 changes: 75 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,51 @@ parameters:
count: 1
path: src/References/ReferencesListener.php

-
message: "#^Method Gedmo\\\\Revisionable\\\\Document\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Document\\\\Revision\\<object\\>\\.$#"
count: 1
path: src/Revisionable/Document/Revision.php

-
message: "#^Unable to resolve the template type T in call to method Doctrine\\\\ORM\\\\EntityManagerInterface\\:\\:getReference\\(\\)$#"
count: 1
path: src/Revisionable/Entity/Repository/RevisionRepository.php

-
message: "#^Method Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\:\\:createRevision\\(\\) should return Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<T of object\\> but returns Gedmo\\\\Revisionable\\\\Entity\\\\Revision\\<object\\>\\.$#"
count: 1
path: src/Revisionable/Entity/Revision.php

-
message: "#^Access to offset 'isOwningSide' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
count: 1
path: src/Revisionable/Mapping/Driver/Attribute.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$associationMappings\\.$#"
count: 1
path: src/Revisionable/Mapping/Driver/Xml.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\>\\:\\:setFieldValue\\(\\)\\.$#"
count: 1
path: src/Revisionable/RevisionableListener.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
count: 4
path: src/Revisionable/RevisionableListener.php

-
message: "#^Method Gedmo\\\\Revisionable\\\\RevisionableListener\\:\\:getRevisionClass\\(\\) should return class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<T of object\\>\\> but returns class\\-string\\<Gedmo\\\\Revisionable\\\\RevisionInterface\\<object\\>\\>\\.$#"
count: 1
path: src/Revisionable/RevisionableListener.php

-
message: "#^Method Gedmo\\\\Tool\\\\WrapperInterface\\<Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\>\\:\\:getIdentifier\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
count: 2
path: src/Revisionable/RevisionableListener.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getReflectionProperty\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -440,26 +485,11 @@ parameters:
count: 1
path: src/Timestampable/Mapping/Driver/Yaml.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
count: 1
path: src/Tool/Wrapper/EntityWrapper.php

-
message: "#^Parameter \\#2 \\$em of class Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper constructor expects Doctrine\\\\ORM\\\\EntityManagerInterface, Doctrine\\\\Persistence\\\\ObjectManager given\\.$#"
count: 1
path: src/Tool/Wrapper/EntityWrapper.php

-
message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$identifier\\.$#"
count: 1
path: src/Tool/Wrapper/MongoDocumentWrapper.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
count: 2
path: src/Tool/Wrapper/MongoDocumentWrapper.php

-
message: "#^Call to function property_exists\\(\\) with \\$this\\(Gedmo\\\\Translatable\\\\Hydrator\\\\ORM\\\\ObjectHydrator\\) and '_em' will always evaluate to false\\.$#"
count: 1
Expand Down Expand Up @@ -840,6 +870,36 @@ parameters:
count: 1
path: tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php

-
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\\>\\.$#"
count: 1
path: tests/Gedmo/Revisionable/Fixture/Document/CommentRevision.php

-
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\\>\\.$#"
count: 1
path: tests/Gedmo/Revisionable/Fixture/Entity/CommentRevision.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Revisionable\\\\Document\\\\Revision\\>\\:\\:getRevisions\\(\\)\\.$#"
count: 1
path: tests/Gedmo/Revisionable/RevisionableDocumentTest.php

-
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\\.$#"
count: 1
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php

-
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\\.$#"
count: 1
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php

-
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\\.$#"
count: 1
path: tests/Gedmo/Revisionable/RevisionableEntityTest.php

-
message: "#^Method Gedmo\\\\Tests\\\\Sluggable\\\\Fixture\\\\Doctrine\\\\FakeFilter\\:\\:addFilterConstraint\\(\\) has parameter \\$targetTableAlias with no type specified\\.$#"
count: 1
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<testsuite name="Loggable Extension">
<directory suffix="Test.php">./tests/Gedmo/Loggable/</directory>
</testsuite>
<testsuite name="Revisionable Extension">
<directory suffix="Test.php">./tests/Gedmo/Revisionable/</directory>
</testsuite>
<testsuite name="Sortable Extension">
<directory suffix="Test.php">./tests/Gedmo/Sortable/</directory>
</testsuite>
Expand Down
5 changes: 5 additions & 0 deletions schemas/orm/doctrine-extensions-mapping-2-2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<xs:element name="tree-closure" type="gedmo:tree-closure"/>
<xs:element name="tree-path" type="gedmo:tree-path"/>
<xs:element name="loggable" type="gedmo:loggable"/>
<xs:element name="revisionable" type="gedmo:revisionable"/>
<xs:element name="soft-deleteable" type="gedmo:soft-deleteable"/>
<xs:element name="uploadable" type="gedmo:uploadable"/>
<xs:element name="reference" type="gedmo:reference"/>
Expand Down Expand Up @@ -92,6 +93,10 @@
<xs:attribute name="log-entry-class" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="revisionable">
<xs:attribute name="revision-class" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="slug">
<xs:sequence>
<xs:element name="handler" type="gedmo:handler" minOccurs="0" maxOccurs="unbounded"/>
Expand Down
5 changes: 5 additions & 0 deletions src/AbstractTrackingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
* @phpstan-extends MappedEventSubscriber<TConfig, TEventAdapter>
*
* @author Gediminas Morkevicius <[email protected]>
*
* @template TConfig of array
* @template TEventAdapter of AdapterInterface
*
* @extends MappedEventSubscriber<TConfig, TEventAdapter>
*/
abstract class AbstractTrackingListener extends MappedEventSubscriber
{
Expand Down
2 changes: 2 additions & 0 deletions src/Blameable/BlameableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @author Gediminas Morkevicius <[email protected]>
*
* @extends AbstractTrackingListener<array, BlameableAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
class BlameableListener extends AbstractTrackingListener
Expand Down
4 changes: 4 additions & 0 deletions src/DoctrineExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function registerMappingIntoDriverChainORM(MappingDriverChain $dri
$paths = [
__DIR__.'/Translatable/Entity',
__DIR__.'/Loggable/Entity',
__DIR__.'/Revisionable/Entity',

Check warning on line 44 in src/DoctrineExtensions.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineExtensions.php#L44

Added line #L44 was not covered by tests
__DIR__.'/Tree/Entity',
];

Expand All @@ -62,6 +63,7 @@ public static function registerAbstractMappingIntoDriverChainORM(MappingDriverCh
$paths = [
__DIR__.'/Translatable/Entity/MappedSuperclass',
__DIR__.'/Loggable/Entity/MappedSuperclass',
__DIR__.'/Revisionable/Entity/MappedSuperclass',

Check warning on line 66 in src/DoctrineExtensions.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineExtensions.php#L66

Added line #L66 was not covered by tests
__DIR__.'/Tree/Entity/MappedSuperclass',
];

Expand All @@ -83,6 +85,7 @@ public static function registerMappingIntoDriverChainMongodbODM(MappingDriverCha
$paths = [
__DIR__.'/Translatable/Document',
__DIR__.'/Loggable/Document',
__DIR__.'/Revisionable/Document',

Check warning on line 88 in src/DoctrineExtensions.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineExtensions.php#L88

Added line #L88 was not covered by tests
];

if (\PHP_VERSION_ID >= 80000) {
Expand All @@ -103,6 +106,7 @@ public static function registerAbstractMappingIntoDriverChainMongodbODM(MappingD
$paths = [
__DIR__.'/Translatable/Document/MappedSuperclass',
__DIR__.'/Loggable/Document/MappedSuperclass',
__DIR__.'/Revisionable/Document/MappedSuperclass',

Check warning on line 109 in src/DoctrineExtensions.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineExtensions.php#L109

Added line #L109 was not covered by tests
];

if (\PHP_VERSION_ID >= 80000) {
Expand Down
2 changes: 2 additions & 0 deletions src/IpTraceable/IpTraceableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*
* @author Pierre-Charles Bertineau <[email protected]>
*
* @extends AbstractTrackingListener<array, IpTraceableAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
class IpTraceableListener extends AbstractTrackingListener
Expand Down
64 changes: 64 additions & 0 deletions src/Mapping/Annotation/Revisionable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Doctrine Behavioral Extensions package.
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gedmo\Mapping\Annotation;

use Doctrine\Common\Annotations\Annotation;
use Doctrine\Deprecations\Deprecation;
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
use Gedmo\Revisionable\RevisionInterface;

/**
* Revisionable annotation for the revisionable behavioral extension
*
* @phpstan-template T of RevisionInterface
*
* @Annotation
*
* @NamedArgumentConstructor
*
* @Target("CLASS")
*
* @author Gediminas Morkevicius <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class Revisionable implements GedmoAnnotation
{
use ForwardCompatibilityTrait;

/**
* @phpstan-var class-string<T>|null
*/
public ?string $revisionClass;

/**
* @param array<string, mixed> $data
*
* @phpstan-param class-string<T>|null $revisionClass
*/
public function __construct(array $data = [], ?string $revisionClass = null)
{
if ([] !== $data) {
Deprecation::trigger(
'gedmo/doctrine-extensions',
'https://github.com/doctrine-extensions/DoctrineExtensions/pull/2357',
'Passing an array as first argument to "%s()" is deprecated. Use named arguments instead.',
__METHOD__

Check warning on line 52 in src/Mapping/Annotation/Revisionable.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Annotation/Revisionable.php#L48-L52

Added lines #L48 - L52 were not covered by tests
);

$args = func_get_args();

Check warning on line 55 in src/Mapping/Annotation/Revisionable.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Annotation/Revisionable.php#L55

Added line #L55 was not covered by tests

$this->revisionClass = $this->getAttributeValue($data, 'revisionClass', $args, 1, $revisionClass);

Check warning on line 57 in src/Mapping/Annotation/Revisionable.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Annotation/Revisionable.php#L57

Added line #L57 was not covered by tests

return;

Check warning on line 59 in src/Mapping/Annotation/Revisionable.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Annotation/Revisionable.php#L59

Added line #L59 was not covered by tests
}

$this->revisionClass = $revisionClass;
}
}
2 changes: 1 addition & 1 deletion src/Mapping/Annotation/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;

/**
* Versioned annotation for Loggable behavioral extension
* Versioned annotation for use with the Loggable and Revisionable extensions
*
* @Annotation
*
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/MappedEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
* @phpstan-template TEventAdapter of AdapterInterface
*
* @author Gediminas Morkevicius <[email protected]>
*
* @template TConfig of array
* @template TEventAdapter of AdapterInterface
*/
abstract class MappedEventSubscriber implements EventSubscriber
{
Expand Down
2 changes: 2 additions & 0 deletions src/ReferenceIntegrity/ReferenceIntegrityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*
* @author Evert Harmeling <[email protected]>
*
* @extends MappedEventSubscriber<array, AdapterInterface>
*
* @final since gedmo/doctrine-extensions 3.11
*/
class ReferenceIntegrityListener extends MappedEventSubscriber
Expand Down
Loading

0 comments on commit 5b3b1cb

Please sign in to comment.