Beispiel #1
0
 /**
  * @param Parameter $parameter
  * @param mixed $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $innerParameter = $this->getInnerParameter($parameter);
     if (!$this->reader->has($innerParameter) || !$serialized || strtolower($serialized) == 'n') {
         return null;
     }
     $field = $this->getField($innerParameter);
     return $field->inflate($innerParameter, $this->reader->read($innerParameter));
 }
Beispiel #2
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return array
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $items = [];
     for ($i = 0; $i < $serialized; $i++) {
         $itemParameter = $this->makeInnerParameter($parameter, "-{$i}");
         $field = $this->getField($itemParameter);
         $items[] = $field->inflate($itemParameter, $this->reader->read($itemParameter));
     }
     return $items;
 }
Beispiel #3
0
 private function readRawParameters(Action $action)
 {
     $values = [];
     foreach ($action->parameters() as $parameter) {
         if ($this->reader->has($parameter)) {
             $values[$parameter->getName()] = $this->reader->read($parameter);
         }
     }
     return $values;
 }
Beispiel #4
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return Html
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $lines = [];
     $line = $serialized;
     while ($line) {
         $lines[] = $line;
         $lineParameter = $this->lineParameter($parameter, count($lines));
         $line = $this->reader->has($lineParameter) ? $this->reader->read($lineParameter) : null;
     }
     return new Html(implode(PHP_EOL, $lines));
 }
Beispiel #5
0
 /**
  * @param Parameter $parameter
  * @param null $serialized
  * @return object
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $properties = [];
     foreach ($this->getProperties($parameter) as $property) {
         $propertyParameter = new Parameter($parameter->getName() . '-' . $property->name(), $property->type());
         $field = $this->getField($propertyParameter);
         $properties[$property->name()] = $field->inflate($propertyParameter, $this->reader->read($propertyParameter));
     }
     $injector = new Injector(new Factory());
     $instance = $injector->injectConstructor($this->getClass($parameter), $properties, function () {
         return false;
     });
     foreach ($this->getProperties($parameter) as $property) {
         $value = $properties[$property->name()];
         if (!is_null($value) && $property->canSet()) {
             $property->set($instance, $value);
         }
     }
     return $instance;
 }
Beispiel #6
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];
 }
Beispiel #7
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];
 }
Beispiel #8
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;
 }
 private function given_HasTheValue($parameterName, $value)
 {
     $parameter = $this->parameter($parameterName);
     Mockster::stub($this->reader->has($parameter))->will()->return_(true);
     Mockster::stub($this->reader->read($parameter))->will()->return_($value);
 }
Beispiel #10
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $type = $this->getTypes($parameter)[(int) $serialized];
     $optionParameter = new Parameter($parameter->getName() . '-value', $type);
     return $this->getField($optionParameter)->inflate($optionParameter, $this->reader->read($optionParameter));
 }
Beispiel #11
0
 protected function before()
 {
     $this->reader = Mockster::of(ParameterReader::class);
     Mockster::stub($this->reader->read(Argument::any()))->will()->forwardTo(function (Parameter $parameter) {
         return $this->parameters[$parameter->getName()];
     });
     Mockster::stub($this->reader->has(Argument::any()))->will()->forwardTo(function (Parameter $parameter) {
         return array_key_exists($parameter->getName(), $this->parameters);
     });
 }