devhelp/flow-control

组件,用于控制流程中的状态变化。

1.0 2014-10-04 18:23 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:21:56 UTC


README

Build Status SensioLabsInsight

安装

推荐使用 Composer 安装 Flow Control,请访问Composer 网站获取更多信息。

$ composer require 'devhelp/flow-control:dev-master'

用途

Flow Control 是一个简单的工具,允许控制 Flow 类中定义的流程。

有两个主要的类:Flow 和 FlowControl。Flow 使用移动数组入口点定义,FlowControl 用于控制流程中的状态变化。

流程的概念是通用的,一些明显的用例可以是定义和控制结账流程中的流程。

用法

//two way flow with optional 'step_c'
$exampleFlowA = new Flow(
    'flow_a',
    array(
        'step_a' => array('step_b'),
        'step_b' => array('step_a', 'step_c', 'step_d'),
        'step_c' => array('step_b', 'step_d'),
        'step_d' => array('step_b', 'step_c')
    ),
    array('step_a')
);

//one way flow
$exampleFlowB = new Flow(
    'flow_b',
    array(
        'step_a' => array('step_b'),
        'step_b' => array('step_c'),
        'step_c' => array('step_d'),
    ),
    array('step_a')
);

$flows = array($exampleFlowA, $exampleFlowB);

$repository = new SimpleFlowRepository($flows);

$flowControl = new FlowControl($repository);

/**
 * origin of current steps is out of the scope of FlowControl component,
 * the same is regarding changing the state in the flow. FlowControl
 * is only for resolving valid moves
 */
$currentSteps = array(
    'flow_a' => 'step_c',
);

$flowControl->setFlowSteps($currentSteps);

$flowControl->isAllowed('step_d', 'flow_a'); //true
$flowControl->isAllowed('step_a', 'flow_a'); //false
$flowControl->isAllowed('step_c', 'flow_a'); //true
$flowControl->isAllowed('step_a', 'flow_b'); //true
$flowControl->isAllowed('step_b', 'flow_b'); //false

$moves = array(
    'flow_a' => 'step_d',
    'flow_b' => 'step_b',
);

$validMoves = $flowControl->resolveValid($moves); //array('flow_a' => 'step_d')

鸣谢

由 Devhelp.pl 提供:http://devhelp.pl