2017 © Pedro Peláez
 

symfony-bundle flow-bundle

Symfony2 flow manager, process entities by flows (status)

image

redcode/flow-bundle

Symfony2 flow manager, process entities by flows (status)

  • Tuesday, December 17, 2013
  • by maZahaca
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Using transit between statuses with redcode-flow bundle

Steps to start * Mark with annotation status field or status entity. Example:, (*1)

``` php 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; }, (*2)

use RedCode\Flow\Annotation\Status as Flow; /** * @ORM\Entity */ class OrderStatus { /** * @var int * @Flow\StatusValue * @ORM\Column(type="integer") */ private $status; }, (*3)


* Create your manager and extend it from FlowManager ``` php 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 ); } }
  • Create your own flows between statuses

``` php use RedCode\Flow\Item\BaseFlow;, (*4)

class SomeFlow extends BaseFlow { public function __construct() { // set allowed user roles or set false to switch off option $this->roles = [ 'ROLE_ADMIN' ];, (*5)

    // 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;
}

}, (*6)


* Define service in xml or yaml file ``` xml <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>
  • Use service in your code

php /** * Modify order or it status and save using method execute */ $container->get('order.manager')->execute($order);, (*7)

The Versions

17/12 2013

0.1.x-dev

0.1.9999999.9999999-dev https://github.com/maZahaca/redcode-flow

Symfony2 flow manager, process entities by flows (status)

  Sources   Download

MIT

The Requires

 

bundle symfony status flow transit