承接 devhelp/procedure 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devhelp/procedure

Composer 安装命令:

composer require devhelp/procedure

包简介

introduces mechanism that allows you to define steps with its arguments that are going to be interpreted in order they are defined in the procedure

README 文档

README

Build Status SensioLabsInsight

Installation

Composer is preferred to install devhelp/procedure, please check composer website for more information.

$ composer require 'devhelp/procedure:dev-master'

Purpose

devhelp/procedure introduces mechanism that allows you to define steps with its arguments that are going to be interpreted(*) in order they are defined in the procedure.

"interpreted" can mean, for example, "called" if such interpreter will be set to interpret the steps.

devhelp/procedure is shipped with CallableInterpreter, example usage is shown below.

Usage

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Devhelp\Procedure\ProcedureRunner;
use Devhelp\Procedure\ArgumentResolver;
use Devhelp\Procedure\Interpreter\CallableInterpreter;
use Devhelp\Procedure\Model\Procedure;
use Devhelp\Procedure\Model\Step;
use Devhelp\Procedure\Model\Reference;

//example class
class Math
{
    public static function add($a, $b) {
        return $a + $b;
    }

    public static function mul($a, $b) {
        return $a * $b;
    }
}

/**
 * because we are using CallableInterpreter in the example, first argument
 * of step arguments is a callback
 */

$stepOne = new Step('add_1', array('Math::add', 1, 1));
//1 + 1 = 2 (store result as 'add_1')

$stepTwo = new Step('add_2', array('Math::add', 2, 2));
//2 + 2 = 4 (store result as 'add_2')

$stepThree = new Step('mul', array('Math::mul', new Reference('add_1'), new Reference('add_2')));
//2 * 4 = 8 (store result as 'mul')

$stepFour = new Step('dec2bin', array('decbin', new Reference('mul')));
//decbin(8) = '1000' (store result as 'dec2bin', but since this is last step it does not matter)

$procedure = new Procedure(array($stepOne, $stepTwo, $stepThree, $stepFour));


$argumentResolver = new ArgumentResolver();
$interpreter = new CallableInterpreter();

$runner = new ProcedureRunner();
$runner->setArgumentResolver($argumentResolver);
$runner->setInterpreter($interpreter);

echo $runner->follow($procedure), PHP_EOL; //returns result of last step ('1000')

FAQ

How can I change interpretation

You can write own interpreter class and set it in ProcedureRunner. It has to implement Devhelp\Procedure\Interpreter\InterpreterInterface.

<?php

namespace Acme\Demo\Interpreter;


use Devhelp\Procedure\Model\Step;
use Devhelp\Procedure\Exception\StepInterpretationException;
use Devhelp\Procedure\Interpreter\InterpreterInterface;

class MyCustomInterpreter implements InterpreterInterface
{
    /**
     * {@inheritdoc}
     */
    public function interpret(Step $step, array $arguments)
    {
        /**
         * my custom logic that interprets the step
         */
    }
}

Credits

Brought to you by : Devhelp.pl (http://devhelp.pl)

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固