gpt4 book ai didi

php - Symfony workflow::can 通过 workflow guard 事件监听器

转载 作者:可可西里 更新时间:2023-11-01 13:31:36 27 4
gpt4 key购买 nike

如果你们中的很多人已经测试过 symfony workflow 组件,我现在不知道,但我希望你们中的一些人已经测试过 :)

所以,我在两个对象上使用这个组件,我希望第一个对象更新第二个 strong> 取决于它应用的 transition

为此,我在我的第一个对象上使用了workflow guard listener,并尝试在我的对象上执行一个workflow::apply 第二个对象(使用第二个工作流程...)

问题是,当我创建一个workflow::can 时,事件被调度 并尝试应用 一个新的状态在我的第二个对象上...这很不正常,因为我只是在问我是否可以应用一些过渡并且要求实际应用我的第一个对象

配置

framework:
workflows:
request_for_operation:
type: 'state_machine'
marking_store:
type: 'single_state'
arguments:
- 'status'
supports:
- AppBundle\Entity\RequestForOperation
places:
- draft
- pending_for_management
- in_progress
- finished
- canceled
transitions:
request_for_operations:
from: draft
to: pending_for_management
start_rfop_management:
from: pending_for_management
to: in_progress
close:
from: in_progress
to: finished
cancel:
from: [pending_for_management, in_progress]
to: canceled
operation:
type: 'state_machine'
marking_store:
type: 'single_state'
arguments:
- 'status'
supports:
- AppBundle\Entity\Operation
places:
- draft
- pending_for_management
- in_progress
- finished
- canceled
transitions:
validate_operation:
from: draft
to: pending_for_management
start_tracking:
from: pending_for_management
to: in_progress
close:
from: in_progress
to: finished
cancel:
from: [pending_for_management, in_progress]
to: canceled

订阅者

class RequestForOperationListener implements EventSubscriberInterface
{
public function __construct(
OperationManager $operationManager,
UserNotifier $userNotifier
) {
$this->operationManager = $operationManager;
$this->userNotifier = $userNotifier;
}

public static function getSubscribedEvents()
{
return [
'workflow.request_for_operation.guard.request_for_operations' => ['onRequestForOperations'],
'workflow.request_for_operation.guard.start_rfop_management' => ['onStartRfopManagement'],
'workflow.request_for_operation.guard.close' => ['onClose'],
'workflow.request_for_operation.guard.cancel' => ['onCancel'],
];
}

public function onRequestForOperations(GuardEvent $event)
{
/** @var RequestForOperation $rfop */
$rfop = $event->getSubject();

//get all the operations linked to the rfop
$operations = $rfop->getOperations();
foreach ($operations as $operation) {
//set the status of the operation to 'pending_for_management'
$this->operationManager->applyTransition($operation, 'validate_operation');
//set the status of the sub-operations to 'pending_for_management'
foreach ($operation->getChildren() as $subOperation) {
$this->operationManager->applyTransition($subOperation, 'validate_operation');
}

//get the users (i.e: managers) linked to the operation and notify them (by mail or whatever)
$this->notifyAssignedUsers($operation->getUsers(), $operation);
}
}
}

最佳答案

我想我遇到了和你一样的问题,我已经记录了 Symfony 项目的错误:https://github.com/symfony/symfony/issues/33105

关于php - Symfony workflow::can 通过 workflow guard 事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41466939/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com