-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: avoided edit/deletion of pre-configured services
- Loading branch information
1 parent
33ee363
commit 5c49b38
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/Demo/Domain/Service/Service/ServiceLifecycleEventHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/Demo/Domain/Service/Service/ServiceLifecycleServiceCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
|
||
} | ||
} |