Exemplo n.º 1
0
    public function render()
    {
        /** @var Command $class */
        $class = $this->commandState->commandClass;
        $action = $this->io->makeAnchor($class::createState());
        echo '<form method="post" action="' . $action . '">';
        foreach ($class::definition()->optionsArray() as $option) {
            $value = '';
            if (isset($this->commandState->{$option->name})) {
                $value = $this->commandState->{$option->name};
                if ($value instanceof Definition) {
                    $value = '';
                }
            }
            $labelCaption = $option->description ? $option->description : $option->name;
            $id = 'formItem' . ++self::$surrogateId;
            $name = $this->io->getRequestMapper()->getExportName($option);
            $this->io;
            echo <<<HTML
 <div class="form-group">
    <label for="{$id}">{$labelCaption}</label>
    <input class="form-control" id="{$id}" name="{$name}" placeholder="{$labelCaption}" value="{$value}">
 </div>
  
HTML;
        }
        $submitName = $class::definition()->getName();
        echo '<button type="submit" class="btn btn-default">' . $submitName . '</button>';
        echo '</form>';
    }
Exemplo n.º 2
0
 public static function run(Command\Definition $definition, Request $request = null)
 {
     if (null === $request) {
         $request = Request::createAuto();
     }
     $requestMapper = new Command\Web\RequestMapper($request);
     $response = new Response();
     $layout = new Layout();
     $layout->pushMain($response);
     try {
         $io = new Command\Io($definition, $requestMapper, $response);
         $io->getCommand()->performAction();
     } catch (\Exception $exception) {
         $response->error($exception->getMessage());
     }
     $layout->render();
 }
Exemplo n.º 3
0
 /**
  * @param Io|null $fillFromIo
  * @return State
  * @return static
  */
 public static function createState(Io $fillFromIo = null)
 {
     $commandClass = get_called_class();
     /** @var State $state */
     $state = null;
     if ($fillFromIo !== null) {
         $state = $fillFromIo->getRequestState($commandClass);
         if (!$state) {
             $state = new State();
         }
         $state->setIo($fillFromIo);
     } else {
         $state = new State();
     }
     $state->commandClass = $commandClass;
     return $state;
 }
Exemplo n.º 4
0
 public function makeAnchor()
 {
     return $this->io->makeAnchor($this);
 }