rtens/domin
Composer 安装命令:
composer require rtens/domin
包简介
General purpose DDD-friendly administration interface
README 文档
README
domin ( domain model interface ) is an administration interface for abstract Domain Models using the Command Object pattern.
For an example of how to use use, check out the sample application.
Model
Every ability of a system is represented by an Action which specifies how to execute it and what Parameters
it requires. Therefore domin can take care of getting missing parameters from the user using Fields. Actions may
return values which are presented using Renderers.
Installation
To use domin in your project, require it with Composer
composer require rtens/domin
If you would like to develop on domin, download it with Composer and execute the specification with scrut
composer create-project -sdev rtens/domin
cd domin
vendor/bin/scrut spec
Quick Start
To run domin as a web application with curir as delivery system, paste the following code into index.php
use rtens\domin\delivery\web\adapters\curir\root\IndexResource; use rtens\domin\delivery\web\WebApplication; use watoki\curir\WebDelivery; WebDelivery::quickResponse(IndexResource::class, WebDelivery::init(null, WebApplication::init(function (WebApplication $app) { // Set-up $app here (e.g. $app->actions->add('foo', ...)) })));
To run domin with silex, past this code into index.php
use rtens\domin\delivery\web\adapters\silex\SilexControllerProvider; use rtens\domin\delivery\web\WebApplication; use Silex\Application; require_once __DIR__ . '/vendor/autoload.php'; $app = new Application(); $app->mount('/', new SilexControllerProvider( WebApplication::init(function (WebApplication $app) { // Set-up $app here (e.g. $app->actions->add('foo', ...)) }))); $app->run();
And then start a development server to access the application on localhost:8000
$ php -S localhost:8000 index.php
To get the CLI application running, paste this code into cli.php
use rtens\domin\delivery\cli\CliApplication; CliApplication::run(CliApplication::init(function (CliApplication $app) { // Set-up $app here (e.g. $app->actions->add('foo', ...)) }));
and run it with
$ php cli.php
Action!
Actions decide what Parameters they need, how to fill() them with default values and, most importantly, how to execute() them.
The way domin knows what actions there are is through the ActionRegistry, so all actions need to be added to it.
There are several ways to create actions:
Implementing Action
The most straight-forward although probably not most convenient way is to create an implementation of Action for
every ability of the system.
class MyAction implements Action { public function caption() { return 'Some Action'; } public function description() { return 'Some Description'; } public function parameters() { return [ new Parameter('foo', new StringType()), new Parameter('bar', new ClassType(\DateTime::class)) ]; } public function fill(array $parameters) { $parameters['foo'] = 'default value of foo'; return $parameters; } public function execute(array $parameters) { return "Make it so! " . json_encode($parameters); } } $actionRegistry->add('my', new MyAction());
Extending ObjectAction
If you represent abilities with DTOs, you can extend you actions from the ObjectAction to infer Parameters from
the properties of these classes using reflection. This sub-class can then be made generic for example by using
a Command Bus.
class MyAction extends ObjectAction { public function __construct($class, TypeFactory $types, CommandBus $bus) { parent::__construct($class, $types); $this->bus = $bus; } protected function executeWith($object) { $this->bus->handle($object); } } $actionRegistry->add('my', new MyAction(MyCommand::class, $types, $bus)); $actionRegistry->add('your', new MyAction(YourCommand::class, $types, $bus)); $actionRegistry->add('their', new MyAction(TheirCommand::class, $types, $bus));
Generating ObjectActions
With a generic way to execute actions, you can use the ObjectActionGenerator to generate and register actions from
all classes in a folder automatically.
(new ObjectActionGenerator($actionRegistry, $typeFactory))->fromFolder('model/commands', function ($object) { $bus->handle($object); });
Using MethodAction
If you don't feel like creating a class for every command, you can use the MethodAction to infer parameters
from a method signature.
$actionRegistry->add('my', new MethodAction($handler, 'handleMyCommand', $typeFactory)); $actionRegistry->add('your', new MethodAction($handler, 'handleYourCommand', $typeFactory)); $actionRegistry->add('their', new MethodAction($handler, 'handleTheirCommand', $typeFactory));
Generating MethodActions
There is also a MethodActionGenerator to register all methods of an object.
(new MethodActionGenerator($actionRegistry, $typeFactory))->fromObject($handler);
License
domin is released under the MIT License
rtens/domin 适用场景与选型建议
rtens/domin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.07k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「cms」 「ddd」 「administration」 「domain model」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rtens/domin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rtens/domin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rtens/domin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Value Objects Library
2lenet/EasyAdminPlusBundle
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 1.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-02