kitpages/step-bundle

这是一个包含工作流系统步骤的Symfony2扩展包。

安装: 684

依赖项: 1

建议者: 0

安全: 0

星标: 0

关注者: 5

分支: 0

开放问题: 0

类型:symfony-bundle

v1.1.0 2014-02-11 16:17 UTC

This package is auto-updated.

Last update: 2024-09-04 18:56:35 UTC


README

Build Status

此扩展包为未来工作流系统提供步骤系统。

版本

2014年11月2日 : v1.1.0

  • 没有向后不兼容的更改
  • 新功能 : 停表计时器,以查看SF2调试工具栏中的步骤使用情况
  • 增强 : 更多的单元测试

2013年12月5日 : v1.0.0

  • 主要重构和链与步骤之间的分离

当前状态

此扩展包稳定、经过测试,并且正在travis-ci上运行。

安装

在composer.json中添加KitpagesStepBundle

{
    "require": {
        "kitpages/step-bundle": "*"
    }
}

现在运行步骤以让composer下载该扩展包

$ php composer.phar update kitpages/step-bundle

AppKernel.php

$bundles = array(
    ...
    new Kitpages\StepBundle\KitpagesStepBundle(),
);

创建一个步骤

每个步骤必须实现StepInterface或扩展StepAbstract。使用setContainer方法将DIC注入到步骤中。

<?php
namespace Kitpages\StepBundle\Tests\Sample;

use Kitpages\StepBundle\Step\StepAbstract;

class StepSample extends StepAbstract
{
    public function execute() {
        // do whatever you want
        return $whatever;
    }
}

配置示例

以下配置定义了2个步骤

  • kitpagesMep : 生产启动
  • kitpagesCms : 实例化一个KitpagesCms

让我们看看config.yml中的配置

kitpages_step:
    shared_step_list:
        CodeCopy:
            class: '\Kitpages\StepBundle\Step\CodeCopy'
            parameter_list:
                src_dir: '/home/webadmin/htdocs/dev/www.kitpages.com'
                dest_dir: '/home/webadmin/htdocs/prod/www.kitpages.com'
            help:
                short: copy a directory to another
                complete: |
                    This step copies a directory to another
                    @param string return string returned by the step
                    @service listener service used for xxx
                    @event:returnValue string
                    @return boolean true if ok or false

        CodeCopyPreProd:
            parent_shared_step: CodeCopy
            parameter_list:
                dest_dir: '/home/webadmin/htdocs/pre-prod/www.kitpages.com'
        GitKitpages:
            class: '\Kitpages\StepBundle\Step\GitKitpages'
            parameter_list:
                url: git.kitpages.com
            service_list:
                logger: logger

使用app/console

使用app/console运行一个步骤

# run a step with parameters defined in config.yml
php app/console kitpages:step:run-step CodeCopy

# run a step with custom parameters
php app/console kitpages:step:run-step CodeCopy --p=src_dir:'/home/webadmin/src' --p=dest_dir:'/tmp/destDir'

使用PHP运行一个步骤

$stepKitpages = $this->get("kitpages_step.step");
$codeCopyStepKitpages = $stepKitpages->getStep('CodeCopy');
$codeCopyStepKitpages->setParameter('src_dir', '/home/webadmin/htdocs/dev/cms2.kitpages.com');

$codeCopyStepKitpages->execute();

使用事件

通过事件,您可以更改每个步骤的执行方式。您可以

  • 阻止步骤运行execute()方法。$event->preventDefault()
  • 在执行前后更改步骤
  • 更改返回值
  • ...

创建一个监听器

namespace Foo\Bar;
class StepListener
{
    public function onStepExecute(StepEvent $event)
    {
        $step = $event->getStep();
        // do whatever you want with the current step
        // $event->preventDefault();
        // $event->stopPropagation();
        // log something ?
    }
}

注册监听器

services:
    stepListener:
        class: Foo\Bar\StepListener
        tags:
            - { name: kernel.event_listener, event: kitpages_step.on_step_execute, method: onStepExecute }
use Kitpages\StepBundle\Step\StepEvent;
[...]

$event = new StepEvent();

$stepKitpages = $this->get("kitpages_step.step");
$codeCopyStepKitpages = $stepKitpages->getStep('CodeCopy');
$codeCopyStepKitpages->setParameter('src_dir', '/home/webadmin/htdocs/dev/cms2.kitpages.com');

$codeCopyStepKitpages->execute($event);

分支之前的旧版本

2013年4月23日 : v1.4.0 帮助系统步骤