Exemplo n.º 1
0
 /**
  * @param array $configuration
  * @return null|ConditionInterface
  */
 public function assemble(array $configuration)
 {
     if (!$this->isService($configuration)) {
         return null;
     }
     $options = array();
     $conditionType = $this->getEntityType($configuration);
     $conditionParameters = $this->getEntityParameters($configuration);
     $conditionParameters = $this->parseParameters($conditionParameters);
     if (is_array($conditionParameters[self::PARAMETERS_KEY])) {
         foreach ($conditionParameters[self::PARAMETERS_KEY] as $key => $conditionParameter) {
             if ($this->isService($conditionParameter)) {
                 $options[$key] = $this->assemble($conditionParameter);
             } else {
                 $options[$key] = $conditionParameter;
             }
         }
     } elseif ($conditionParameters[self::PARAMETERS_KEY] !== null) {
         $options[] = $conditionParameters[self::PARAMETERS_KEY];
     }
     $message = null;
     if (isset($conditionParameters[self::MESSAGE_KEY])) {
         $message = $conditionParameters[self::MESSAGE_KEY];
     } elseif (isset($options[self::MESSAGE_KEY])) {
         $message = $options[self::MESSAGE_KEY];
         unset($options[self::MESSAGE_KEY]);
     }
     $passedOptions = $this->passConfiguration($options);
     $serviceName = $this->getServiceName($conditionType);
     return $this->factory->create($serviceName, $passedOptions, $message);
 }
Exemplo n.º 2
0
 /**
  * @param array $conditionConfiguration
  * @return null|ConfigurableCondition
  */
 protected function createConfigurableCondition(array $conditionConfiguration)
 {
     $condition = null;
     $conditionConfiguration = $this->getOption($conditionConfiguration, self::CONDITIONS_KEY, null);
     if ($conditionConfiguration) {
         $condition = $this->conditionFactory->create(ConfigurableCondition::ALIAS, $conditionConfiguration);
     }
     return $condition;
 }
Exemplo n.º 3
0
 public function testCreate()
 {
     $options = array('key' => 'value');
     $message = 'Test';
     $conditionMock = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionInterface')->getMock();
     $conditionMock->expects($this->once())->method('setMessage')->with($message);
     $conditionMock->expects($this->once())->method('initialize')->with($options);
     $this->container->expects($this->once())->method('get')->with(self::TEST_TYPE_SERVICE)->will($this->returnValue($conditionMock));
     $this->model->create(self::TEST_TYPE, $options, $message);
 }
 /**
  * @param string $name
  * @param array $options
  * @param array $definition
  * @param Step[]|ArrayCollection $steps
  * @param Attribute[]|Collection $attributes
  * @return Transition
  * @throws AssemblerException
  */
 protected function assembleTransition($name, array $options, array $definition, $steps, $attributes)
 {
     $this->assertOptions($options, array('step_to', 'label'));
     $stepToName = $options['step_to'];
     if (empty($steps[$stepToName])) {
         throw new AssemblerException(sprintf('Step "%s" not found', $stepToName));
     }
     $transition = new Transition();
     $transition->setName($name)->setLabel($options['label'])->setStepTo($steps[$stepToName])->setMessage($this->getOption($options, 'message', null))->setStart($this->getOption($options, 'is_start', false))->setHidden($this->getOption($options, 'is_hidden', false))->setUnavailableHidden($this->getOption($options, 'is_unavailable_hidden', false))->setFormType($this->getOption($options, 'form_type', WorkflowTransitionType::NAME))->setFormOptions($this->assembleFormOptions($options, $attributes, $name))->setFrontendOptions($this->getOption($options, 'frontend_options', array()));
     if (!empty($definition['pre_conditions'])) {
         $condition = $this->conditionFactory->create(ConfigurableCondition::ALIAS, $definition['pre_conditions']);
         $transition->setPreCondition($condition);
     }
     if (!empty($definition['conditions'])) {
         $condition = $this->conditionFactory->create(ConfigurableCondition::ALIAS, $definition['conditions']);
         $transition->setCondition($condition);
     }
     if (!empty($definition['post_actions'])) {
         $postAction = $this->actionFactory->create(ConfigurableAction::ALIAS, $definition['post_actions']);
         $transition->setPostAction($postAction);
     }
     return $transition;
 }