redcode / flow-bundle
Symfony2 流管理器,通过流(状态)处理实体
0.1.x-dev
2013-12-17 12:00 UTC
Requires
- php: >=5.4.0
- redcode/flow: 0.1.x-dev
- symfony/framework-bundle: 2.3.*
This package is not auto-updated.
Last update: 2024-09-24 01:22:50 UTC
README
启动步骤
- 使用状态字段或状态实体进行标注。例如
use RedCode\Flow\Annotation\Status as Flow; /** * @ORM\Entity */ class Order { /** * @var OrderStatus * @Flow\StatusEntity * @ORM\ManyToOne(targetEntity="OrderStatus", cascade={"persist"}) * @ORM\JoinColumn(name="status_id") */ private $status; } use RedCode\Flow\Annotation\Status as Flow; /** * @ORM\Entity */ class OrderStatus { /** * @var int * @Flow\StatusValue * @ORM\Column(type="integer") */ private $status; }
- 创建你的管理器并从FlowManager扩展
use RedCode\Flow\FlowManager; use RedCode\Flow\Annotation\Reader; class OrderManager extends FlowManager { public function __construct(SecurityContext $securityContext, EntityManager $em, Reader $reader, array $flows = array ()) { parent::__construct( $securityContext, $em, $reader, 'Order', // class name $flows ); } }
- 在状态之间创建自己的流
use RedCode\Flow\Item\BaseFlow; class SomeFlow extends BaseFlow { public function __construct() { // set allowed user roles or set false to switch off option $this->roles = [ 'ROLE_ADMIN' ]; // set allowed movements between statuses $this->movements = [ new FlowMovement(1, 2), new FlowMovement(null, 2), ]; } /** * @inheritDoc */ public function execute($entity, FlowMovement $movement) { // some actions when transit comes return $entity; } }
- 在xml或yaml文件中定义服务
<service id="order.manager" class="OrderManager"> <argument type="service" id="security.context" /> <argument type="service" id="em" /> <argument type="service"> <service class="RedCode\Flow\Annotation\Reader"> <argument type="service" id="annotation_reader"/> <argument type="service" id="em"/> </service> </argument> <argument type="collection"> <argument type="service"> <service class="SomeFlow"> </service> </argument> </argument> <argument type="service" id="em" /> </service>
- 在你的代码中使用服务
/** * Modify order or it status and save using method execute */ $container->get('order.manager')->execute($order);