Skip to content

Commit

Permalink
Merge branch '4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmadariaga committed May 30, 2024
2 parents ef64da5 + 5228e7a commit bd9a190
Show file tree
Hide file tree
Showing 104 changed files with 2,538 additions and 1,049 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PHPStan tests

on:
push:
branches: [ 4.x ]
pull_request:
branches: [ 4.x ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Validate composer.json
run: composer validate --strict

- name: Install dependencies
uses: php-actions/composer@v6

- name: Run PHPStan tests
run: bin/test-phpstan
21 changes: 0 additions & 21 deletions Application/ForeignKeyTransformerInterface.php

This file was deleted.

24 changes: 8 additions & 16 deletions Application/Service/DataGateway.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Ivoz\Core\Application\Service;

use Doctrine\ORM\EntityManager;
use Ivoz\Core\Application\DataTransferObjectInterface;
use Ivoz\Core\Application\Event\CommandWasExecuted;
use Ivoz\Core\Application\RequestId;
use Ivoz\Core\Application\Service\Assembler\DtoAssembler;
use Doctrine\ORM\EntityManagerInterface;
use Ivoz\Core\Domain\DataTransferObjectInterface;
use Ivoz\Core\Domain\Event\CommandWasExecuted;
use Ivoz\Core\Domain\RequestId;
use Ivoz\Core\Domain\Service\Assembler\DtoAssembler;
use Ivoz\Core\Domain\Service\DomainEventPublisher;
use Ivoz\Core\Domain\Service\QueryBuilderFactory;
use Ivoz\Core\Infrastructure\Domain\Service\DoctrineEntityPersister;

/**
Expand All @@ -18,7 +19,7 @@
class DataGateway
{
/**
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

Expand Down Expand Up @@ -52,17 +53,8 @@ class DataGateway
*/
public static $user = '';

/**
* DataGateway constructor.
* @param EntityManager $entityManager
* @param QueryBuilderFactory $queryBuilderFactory
* @param DoctrineEntityPersister $entityPersister
* @param DtoAssembler $dtoAssembler
* @param DomainEventPublisher $eventPublisher
* @param RequestId $requestId
*/
public function __construct(
EntityManager $entityManager,
EntityManagerInterface $entityManager,
QueryBuilderFactory $queryBuilderFactory,
DoctrineEntityPersister $entityPersister,
DtoAssembler $dtoAssembler,
Expand Down
2 changes: 1 addition & 1 deletion Domain/Assert/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function regexFormat($pattern, $message = null, $propertyPath = nu

$pattern = '/' . str_replace('/', '\/', $pattern) . '/';

if (@preg_match($pattern, null) === false) {
if (@preg_match($pattern, '') === false) {
$message = \sprintf(
static::generateMessage($message) ?: '"%s" is not a valid regexp',
static::stringify($pattern)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Ivoz\Core\Application;
namespace Ivoz\Core\Domain;

interface DataTransferObjectInterface
{
Expand All @@ -18,28 +18,21 @@ interface DataTransferObjectInterface
self::CONTEXT_DETAILED_COLLECTION
];

public function setId($id = null);
public function setId(int|string $id);
public function getId();
public function normalize(string $context, string $role = ''): array;

/**
* @return array
* @param array<array-key, mixed> $data
*/
public function normalize(string $context, string $role = '');

/**
* @return void
*/
public function denormalize(array $data, string $context, string $role = '');

public function denormalize(array $data, string $context, string $role = ''): void;
/**
* @return array
* @return array<array-key, array<array-key, array<int, string>|string>|string>
*/
public static function getPropertyMap(string $context = '', string $role = null);

public static function getPropertyMap(string $context = '', string $role = null): array;
public function getSensitiveFields(): array;

/**
* @return array
* @return array<array-key, mixed>
*/
public function toArray($hideSensitiveData = false);
public function toArray(bool $hideSensitiveData = false): array;
}
20 changes: 19 additions & 1 deletion Application/Event/CommandEventInterface.php → Domain/Event/CommandEventInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Ivoz\Core\Application\Event;
namespace Ivoz\Core\Domain\Event;

use Ivoz\Core\Domain\Event\DomainEventInterface;

Expand All @@ -14,15 +14,33 @@ public function __construct(
array $agent
);

/**
* @return string
*/
public function getId();

/**
* @return string
*/
public function getRequestId();

/**
* @return string
*/
public function getService();

/**
* @return string
*/
public function getMethod();

/**
* @return array
*/
public function getArguments();

/**
* @return array
*/
public function getAgent();
}
2 changes: 1 addition & 1 deletion Application/Event/CommandWasExecuted.php → Domain/Event/CommandWasExecuted.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Ivoz\Core\Application\Event;
namespace Ivoz\Core\Domain\Event;

use Ramsey\Uuid\Uuid;

Expand Down
12 changes: 12 additions & 0 deletions Domain/Event/EntityEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ interface EntityEventInterface extends DomainEventInterface
{
public function __construct(string $entityClass, $entityId, array $changeSet = null);

/**
* @return string
*/
public function getId();

/**
* @return string
*/
public function getEntityClass();

/**
* @return int|string
*/
public function getEntityId();

/**
* @return array
*/
public function getData();
}
21 changes: 21 additions & 0 deletions Domain/ForeignKeyTransformerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Ivoz\Core\Domain;

use Doctrine\Common\Collections\ArrayCollection;
use Ivoz\Core\Domain\Model\EntityInterface;

interface ForeignKeyTransformerInterface
{
/**
* @param EntityInterface|DataTransferObjectInterface|null $element
* @param bool $persist
*/
public function transform($element, $persist = true);

/**
* @param array $elements
* @return ArrayCollection<array-key, EntityInterface>
*/
public function transformCollection(array $elements);
}
2 changes: 1 addition & 1 deletion Application/Helper/ArrayObjectHelper.php → Domain/Helper/ArrayObjectHelper.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Ivoz\Core\Application\Helper;
namespace Ivoz\Core\Domain\Helper;

class ArrayObjectHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Ivoz\Core\Application\Helper;
namespace Ivoz\Core\Domain\Helper;

use Doctrine\Common\Persistence\Proxy;
use Ivoz\Core\Application\DataTransferObjectInterface;
use Doctrine\Persistence\Proxy;
use Ivoz\Core\Domain\DataTransferObjectInterface;
use Ivoz\Core\Domain\Model\EntityInterface;

class EntityClassHelper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Ivoz\Core\Application\Helper;
namespace Ivoz\Core\Domain\Helper;

use Doctrine\Common\Inflector\Inflector;
use Ivoz\Core\Domain\Model\EntityInterface;
Expand All @@ -24,7 +24,7 @@ public static function getServiceNameByEntityFqdn(string $entityClass, string $e

$prefix = $classSegments[1];
$entityName = end($classSegments);
$snakeCaseEntity = Inflector::tableize($entityName);
$snakeCaseEntity = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $entityName));
$serviceName = $prefix . '.lifecycle.' . $snakeCaseEntity . '.' . $event;

return strtolower($serviceName);
Expand Down
62 changes: 62 additions & 0 deletions Domain/Model/Changelog/Changelog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Ivoz\Core\Domain\Model\Changelog;

use Ivoz\Core\Domain\Event\EntityEventInterface;
use Ivoz\Core\Domain\Model\LoggerEntityInterface;
use Ivoz\Core\Domain\Model\Commandlog\CommandlogInterface;

/**
* Changelog
*/
class Changelog extends ChangelogAbstract implements LoggerEntityInterface, ChangelogInterface
{
use ChangelogTrait;

/**
* @param \Ivoz\Core\Domain\Event\EntityEventInterface $event
* @return self
*/
public static function fromEvent(
EntityEventInterface $event,
CommandlogInterface $command
) {
$entity = new static(
$event->getEntityClass(),
(string) $event->getEntityId(),
$event->getOccurredOn(),
$event->getMicrotime()
);

$entity->id = $event->getId();
$entity->setData(
$event->getData()
);

$entity->setCommand($command);

$entity->sanitizeValues();
$entity->initChangelog();

return $entity;
}

/**
* @param array<array-key, mixed> $data | null
* @return static
*/
public function replaceData($data = null)
{
return $this->setData($data);
}

/**
* Get id
* @codeCoverageIgnore
* @return string
*/
public function getId(): ?string
{
return $this->id;
}
}
Loading

0 comments on commit bd9a190

Please sign in to comment.