Exemplo n.º 1
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  * @throws \Exception
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName(), $this->getType($parameter)->getOptionType());
     $options = $this->getType($parameter)->getOptions();
     if (!array_key_exists($serialized, $options)) {
         throw new \Exception("[{$serialized}] is not an option in [" . implode(',', array_keys($options)) . ']');
     }
     return $this->fields->getField($param)->inflate($param, $options[$serialized]);
 }
Exemplo n.º 2
0
 /**
  * @param Parameter[] $parameters
  * @param mixed[] $values
  * @return mixed[]
  */
 private function inflate($parameters, $values)
 {
     $inflated = [];
     foreach ($parameters as $parameter) {
         $name = $parameter->getName();
         if (isset($values[$name])) {
             $inflated[$name] = $this->fields->getField($parameter)->inflate($parameter, $values[$name]);
         }
     }
     return $inflated;
 }
Exemplo n.º 3
0
 /**
  * @param Parameter $parameter
  * @return array|\rtens\domin\delivery\web\Element[]
  */
 public function headElements(Parameter $parameter)
 {
     $action = $this->actions->getAction($parameter->getName());
     $headElements = [self::descriptionCode()];
     foreach ($action->parameters() as $parameter) {
         $field = $this->fields->getField($parameter);
         if ($field instanceof WebField) {
             $headElements = array_merge($headElements, $field->headElements($parameter));
         }
     }
     return $headElements;
 }
Exemplo n.º 4
0
 private function readParameters(Action $action)
 {
     $failed = [];
     $params = [];
     foreach ($action->parameters() as $parameter) {
         try {
             if ($this->paramReader->has($parameter)) {
                 $inflated = $this->fields->getField($parameter)->inflate($parameter, $this->paramReader->read($parameter));
                 if ($parameter->getType()->is($inflated)) {
                     $params[$parameter->getName()] = $inflated;
                     continue;
                 }
             }
             if ($parameter->isRequired()) {
                 throw new \Exception("[{$parameter->getName()}] is required.");
             }
         } catch (\Exception $e) {
             $failed[$parameter->getName()] = $e;
         }
     }
     return [$params, $failed];
 }
Exemplo n.º 5
0
 private function readParameters(Action $action)
 {
     $params = [];
     $missing = [];
     foreach ($action->parameters() as $parameter) {
         if ($this->paramReader->has($parameter)) {
             $inflated = $this->fields->getField($parameter)->inflate($parameter, $this->paramReader->read($parameter));
             if ($parameter->getType()->is($inflated)) {
                 $params[$parameter->getName()] = $inflated;
             } else {
                 if ($parameter->isRequired()) {
                     $missing[] = $parameter->getName();
                 }
             }
         } else {
             if ($parameter->isRequired()) {
                 $missing[] = $parameter->getName();
             }
         }
     }
     return [$params, $missing];
 }
Exemplo n.º 6
0
 private function readParameters(ParameterReader $reader, FieldRegistry $fields, Action $action)
 {
     $values = ['inflated' => [], 'errors' => []];
     foreach ($action->parameters() as $parameter) {
         if ($reader->has($parameter)) {
             $field = $fields->getField($parameter);
             try {
                 $values['inflated'][$parameter->getName()] = $field->inflate($parameter, $reader->read($parameter));
             } catch (\Exception $e) {
                 $values['errors'][$parameter->getName()] = $e;
             }
         }
     }
     return $values;
 }
Exemplo n.º 7
0
 /**
  * @param $itemParameter
  * @return CliField
  * @throws \Exception
  */
 private function getField($itemParameter)
 {
     return $this->fields->getField($itemParameter);
 }
Exemplo n.º 8
0
 /**
  * @param Parameter $param
  * @return CliField
  */
 private function getField(Parameter $param)
 {
     return $this->fields->getField($param);
 }
Exemplo n.º 9
0
 private function itemHeadElements(Parameter $itemParameter)
 {
     /** @var WebField $field */
     $field = $this->fields->getField($itemParameter);
     return $field->headElements($itemParameter);
 }
Exemplo n.º 10
0
 /**
  * @param Parameter $innerParameter
  * @return WebField
  */
 private function getInnerField(Parameter $innerParameter)
 {
     return $this->fields->getField($innerParameter);
 }
Exemplo n.º 11
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $primitiveParameter = new Parameter($parameter->getName(), $this->getType($parameter)->getPrimitive());
     return $this->fields->getField($primitiveParameter)->inflate($primitiveParameter, $serialized);
 }
Exemplo n.º 12
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName(), $this->getType($parameter)->getOptionType());
     return $this->fields->getField($param)->inflate($param, $this->getType($parameter)->getOptions()[(int) $serialized]);
 }
Exemplo n.º 13
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName() . '-value', $this->getOptionType($parameter));
     return $this->fields->getField($param)->inflate($param, $serialized);
 }