, (*1)
Installation
Composer is preferred way to install FlowControlBundle, please check composer website for more information., (*2)
$ composer require 'devhelp/flow-control-bundle:dev-master'
Purpose
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., (*3)
You can, for example:
- define checkout flow for your online store
- define multiple flows at once for different use cases, (*4)
Usage
There is a sandbox app available on github where you can take closer look at the
bundle and how it can be used, (*5)
Define your flow in config.yml
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
Define controller actions as flow steps
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()
{
//...
}
}
Done!
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, (*6)
FAQ
How does it change the steps in flow ?
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, (*7)
Where are the current steps stored ?
'devhelp.flow_control.current_steps' service is responsible for it. Default implementation stores current steps in session, (*8)
How can I change the way current steps are stored
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, (*9)
I don't want my action to automatically update current steps
You can disable this in action configuration, (*10)
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()
{
//...
}
}
How can I manually update my moves ?
Take a look at the FlowStepsUpdateListener for guidance, (*11)
How can I customize what happens once no valid steps are found for the action ?
Currently suggested way is to intercept NoValidStepsFoundException on 'kernel.exception' event and replace the Response, (*12)
Credits
Brought to you by : Devhelp.pl (http://devhelp.pl), (*13)