Esempio n. 1
0
 /**
  * Check if the current user can reach the given Step
  * @param ModelInterface $model
  * @param Step $step
  * @return boolean
  */
 protected function canReachStep(ModelInterface $model, Step $step)
 {
     $roles = $step->getRoles();
     return !(!empty($roles) && !$this->authorizationChecker->isGranted($roles, $model->getWorkflowObject()));
 }
 protected function getProcessHandler($authenticatedUser = true)
 {
     $stepValidateDoc = new Step('step_validate_doc', 'Validate doc', array(), array('setStatus', 'Vas24x7\\WorkflowBundle\\Tests\\Fixtures\\FakeModel::STATUS_VALIDATE'));
     $stepRemoveDoc = new Step('step_remove_doc', 'Remove doc', array(), array('setStatus', 'Vas24x7\\WorkflowBundle\\Tests\\Fixtures\\FakeModel::STATUS_REMOVE'));
     $stepRemoveOnInvalidDoc = new Step('step_remove_on_invalid_doc', 'Remove doc', array(), array('setStatus', 'Vas24x7\\WorkflowBundle\\Tests\\Fixtures\\FakeModel::STATUS_REMOVE'), array(), 'step_fake');
     $stepFake = new Step('step_fake', 'Fake', array());
     $stepCreateDoc = new Step('step_create_doc', 'Create doc', array(), array('setStatus', 'Vas24x7\\WorkflowBundle\\Tests\\Fixtures\\FakeModel::STATUS_CREATE'), array('ROLE_ADMIN'));
     $stepCreateDoc->addNextState('validate', NextStateInterface::TYPE_STEP, $stepValidateDoc);
     $stepCreateDoc->addNextState('validate_with_pre_validation', NextStateInterface::TYPE_STEP, $stepValidateDoc);
     $stepCreateDoc->addNextState('validate_with_pre_validation_invalid', NextStateInterface::TYPE_STEP, $stepValidateDoc);
     $stepCreateDoc->addNextState('remove', NextStateInterface::TYPE_STEP, $stepRemoveDoc);
     $stepCreateDoc->addNextState('remove_on_invalid', NextStateInterface::TYPE_STEP, $stepRemoveOnInvalidDoc);
     $stepCreateDoc->addNextStateOr('validate_or_remove', NextStateInterface::TYPE_STEP_OR, array(array('target' => $stepValidateDoc, 'condition_object' => new FakeModelChecker(), 'condition_method' => 'isClean'), array('target' => $stepRemoveDoc, 'condition_object' => null, 'condition_method' => null)));
     $process = new Process('document_proccess', array('step_create_doc' => $stepCreateDoc, 'step_validate_doc' => $stepValidateDoc, 'step_remove_doc' => $stepRemoveDoc, 'step_remove_on_invalid_doc' => $stepRemoveOnInvalidDoc, 'step_fake' => $stepFake), 'step_create_doc', array('step_validate_doc'));
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener('document_proccess.step_fake.reached', array(new FakeProcessListener(), 'handleSucccess'));
     $dispatcher->addListener('document_proccess.step_remove_doc.validate', array(new FakeValidatorListener(), 'invalid'));
     $dispatcher->addListener('document_proccess.step_remove_on_invalid_doc.validate', array(new FakeValidatorListener(), 'invalid'));
     $dispatcher->addListener('document_proccess.step_validate_doc.validate', array(new FakeValidatorListener(), 'valid'));
     $dispatcher->addListener('document_proccess.step_create_doc.validate_with_pre_validation.pre_validation', array(new FakeValidatorListener(), 'valid'));
     $dispatcher->addListener('document_proccess.step_create_doc.validate_with_pre_validation_invalid.pre_validation', array(new FakeValidatorListener(), 'invalid'));
     $dispatcher->addListener('document_proccess.step_create_doc.validate_with_pre_validation_invalid.pre_validation_fail', array(new FakeProcessListener(), 'handleSucccess'));
     $processHandler = new ProcessHandler($process, $this->modelStorage, $dispatcher);
     $this->authorizationChecker = new FakeAuthorizationChecker($authenticatedUser);
     $processHandler->setAuthorizationChecker($this->authorizationChecker);
     return $processHandler;
 }