DomainComponent
[2.1.4] - 2020-09-01
该库的设计旨在帮助您使用域设计开发方法来构建应用程序。
它与:
但是您可以将其与任何PHP项目一起使用。
这里有一些幻灯片解释我们如何到达那里。
域事件:
该库的构建是为了允许您使用学说模型作为域模型。这有一定的成本:您不能再手工实例化域模型了。这意味着您需要用于域模型的任何使用工厂。
该组件为Symfony Serialiser和Toctrine提供了实现。为了您自己的需要,您应该使用类(如果使用捆绑包,服务) BiigComponentDomainModelInstantiatorInstantiator 。
composer require biig/domain class YourModel extends DomainModel
{
public const CREATION = ' creation ' ;
public function __construct ()
{
$ this -> dispatch ( new DomainEvent ( $ this ), self :: CREATION );
}
} class DomainRule implements DomainRuleInterface
{
public function on ()
{
return YourModel :: CREATION ;
}
public function execute ( DomainEvent $ event )
{
// Do Something on your model creation
}
}由于您的模型需要一个调度程序,因此每当创建模型的新实例时,都需要调用setDispatcher()方法。为了避免手动执行此操作,您可以使用库提供的Instantiator 。
它不会使用构造函数添加调度程序,因为在PHP中,您可以在没有构造函数的情况下创建对象。例如,这就是学说的作用。
使用捆绑包:
<?php
// config/bundles.php
return [
// ...
Biig Component Domain Integration Symfony DomainBundle ::class => [ ' all ' => true ],
];了解有关Symfony集成的更多信息
| 版本 | 地位 | 文档 | Symfony版本 | PHP版本 |
|---|---|---|---|---|
| 1.x | 维护 | V1 | '> = 3.3 && <5' | '> = 7.1' |
| 2.x | 最新的 | v2 | '> = 4.3' | '> = 7.1' |