Example #1
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;
 }
Example #2
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;
 }
Example #3
0
 private function givenANonModifyingAction($actionId)
 {
     $this->action = Mockster::of(Action::class);
     $this->app->actions->add($actionId, Mockster::mock($this->action));
     Mockster::stub($this->action->execute(Arg::any()))->will()->return_('Value of ' . $actionId);
     Mockster::stub($this->action->isModifying())->will()->return_(false);
     Mockster::stub($this->action->caption())->will()->return_('My Foo');
     Mockster::stub($this->action->parameters())->will()->return_([new Parameter('one', new StringType())]);
 }
Example #4
0
 public function fill(array $parameters)
 {
     if ($this->fill) {
         $parameters = call_user_func($this->fill, $parameters);
     } else {
         $parameters = $this->action->fill($parameters);
     }
     return $parameters;
 }
Example #5
0
 protected function handleValueResult(ValueResult $result)
 {
     $value = $result->getValue();
     $renderer = $this->renderers->getRenderer($value);
     if ($renderer instanceof WebRenderer) {
         $this->headElements = $renderer->headElements($value);
     }
     $this->model['output'] = $renderer->render($value);
     if (!$this->action->isModifying()) {
         $this->crumbs->updateCrumbs($this->action, $this->actionId);
     }
 }
Example #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];
 }
Example #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];
 }
Example #8
0
 private function shortDescription(Action $action)
 {
     $description = $this->parser->shorten($action->description());
     return $description ? " ({$description})" : '';
 }
 private function thenTheDescriptionShouldBe($string)
 {
     $this->assert($this->uut->description(), $string);
 }