mirror of
https://gitlab.com/izyim/prototypes/ddd-example.git
synced 2026-08-19 04:24:04 +00:00
Add common domain and presentation layer
1. domain exception 2. create domain command
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain;
|
||||
|
||||
class AggregateRoot
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain;
|
||||
|
||||
use Src\Common\Domain\Exceptions\UnauthorizedUserException;
|
||||
|
||||
interface CommandInterface
|
||||
{
|
||||
/**
|
||||
* @throws UnauthorizedUserException
|
||||
*/
|
||||
public function execute();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain\Exceptions;
|
||||
|
||||
class EntityNotFoundException extends \DomainException
|
||||
{
|
||||
public function __construct(string $message = 'Entity not found')
|
||||
{
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain\Exceptions;
|
||||
|
||||
final class IncorrectEmailFormatException extends \DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Must be a valid email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain\Exceptions;
|
||||
|
||||
final class MaximumValueException extends \DomainException
|
||||
{
|
||||
public function __construct($fieldName, $value)
|
||||
{
|
||||
parent::__construct(__("The maximum value for '$fieldName' is '$value"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain\Exceptions;
|
||||
|
||||
final class RequiredException extends \DomainException
|
||||
{
|
||||
public function __construct($fieldName)
|
||||
{
|
||||
parent::__construct(trans('validation.required', ['attribute' => $fieldName]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain\Exceptions;
|
||||
|
||||
final class UnauthorizedUserException extends \Exception
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The user is not authorized to access this resource');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Domain;
|
||||
|
||||
use Src\Common\Domain\Exceptions\UnauthorizedUserException;
|
||||
|
||||
interface QueryInterface
|
||||
{
|
||||
/**
|
||||
* @throws UnauthorizedUserException
|
||||
*/
|
||||
public function handle(): mixed;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Common\Presentation\CLI;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class CreateDomainCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'make:domain {boundedContext} {domainName}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates a new domain directory structure';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$basePath = 'src/' . $this->argument('boundedContext') . '/' . $this->argument('domainName');
|
||||
|
||||
// Application
|
||||
$applicationStructure = [
|
||||
'DTO',
|
||||
'Repositories/Eloquent',
|
||||
'Exceptions',
|
||||
'Jobs',
|
||||
'Providers',
|
||||
'Mappers',
|
||||
'UseCases/Commands',
|
||||
'UseCases/Queries',
|
||||
];
|
||||
foreach ($applicationStructure as $applicationDirectory) {
|
||||
File::makeDirectory($basePath . '/Application/' . $applicationDirectory, 0755, true);
|
||||
touch($basePath . '/Application/' . $applicationDirectory . '/.gitkeep');
|
||||
}
|
||||
|
||||
// Domain
|
||||
$domainStructure = [
|
||||
'Exceptions',
|
||||
'Factories',
|
||||
'Model',
|
||||
'Policies',
|
||||
'Repositories',
|
||||
'Services'
|
||||
];
|
||||
foreach ($domainStructure as $domainDirectory) {
|
||||
File::makeDirectory($basePath . '/Domain/' . $domainDirectory, 0755, true);
|
||||
touch($basePath . '/Domain/' . $domainDirectory . '/.gitkeep');
|
||||
}
|
||||
|
||||
// Infrastructure
|
||||
$infrastructureStructure = [
|
||||
'EloquentModels'
|
||||
];
|
||||
foreach ($infrastructureStructure as $infrastructureDirectory) {
|
||||
File::makeDirectory($basePath . '/Infrastructure/' . $infrastructureDirectory, 0755, true);
|
||||
touch($basePath . '/Infrastructure/' . $infrastructureDirectory . '/.gitkeep');
|
||||
}
|
||||
|
||||
// Presentation
|
||||
$presentationStructure = [
|
||||
'API',
|
||||
'CLI',
|
||||
'HTTP'
|
||||
];
|
||||
foreach ($presentationStructure as $presentationDirectory) {
|
||||
File::makeDirectory($basePath . '/Presentation/' . $presentationDirectory, 0755, true);
|
||||
touch($basePath . '/Presentation/' . $presentationDirectory . '/.gitkeep');
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user