Пример #1
0
 public function testTransitionCreationSuccess()
 {
     $this->specify('create a transition instance with success', function () {
         $start = new Status(['id' => 'draft', 'workflowId' => 'workflow1']);
         $end = new Status(['id' => 'published', 'workflowId' => 'workflow1']);
         $tr = new Transition(['start' => $start, 'end' => $end]);
         verify("start status id is 'draft'", $tr->getStartStatus()->getId())->equals('draft');
         verify("end status id is 'published'", $tr->getEndStatus()->getId())->equals('published');
     });
 }
Пример #2
0
 /**
  * Produces the following sequence when a model changes from status A to status B:
  *
  * - beforeLeaveStatus(A)
  * - beforeChangeStatus(A,B)
  * - beforeEnterStatus(B)
  *
  * - afterLeaveStatus(A)
  * - afterChangeStatus(A,B)
  * - afterEnterStatus(B)
  * @param Transition $transition
  * @param Object $sender
  * @return array|\yii\base\Event[]
  * @see \fproject\workflow\events\IEventSequenceScheme::createChangeStatusSequence()
  */
 public function createChangeStatusSequence($transition, $sender)
 {
     return ['before' => [new WorkflowEvent(WorkflowEvent::beforeLeaveStatus($transition->getStartStatus()->getId()), ['start' => $transition->getStartStatus(), 'sender' => $sender]), new WorkflowEvent(WorkflowEvent::beforeChangeStatus($transition->getStartStatus()->getId(), $transition->getEndStatus()->getId()), ['start' => $transition->getStartStatus(), 'end' => $transition->getEndStatus(), 'transition' => $transition, 'sender' => $sender]), new WorkflowEvent(WorkflowEvent::beforeEnterStatus($transition->getEndStatus()->getId()), ['end' => $transition->getEndStatus(), 'sender' => $sender])], 'after' => [new WorkflowEvent(WorkflowEvent::afterLeaveStatus($transition->getStartStatus()->getId()), ['start' => $transition->getStartStatus(), 'sender' => $sender]), new WorkflowEvent(WorkflowEvent::afterChangeStatus($transition->getStartStatus()->getId(), $transition->getEndStatus()->getId()), ['start' => $transition->getStartStatus(), 'end' => $transition->getEndStatus(), 'transition' => $transition, 'sender' => $sender]), new WorkflowEvent(WorkflowEvent::afterEnterStatus($transition->getEndStatus()->getId()), ['end' => $transition->getEndStatus(), 'sender' => $sender])]];
 }
Пример #3
0
 /**
  * Add an out-going transition to this status.
  *
  * @param Transition $transition
  * @throws WorkflowException
  */
 public function addTransition($transition)
 {
     if (empty($transition) || !$transition instanceof Transition) {
         throw new WorkflowException('"transition" must be an instance of Transition');
     }
     $this->_transitions[$transition->getEndStatus()->getId()] = $transition;
 }