Skip to content

Commit

Permalink
Exchanged Doctrine's EventSubscriber with EventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bertrams committed Aug 26, 2024
1 parent 169c803 commit daa1e8f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Automation/PublishTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
$this->domainEventCollector = $domainEventCollector;
}

public function handle($workload)
public function handle($workload): void
{
if (!\is_array($workload)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Automation/UnpublishTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(EntityManagerInterface $entityManager, TranslatorInt
$this->domainEventCollector = $domainEventCollector;
}

public function handle($workload)
public function handle($workload): void
{
if (!\is_array($workload)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\EventSubscriber\ORM;
namespace Manuxi\SuluEventBundle\EventListener\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Manuxi\SuluEventBundle\Entity\Interfaces\AuthorInterface;
use Sulu\Bundle\ContactBundle\Entity\ContactInterface;
Expand All @@ -15,7 +13,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

class AuthorSubscriber implements EventSubscriber
class AuthorListener
{
const AUTHOR_PROPERTY_NAME = 'author';

Expand All @@ -28,14 +26,6 @@ public function __construct(string $userClass, TokenStorageInterface $tokenStora
$this->tokenStorage = $tokenStorage;
}

public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
Events::onFlush,
];
}

public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
$metadata = $event->getClassMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,16 @@

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\EventSubscriber\ORM;
namespace Manuxi\SuluEventBundle\EventListener\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Manuxi\SuluEventBundle\Entity\Interfaces\AuthoredInterface;

class AuthoredSubscriber implements EventSubscriber
class AuthoredListener
{
const AUTHORED_PROPERTY_NAME = 'authored';

public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
Events::preUpdate,
Events::prePersist,
];
}

public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
$metadata = $event->getClassMetadata();
Expand Down
13 changes: 8 additions & 5 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,16 @@
<argument type="service" id="sulu_core.webspace.webspace_manager"/>
</service>

<service id="sulu_event.persistence.event_subscriber.orm.author" class="Manuxi\SuluEventBundle\EventSubscriber\ORM\AuthorSubscriber">
<service id="sulu_event.persistence.event_listener.doctrine.author" class="Manuxi\SuluEventBundle\EventListener\Doctrine\AuthorListener">
<argument>%sulu.model.contact.class%</argument>
<argument type="service" id="security.token_storage" on-invalid="null"/>
<tag name="doctrine.event_subscriber"/>
<tag name="doctrine.event_listener" event="loadClassMetadata"/>
<tag name="doctrine.event_listener" event="onFlush"/>
</service>
<service id="sulu_event.persistence.event_subscriber.orm.authored" class="Manuxi\SuluEventBundle\EventSubscriber\ORM\AuthoredSubscriber">
<tag name="doctrine.event_subscriber"/>
<service id="sulu_event.persistence.event_listener.doctrine.authored" class="Manuxi\SuluEventBundle\EventListener\Doctrine\AuthoredListener">
<tag name="doctrine.event_listener" event="loadClassMetadata"/>
<tag name="doctrine.event_listener" event="preUpdate"/>
<tag name="doctrine.event_listener" event="prePersist"/>
</service>

<service id="sulu_event.model.event" class="Manuxi\SuluEventBundle\Entity\Models\EventModel">
Expand Down Expand Up @@ -201,4 +204,4 @@
<tag name="twig.extension"/>
</service>
</services>
</container>
</container>

0 comments on commit daa1e8f

Please sign in to comment.