t4web / domain-module
ZF2 Module for Domain implementation.
Installs: 1 495
Dependents: 5
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 0
Open Issues: 0
Type:zf2-module
Requires
- php: >=5.5.0
- t4web/domain: ~1.2.0
- t4web/infrastructure: ~2.0.1
- zendframework/zend-modulemanager: >=2.6
- zendframework/zend-mvc: >=2.6
- zendframework/zend-servicemanager: >=2.6
Requires (Dev)
- phpunit/phpunit: ~4.5
- squizlabs/php_codesniffer: ^2.3
README
ZF2 Module for Domain implementation and Infrastructure implementation. Provide dynamically setup Domain layer.
Main Setup
By cloning project
- Clone this project into your
./vendor/
directory.
With composer
- Add this project in your composer.json:
"require": { "t4web/domain-module": "~1.3.0" }
- Now tell composer to download DomainModule by running the command:
$ php composer.phar update
Post installation
- Enabling it in your
application.config.php
file.
<?php return array( 'modules' => array( // ... 'T4web\DomainModule', ), // ... );
Quick start
Describe entity:
class Task extends \T4webDomain\Entity { protected $name; protected $assigneeId; protected $status; protected $type; /** * @var Users\User\User */ protected $assignee; public function __construct(array $data, Users\User\User $assignee = null) { parent::__construct($data); $this->assignee = $assignee; } /** * @return Users\User\User */ public function getAssignee() { return $this->assignee; } }
Describe entity_map config in your module.config.php
:
return [ // ... 'entity_map' => [ 'Task' => [ // table name 'table' => 'tasks', // optional, only if you have use short service names 'entityClass' => 'Tasks\Task\Task', // optional, only if you have use short service names 'collectionClass' => 'Tasks\Task\TaskCollection', // optional, by default 'id' 'primaryKey' => 'id', // map entity field with table field 'columnsAsAttributesMap' => [ 'id' => 'id', 'name' => 'name', 'assigneeId' => 'assignee_id', 'status' => 'status', 'type' => 'type', ], // optional, aliases for criteria - for pretty query args 'criteriaMap' => [ 'id' => 'id_equalTo' ], // optional, relations for filtering and fetching aggregate entity 'relations' => [ 'User' => ['tasks.assignee_id', 'users.id'] ], ], ], ];
You can get Domain layer from ServiceManager:
// in your controller $creator = $serviceLocator->get('Task\Service\Creator'); $task = $creator->create(['name' => 'buy milk', 'type' => 2]); if (!$task) { return ['errors' => $creator->getMessages()]; } $repository = $serviceLocator->get('Task\Infrastructure\Repository'); /** @var Tasks\Task\Task $task */ $task = $repository->findById(123); $repository = $serviceLocator->get('Task\Infrastructure\AggregateRepository'); $task = $repository->findWith('User')->findById(123); /** @var Users\User\User $assignee */ $assignee = $task->getAssignee();
Components
MODULE-NAME\ENTITY-NAME\Infrastructure\Repository
MODULE-NAME\ENTITY-NAME\Service\Creator
MODULE-NAME\ENTITY-NAME\Service\Deleter
MODULE-NAME\ENTITY-NAME\Service\Updater
MODULE-NAME\ENTITY-NAME\EntityFactory
Service classes:
MODULE-NAME\ENTITY-NAME\Infrastructure\Config
MODULE-NAME\ENTITY-NAME\Infrastructure\Mapper
MODULE-NAME\ENTITY-NAME\Infrastructure\QueryBuilder
We recommend use short service names - without module name
ENTITY-NAME\Infrastructure\Repository
ENTITY-NAME\Service\Creator
ENTITY-NAME\Service\Deleter
ENTITY-NAME\Service\Updater
ENTITY-NAME\EntityFactory
Service classes:
ENTITY-NAME\Infrastructure\Config
ENTITY-NAME\Infrastructure\Mapper
ENTITY-NAME\Infrastructure\QueryBuilder
When you use short service names - entityClass
config parameter is required.