PHPackages                             antonyan/ddd-mappers-project - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. antonyan/ddd-mappers-project

ActiveProject[Utility &amp; Helpers](/categories/utility)

antonyan/ddd-mappers-project
============================

DDD project skeleton

v2.1(7y ago)9191MITPHPPHP &gt;=7.1.0

Since Aug 28Pushed 7y ago4 watchersCompare

[ Source](https://github.com/Antonyan/ddd-mappers-project)[ Packagist](https://packagist.org/packages/antonyan/ddd-mappers-project)[ RSS](/packages/antonyan-ddd-mappers-project/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

DDD project
===========

[](#ddd-project)

This project is intended to help developers in the implementation of DDD approach with PHP programming language. There is a lot of theoretical information and a few examples.

DDD-mappers-project has all that yo u need to create a commercial product in the short term and high quality (high level of maintainability means)

Overview
--------

[](#overview)

Our team doesn't want to emphasize technical things that's why we're using well-known solutions like Symfony components where it's possible.

Besides, we've created a lot of different useful features that can significantly accelerate the development.

Quick start
-----------

[](#quick-start)

All that you need is to run a command `composer create-project antonyan/ddd-mappers-project nameOfYourProject`[Setup DB](https://github.com/Antonyan/ddd-mappers-infrastructure) See Db interaction -&gt; connection

Request
-------

[](#request)

To validate request data we created annotations that you can specify in presentation service (controller). Presentation services are usually based in `/src/app/Services`

Example:

```
/**
     * @Validation(name="phone", type="string", required=true, maxLength=50)
     * @Validation(name="email", type="string", required=true, maxLength=100)
     * @Validation(name="firstName", type="string", required=true, maxLength=100)
     * @Validation(name="lastName", type="string", required=true, maxLength=100)
     * @Validation(name="status", type="string", required=true, maxLength=30)
     * @Validation(name="roles", type="array", required=true)
     *
     * @param Request $request
     * @return CreateEntityJsonResponse
     */
    public function create(Request $request): CreateEntityJsonResponse
    {
        return new CreateEntityJsonResponse($this->getUserService()->create($request->request->all())->toArray());
    }

```

In this case, our validator checks all specified fields and remove any additional from a request.

Available validation types:

```
'array', 'bool', 'float', 'double', 'int', 'integer', 'numeric', 'string'

```

Routing
-------

[](#routing)

Config for request you can find by path `/src/app/config/restRoutes.php`The project uses `Symfony\Component\Routing\RouteCollection` under the hood but we did several improvements that make easy to add a route.

If you need to create a route for a specific case you can use addGET, addPOST, addDELETE or addPUT. In case if you are creating data-centric module you can use addCRUD and project creates all urls with mapping to the presentation service (controller).

```
$routesCollectionBuilder = new RouteCollectionBuilder();

$routesCollectionBuilder->addCRUD('/restaurants', Restaurant::class);

$routesCollectionBuilder->addGET('you/url', 'YouService', 'youMethod');

return $routesCollectionBuilder->build();

```

Context
-------

[](#context)

The main idea of this project to allow a developer to create architecture which will consist of contexts and modules. Easiest way to create context is generate it with `vendor/bin/generate context -n ContextName` command. It'll be created in `/srs/contexts/` and consists of config, Services folders and Contract.

#### config

[](#config)

Folder consists of two files config.php and container.php In config.php you can specify all data that can be changed but should be available in Service (e.x. time to live for token, number of attempts etc.)

Container is used to specify dependencies (Dependency Injection). In this file you should register all module services.

Example: ` $containerBuilder->register('UserService', Contexts\User\UserModule\Services\UserService::class);`

#### Services

[](#services)

In this folder, you can see context service which orchestrates interactions with all services from module level. It can be simple method call

```
    public function create(array $data): UserAggregate
    {
        return $this->getUserAggregateService()->create($data);
    }

```

or it can receive some information from one service and send it to another.

#### Contract

[](#contract)

It's a context contract and services outside context can use it only for interaction with a module.

Example: To use UserService you should specify in presentation service (controller)

```
    private function getUserService(): UserContract
    {
        return $this->container()->get('UserService');
    }

```

Module
------

[](#module)

If you want to create a Module in a quick way you should create Model in the root of the context ` /src/contexts/SomeContext`

Example:

```
