-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial domain structure extracted from current proyects
Co-authored-by: Alejandro Mascort Colomer <[email protected]> Co-authored-by: Diego García <[email protected]> Co-authored-by: Miquel Mariño Espinosa <[email protected]> Co-authored-by: Juan Cama Villafan <[email protected]> Co-authored-by: Victor del Valle <[email protected]> Co-authored-by: Alejandro García Sánchez <[email protected]>
- Loading branch information
Showing
70 changed files
with
2,086 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,19 @@ | ||
name: pipeline | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build environment | ||
run: | | ||
make start | ||
- name: Unit tests | ||
run: make phpunit |
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 @@ | ||
# phpstorm project files | ||
.idea | ||
|
||
# netbeans project files | ||
nbproject/* | ||
|
||
# zend studio for eclipse project files | ||
.buildpath | ||
.project | ||
.settings | ||
|
||
# windows thumbnail cache | ||
Thumbs.db | ||
|
||
# Mac DS_Store Files | ||
.DS_Store | ||
|
||
/vendor/ | ||
composer.lock | ||
/.phpunit.result.cache |
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,15 @@ | ||
FROM php:8.0-cli-alpine | ||
|
||
RUN apk update && \ | ||
apk add --no-cache \ | ||
libzip-dev \ | ||
git \ | ||
openssl-dev && \ | ||
docker-php-ext-install -j$(nproc) \ | ||
zip | ||
|
||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer | ||
|
||
ENV PATH /var/app/bin:/var/app/vendor/bin:$PATH | ||
|
||
WORKDIR /var/app |
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,24 @@ | ||
UID=$(shell id -u) | ||
GID=$(shell id -g) | ||
CONTAINER=php | ||
|
||
start: erase cache-folders build composer-install bash | ||
|
||
erase: | ||
docker-compose down -v | ||
|
||
build: | ||
docker-compose build && \ | ||
docker-compose pull | ||
|
||
cache-folders: | ||
mkdir -p ~/.composer && chown ${UID}:${GID} ~/.composer | ||
|
||
composer-install: | ||
docker-compose run --rm -u ${UID}:${GID} ${CONTAINER} composer install | ||
|
||
bash: | ||
docker-compose run --rm -u ${UID}:${GID} ${CONTAINER} sh | ||
|
||
phpunit: ## execute project unit tests | ||
docker-compose run --rm -u ${UID}:${GID} ${CONTAINER} phpunit --no-coverage |
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,62 @@ | ||
{ | ||
"name": "colvin/common-domain-php", | ||
"description": "Domain structure for shared projects", | ||
"authors": [ | ||
{ | ||
"name": "Aaron Bernabeu Rodríguez", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Alejandro Mascort Colomer", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Alejandro García Sánchez", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Diego García", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Miquel Mariño Espinosa", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Juan Cama Villafan", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Victor del Valle", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": "MIT", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"Colvin\\CommonDomain\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Colvin\\CommonDomain\\Tests\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"symfony/uid": "^5.3" | ||
}, | ||
"require-dev": { | ||
"phpro/grumphp": "^1.5", | ||
"phpunit/phpunit": "^9.5" | ||
}, | ||
"scripts": { | ||
"post-install-cmd": [ | ||
"rm -rf .git/hooks", | ||
"mkdir -p .git/hooks", | ||
"cp -r ./config/hooks/* .git/hooks" | ||
] | ||
} | ||
} |
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,6 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT=$(docker-compose run --no-deps --rm php sh -c "grumphp git:pre-commit" 2>&1) | ||
STATUS=$? | ||
echo "$SCRIPT" | ||
exit $STATUS |
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,8 @@ | ||
version: '3.8' | ||
|
||
services: | ||
php: | ||
build: . | ||
volumes: | ||
- .:/var/app | ||
- ~/.composer:/.composer |
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 @@ | ||
grumphp: | ||
tasks: | ||
composer: | ||
strict: true | ||
jsonlint: ~ | ||
phplint: ~ | ||
phpunit: ~ |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Application; | ||
|
||
use Colvin\CommonDomain\Domain\Message\ActionMessage; | ||
|
||
abstract class Command extends ActionMessage | ||
{ | ||
public static function messageType(): string | ||
{ | ||
return 'command'; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Application; | ||
|
||
use Colvin\CommonDomain\Domain\Message\ActionMessage; | ||
|
||
abstract class Query extends ActionMessage | ||
{ | ||
public static function messageType(): string | ||
{ | ||
return 'query'; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain; | ||
|
||
use Colvin\CommonDomain\Domain\Message\AggregateMessage; | ||
|
||
abstract class DomainEvent extends AggregateMessage | ||
{ | ||
public static function messageType(): string | ||
{ | ||
return 'domain_event'; | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Exception; | ||
|
||
abstract class AggregateException extends DomainException | ||
{ | ||
abstract public function id(): string; | ||
|
||
abstract public function aggregateType(): string; | ||
|
||
final public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'id' => $this->id(), | ||
'aggregateType' => $this->aggregateType(), | ||
]; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Exception; | ||
|
||
abstract class DomainException extends \DomainException implements \JsonSerializable | ||
{ | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Exception; | ||
|
||
abstract class ExistsException extends AggregateException | ||
{ | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Exception; | ||
|
||
abstract class LogicException extends DomainException | ||
{ | ||
abstract public function data(): array; | ||
|
||
final public function jsonSerialize(): array | ||
{ | ||
return $this->data(); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Exception; | ||
|
||
abstract class NotFoundException extends AggregateException | ||
{ | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Message; | ||
|
||
use Colvin\CommonDomain\Domain\Model\ValueObject\Uuid; | ||
|
||
abstract class ActionMessage extends Message | ||
{ | ||
final public static function fromPayload(Uuid $messageId, array $payload): static | ||
{ | ||
return new static($messageId, $payload); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Colvin\CommonDomain\Domain\Message; | ||
|
||
use Colvin\CommonDomain\Domain\Model\ValueObject\DateTimeValueObject; | ||
use Colvin\CommonDomain\Domain\Model\ValueObject\Uuid; | ||
|
||
abstract class AggregateMessage extends Message | ||
{ | ||
final protected function __construct( | ||
Uuid $messageId, | ||
private Uuid $aggregateId, | ||
private DateTimeValueObject $occurredOn, | ||
array $payload | ||
) { | ||
parent::__construct($messageId, $payload); | ||
} | ||
|
||
final public static function fromPayload( | ||
Uuid $messageId, | ||
Uuid $aggregateId, | ||
DateTimeValueObject $occurredOn, | ||
array $payload | ||
): static { | ||
return new static($messageId, $aggregateId, $occurredOn, $payload); | ||
} | ||
|
||
public function aggregateId(): Uuid | ||
{ | ||
return $this->aggregateId; | ||
} | ||
|
||
final public function jsonSerialize(): array | ||
{ | ||
return \array_merge( | ||
parent::jsonSerialize(), | ||
[ | ||
'aggregateId' => $this->aggregateId->value(), | ||
'occurredOn' => $this->occurredOn->jsonSerialize(), | ||
], | ||
); | ||
} | ||
|
||
public function occurredOn(): DateTimeValueObject | ||
{ | ||
return $this->occurredOn; | ||
} | ||
} |
Oops, something went wrong.