survos/workflow-helper-bundle

为使用 Symfony 工作流组件添加一些工具

资助包维护!
kbond

安装数: 2,413

依赖者: 1

建议者: 0

安全: 0

星标: 1

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

1.5.340 2024-09-24 13:44 UTC

This package is auto-updated.

Last update: 2024-09-24 13:45:15 UTC


README

使用 PHP 属性配置工作流。使用单个类来配置并处理工作流事件。(或者创建一个带有配置的接口,以便于分离)。

<?php
// SubmissionWorkflowInterface.php

namespace App\Workflow;

use Survos\WorkflowBundle\Attribute\Place;
use Survos\WorkflowBundle\Attribute\Transition;

interface SubmissionWorkflowInterface
{
    const WORKFLOW_NAME='SubmissionWorkflow';

    #[Place(initial: true, metadata: ['description' => "starting place after submission"])]
    const PLACE_NEW='new';
    #[Place(metadata: ['description' => "waiting for admin approval"])]
    const PLACE_WAITING='waiting';
    const PLACE_APPROVED='approved';
    const PLACE_REJECTED='rejected';
    const PLACE_WITHDRAWN='withdrawn';

    #[Transition(from:[self::PLACE_NEW], to: self::PLACE_WAITING)]
    const TRANSITION_SUBMIT='submit';
    #[Transition(from:[self::PLACE_NEW], to: self::PLACE_APPROVED, guard: "is_granted('ROLE_ADMIN')")]
    const TRANSITION_APPROVE='approve';
    #[Transition(from:[self::PLACE_NEW], to: self::PLACE_REJECTED, guard: "is_granted('ROLE_ADMIN')")]
    const TRANSITION_REJECT='reject';

    #[Transition(from:[self::PLACE_NEW, self::PLACE_APPROVED], to: self::PLACE_WITHDRAWN, guard: "is_granted('ROLE_USER')")]
    const TRANSITION_WITHDRAW='withdrawn';

    #[Transition(from:[self::PLACE_REJECTED, self::PLACE_APPROVED], to: self::PLACE_NEW)]
    const TRANSITION_RESET='reset';

}

现在创建一个实现该接口的类(以获取常量)并处理事件。

symfony new workflow-demo  --webapp --version=next --php=8.2 && cd workflow-demo 
composer config extra.symfony.allow-contrib true
composer req symfony/asset-mapper:^6.4
bin/console importmap:require d3

composer config minimum-stability beta
composer config extra.symfony.allow-contrib true
composer req symfony/stimulus-bundle:2.x-dev
bin/console make:controller d3 -i
symfony server:start -d
symfony open:local --path=/d3



../survos/bin/lb.sh workflow-helper
# composer req survos/workflow-helper-bundle
bin/console make:controller d3 -i
cat > templates/d3  .html.twig <<END
{% extends 'base.html.twig' %}

{% block body %}
workflow here.

{% endblock %}
END
symfony server:start -d
symfony open:local --path=/d3

备注

由于工作流可能使用消息总线,以下是如何使用 Symfony CLI 配置它的提示:https://symfony.ac.cn/doc/current/setup/symfony_server.html#symfony-server_configuring-workers

https://github.com/survos/SurvosWorkflowHelperBundle/network/dependents https://github.com/codereviewvideos/symfony-workflow-example