t4web/domain-module
最新稳定版本:1.5.0
Composer 安装命令:
composer require t4web/domain-module
包简介
ZF2 Module for Domain implementation.
关键字:
README 文档
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.phpfile.
<?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\RepositoryMODULE-NAME\ENTITY-NAME\Service\CreatorMODULE-NAME\ENTITY-NAME\Service\DeleterMODULE-NAME\ENTITY-NAME\Service\UpdaterMODULE-NAME\ENTITY-NAME\EntityFactory
Service classes:
MODULE-NAME\ENTITY-NAME\Infrastructure\ConfigMODULE-NAME\ENTITY-NAME\Infrastructure\MapperMODULE-NAME\ENTITY-NAME\Infrastructure\QueryBuilder
We recommend use short service names - without module name
ENTITY-NAME\Infrastructure\RepositoryENTITY-NAME\Service\CreatorENTITY-NAME\Service\DeleterENTITY-NAME\Service\UpdaterENTITY-NAME\EntityFactory
Service classes:
ENTITY-NAME\Infrastructure\ConfigENTITY-NAME\Infrastructure\MapperENTITY-NAME\Infrastructure\QueryBuilder
When you use short service names - entityClass config parameter is required.
统计信息
- 总下载量: 1.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-11-09