-
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.
Merge pull request #11 from irontec/CDD-3-add-service-entity
Add service entity
- Loading branch information
Showing
16 changed files
with
634 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -37,3 +37,7 @@ Demo\Domain\Model\Administrator\Administrator: | |
ROLE_ADMIN: | ||
id: | ||
neq: 1 | ||
|
||
Demo\Domain\Model\Service\Service: ~ | ||
|
||
|
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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Ivoz\Core\Infrastructure\Persistence\Doctrine\LoggableMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240206172427 extends LoggableMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add Services table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE Services (id INT UNSIGNED AUTO_INCREMENT NOT NULL, iden VARCHAR(50) NOT NULL, UNIQUE INDEX services_iden (iden), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->populateFactoryServices(); | ||
} | ||
|
||
private function populateFactoryServices() | ||
{ | ||
$factoryServices = [ | ||
'Recording', 'Voicemail', 'Queues' | ||
]; | ||
|
||
foreach ($factoryServices as $srv) { | ||
$this->addSql('INSERT INTO Services(iden) VALUES(:srv)', ['srv' => $srv]); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE Services'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Demo\Domain\Model\Service; | ||
|
||
/** | ||
* Service | ||
*/ | ||
class Service extends ServiceAbstract implements ServiceInterface | ||
{ | ||
use ServiceTrait; | ||
|
||
const BUILTIN_SERVICES = ['Recording', 'Voicemail', 'Queues']; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
* @return array<string, mixed> | ||
*/ | ||
public function getChangeSet(): array | ||
{ | ||
return parent::getChangeSet(); | ||
} | ||
|
||
/** | ||
* Get id | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getId(): null|int | ||
{ | ||
return $this->id; | ||
} | ||
} |
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,161 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Demo\Domain\Model\Service; | ||
|
||
use Assert\Assertion; | ||
use Ivoz\Core\Domain\DataTransferObjectInterface; | ||
use Ivoz\Core\Domain\Model\ChangelogTrait; | ||
use Ivoz\Core\Domain\Model\EntityInterface; | ||
use Ivoz\Core\Domain\ForeignKeyTransformerInterface; | ||
|
||
/** | ||
* ServiceAbstract | ||
* @codeCoverageIgnore | ||
*/ | ||
abstract class ServiceAbstract | ||
{ | ||
use ChangelogTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $iden; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
protected function __construct( | ||
string $iden | ||
) { | ||
$this->setIden($iden); | ||
} | ||
|
||
abstract public function getId(): null|string|int; | ||
|
||
public function __toString(): string | ||
{ | ||
return sprintf( | ||
"%s#%s", | ||
"Service", | ||
(string) $this->getId() | ||
); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
protected function sanitizeValues(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @param int | null $id | ||
*/ | ||
public static function createDto($id = null): ServiceDto | ||
{ | ||
return new ServiceDto($id); | ||
} | ||
|
||
/** | ||
* @internal use EntityTools instead | ||
* @param null|ServiceInterface $entity | ||
*/ | ||
public static function entityToDto(?EntityInterface $entity, int $depth = 0): ?ServiceDto | ||
{ | ||
if (!$entity) { | ||
return null; | ||
} | ||
|
||
Assertion::isInstanceOf($entity, ServiceInterface::class); | ||
|
||
if ($depth < 1) { | ||
return static::createDto($entity->getId()); | ||
} | ||
|
||
if ($entity instanceof \Doctrine\ORM\Proxy\Proxy && !$entity->__isInitialized()) { | ||
return static::createDto($entity->getId()); | ||
} | ||
|
||
$dto = $entity->toDto($depth - 1); | ||
|
||
return $dto; | ||
} | ||
|
||
/** | ||
* Factory method | ||
* @internal use EntityTools instead | ||
* @param ServiceDto $dto | ||
*/ | ||
public static function fromDto( | ||
DataTransferObjectInterface $dto, | ||
ForeignKeyTransformerInterface $fkTransformer | ||
): static { | ||
Assertion::isInstanceOf($dto, ServiceDto::class); | ||
$iden = $dto->getIden(); | ||
Assertion::notNull($iden, 'getIden value is null, but non null value was expected.'); | ||
|
||
$self = new static( | ||
$iden | ||
); | ||
|
||
; | ||
|
||
$self->initChangelog(); | ||
|
||
return $self; | ||
} | ||
|
||
/** | ||
* @internal use EntityTools instead | ||
* @param ServiceDto $dto | ||
*/ | ||
public function updateFromDto( | ||
DataTransferObjectInterface $dto, | ||
ForeignKeyTransformerInterface $fkTransformer | ||
): static { | ||
Assertion::isInstanceOf($dto, ServiceDto::class); | ||
|
||
$iden = $dto->getIden(); | ||
Assertion::notNull($iden, 'getIden value is null, but non null value was expected.'); | ||
|
||
$this | ||
->setIden($iden); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @internal use EntityTools instead | ||
*/ | ||
public function toDto(int $depth = 0): ServiceDto | ||
{ | ||
return self::createDto() | ||
->setIden(self::getIden()); | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
protected function __toArray(): array | ||
{ | ||
return [ | ||
'iden' => self::getIden() | ||
]; | ||
} | ||
|
||
protected function setIden(string $iden): static | ||
{ | ||
Assertion::maxLength($iden, 50, 'iden value "%s" is too long, it should have no more than %d characters, but has %d characters.'); | ||
|
||
$this->iden = $iden; | ||
|
||
return $this; | ||
} | ||
|
||
public function getIden(): string | ||
{ | ||
return $this->iden; | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Demo\Domain\Model\Service; | ||
|
||
class ServiceDto extends ServiceDtoAbstract | ||
{ | ||
} |
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,96 @@ | ||
<?php | ||
|
||
namespace Demo\Domain\Model\Service; | ||
|
||
use Ivoz\Core\Domain\DataTransferObjectInterface; | ||
use Ivoz\Core\Domain\Model\DtoNormalizer; | ||
|
||
/** | ||
* ServiceDtoAbstract | ||
* @codeCoverageIgnore | ||
*/ | ||
abstract class ServiceDtoAbstract implements DataTransferObjectInterface | ||
{ | ||
use DtoNormalizer; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $iden = null; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $id = null; | ||
|
||
public function __construct(?int $id = null) | ||
{ | ||
$this->setId($id); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getPropertyMap(string $context = '', string $role = null): array | ||
{ | ||
if ($context === self::CONTEXT_COLLECTION) { | ||
return ['id' => 'id']; | ||
} | ||
|
||
return [ | ||
'iden' => 'iden', | ||
'id' => 'id' | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(bool $hideSensitiveData = false): array | ||
{ | ||
$response = [ | ||
'iden' => $this->getIden(), | ||
'id' => $this->getId() | ||
]; | ||
|
||
if (!$hideSensitiveData) { | ||
return $response; | ||
} | ||
|
||
foreach ($this->sensitiveFields as $sensitiveField) { | ||
if (!array_key_exists($sensitiveField, $response)) { | ||
throw new \Exception($sensitiveField . ' field was not found'); | ||
} | ||
$response[$sensitiveField] = '*****'; | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
public function setIden(string $iden): static | ||
{ | ||
$this->iden = $iden; | ||
|
||
return $this; | ||
} | ||
|
||
public function getIden(): ?string | ||
{ | ||
return $this->iden; | ||
} | ||
|
||
/** | ||
* @param int|null $id | ||
*/ | ||
public function setId($id): static | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
} |
Oops, something went wrong.