Skip to content

Commit

Permalink
core: avoided edit/deletion of pre-configured services
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Feb 7, 2024
1 parent 33ee363 commit 5c49b38
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/src/Demo/Domain/Service/Service/AvoidUpdateDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Demo\Domain\Service\Service;

use Demo\Domain\Model\Service\ServiceInterface;

class AvoidUpdateDelete implements ServiceLifecycleEventHandlerInterface
{
const PRE_PERSIST_PRIORITY = self::PRIORITY_HIGH;
const PRE_REMOVE_PRIORITY = self::PRIORITY_HIGH;

/**
* @return array<string, int>
*/
public static function getSubscribedEvents(): array
{
return [
self::EVENT_PRE_PERSIST => self::PRE_PERSIST_PRIORITY,
self::EVENT_PRE_REMOVE => self::PRE_REMOVE_PRIORITY
];
}

public function execute(ServiceInterface $service): void
{
if ($service->isNew()) {
return;
}

$iden = $service->getIden();

if (in_array($iden, ['Recording', 'Voicemail', 'Queues'])) {
$msg = $service->hasBeenDeleted()
? 'Service ' . $iden . 'can’t be deleted'
: 'Service ' . $iden . 'can’t be edited';

throw new \DomainException($msg);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Demo\Domain\Service\Service;

use Demo\Domain\Model\Service\ServiceInterface;
use Ivoz\Core\Domain\Service\LifecycleEventHandlerInterface;

interface ServiceLifecycleEventHandlerInterface extends LifecycleEventHandlerInterface
{
public function execute(ServiceInterface $service): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Demo\Domain\Service\Service;

use Ivoz\Core\Domain\Model\EntityInterface;
use Ivoz\Core\Domain\Service\DomainEventSubscriberInterface;
use Ivoz\Core\Domain\Service\LifecycleEventHandlerInterface;
use Ivoz\Core\Domain\Service\LifecycleServiceCollectionInterface;
use Ivoz\Core\Domain\Service\LifecycleServiceCollectionTrait;

class ServiceLifecycleServiceCollection implements LifecycleServiceCollectionInterface
{
use LifecycleServiceCollectionTrait;


protected function addService(string $event, LifecycleEventHandlerInterface|DomainEventSubscriberInterface $service)
{

}
}

0 comments on commit 5c49b38

Please sign in to comment.