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' |