antonyan / ddd-mappers-infrastructure
DDD project infrastructure
Installs: 1 197
Dependents: 1
Suggesters: 0
Security: 0
Stars: 8
Watchers: 8
Forks: 2
Open Issues: 1
Requires
- php: >=7.1.0
- aws/aws-php-sns-message-validator: ^1.1
- aws/aws-sdk-php: ^3.24
- doctrine/annotations: ^1.6
- doctrine/dbal: ^2.8
- doctrine/migrations: ^1.8
- guzzlehttp/guzzle: ^6.3
- maxbanton/cwh: ^1.0
- monolog/monolog: ^1.21
- symfony/dependency-injection: ^4.1
- symfony/event-dispatcher: ^4.1
- symfony/http-foundation: ^4.1
- symfony/http-kernel: ^4.1
- symfony/routing: ^4.1
- symfony/validator: ^4.1
- vlucas/phpdotenv: ^2.5
Requires (Dev)
- phpunit/phpunit: 6.*
- dev-master
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.1
- v4.0
- v3.5.1
- v3.5
- v3.4.0
- v3.3
- v3.2
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.11
- v2.10
- v2.9.1
- v2.9
- v2.8.1
- 2.8
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7
- v2.6
- v2.5.1
- v2.5
- v2.4
- 2.3
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2
- v2.1.2
- v2.1.1
- v2.1
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- v1.7.5
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0
- dev-filter_empty_values
- dev-fix_validation_filter
This package is auto-updated.
Last update: 2024-11-06 23:42:24 UTC
README
Infrastructure layer for DDD project based on Data Mapper as Data source pattern Data Mapper
General
In case if you use this layer with DDD project all functionality will be plugged automatically. An entry point is an Application class. Which uses Symfony HttpKernel as an engine.
Main flow
- An application gets a controller (Service of the presentation layer) and method from a request.
- Dispatch event for request preprocessing: filtering, validation etc.
- Call controller.
Dependency management
The architecture of the current application implies that main business logic will place in services. Each module and context will have representative service. Service extends BaseService which get a container (Dependency Injection) and config from "config" folder at the level above. On top of that container for each Service is automatically merged with infrastructure container.
Infrastructure container
Infrastructure container includes db connection, MySqlClient, RequestFactory, HttpClient.
DB interaction
Connection
If you're using MySQL as DB you should specify DDD_RBD_NAME, DDD_RBD_USER, DDD_RBD_PASSWORD, DDD_RBD_HOST, DDD_RBD_DRIVER (pdo_mysql) as env variables or just in .env file of the DDD project
DbMapper
For Rapid application development (RAD) we were created such abstraction as DbMapper. If you need CRUD implementation only it'll be supported out of the box. All that you need is to specify table and fields mapping in Module config. For create and update you should specify identifiers names. Config example:
'DeliveryDbTranslator' => [
'table' => 'deliveries',
'columns' => [
'id' => 'deliveries.id',
'deliveryCostId' => 'deliveries.deliveryCostId',
'orderId' => 'deliveries.orderId',
'status' => 'deliveries.status',
'deliveryTime' => 'deliveries.deliveryTime',
'locationId' => 'deliveries.locationId',
'deliveryPhone' => 'deliveries.deliveryPhone',
'contactPerson' => 'deliveries.contactPerson',
'notice' => 'deliveries.notice',
],
'create' => 'id',
'update' => ['id'],
],
Http interaction
HttpMapper
If the resource that you need you should get from another service (by HTTP(s)) you can use HTTP mapper which interface is similar to DbMapper. Config example:
return [
'httpConfig' => [
'availableUrls' => [
'get' => getenv('SOME_MICROSERVICE_BASE_URL').'/users/:id',
]
],
];
Logging
For logging purpose we're using Monolog, but of course, we encapsulated it to rid of dependencies. We support logging to the file and to the CloudWatch. To use logging you should create Service (example):
class SomeLogger extends LogService
{
/**
* @return string
*/
protected function getChannelName(): string
{
return "specific-channel-name";
}
}
On top of that, you should specify env variable with log destination LOGGING_TYPE = file or LOGGING_TYPE = cloudWatch
Customize your services
application.error.handler
is reserved service to override to handle api fail response on exception