Composer is preferred way to install FlowControlBundle, please check composer website for more information.
$ composer require 'devhelp/flow-control-bundle:dev-master'
FlowControlBundle provides integration with FlowControl library regarding controller actions. It allows you to define your actions as flow steps, meaning that user won't be able to enter an action unless he/she reaches expected step in your flow.
You can, for example:
- define checkout flow for your online store
- define multiple flows at once for different use cases
There is a sandbox app available on github where you can take closer look at the bundle and how it can be used
devhelp_flow_control:
flows:
#your flow name
my_checkout_flow:
moves:
order_configuration: [order_summary]
order_summary: [order_configuration, payment]
payment: [order_configuration, order_summary, payment_summary]
entry_points: [order_configuration]
my_simple_checkout_flow:
moves:
buy_now: [order_summary]
order_summary: [payment]
payment: [payment_summary]
entry_points: [buy_now]
#multiple flows can be defined
use Devhelp\FlowControlBundle\FlowConfiguration\Annotation\Flow;
class OrderController
{
/**
* @Flow(name="my_simple_checkout_flow", step="buy_now")
*/
public function buyNowAction()
{
//...
}
/**
* @Flow(name="my_checkout_flow", step="order_configuration")
*/
public function configureAction()
{
//...
}
/**
* @Flow(name="my_checkout_flow", step="order_summary")
* @Flow(name="my_simple_checkout_flow", step="order_summary")
*/
public function summaryAction()
{
//...
}
}
use Devhelp\FlowControlBundle\FlowConfiguration\Annotation\Flow;
class PaymentController
{
/**
* @Flow(name="my_checkout_flow", step="payment")
* @Flow(name="my_simple_checkout_flow", step="payment")
*/
public function paymentAction()
{
//...
}
/**
* @Flow(name="my_checkout_flow", step="payment_summary")
* @Flow(name="my_simple_checkout_flow", step="payment_summary")
*/
public function summaryAction()
{
//...
}
}
Now if you enter an url for action that is a step in some flow, your access will be restricted if the move is not valid
Every action that ends with successful or redirect response is treated as success and ending such action will result in changing current step in the flow for every valid move
'devhelp.flow_control.current_steps' service is responsible for it. Default implementation stores current steps in session
Right now it is not configurable from the bundle itself (will be soon), but you can use CompilerPass to replace 'devhelp.flow_control.current_steps' service with custom implementation
You can disable this in action configuration
use Devhelp\FlowControlBundle\FlowConfiguration\Annotation\Flow;
use Devhelp\FlowControlBundle\FlowConfiguration\Annotation\DisableAutocommit;
class ExampleController
{
/**
* @Flow(name="my_flow", step="my_step")
* @DisableAutocommit
*/
public function fooAction()
{
//...
}
}
Take a look at the FlowStepsUpdateListener for guidance
Currently suggested way is to intercept NoValidStepsFoundException on 'kernel.exception' event and replace the Response
Brought to you by : Devhelp.pl (http://devhelp.pl)