Exemplo n.º 1
0
 private function makeDefinitionsTree(Definition $definition)
 {
     foreach ($definition->optionsArray() as $option) {
         if ($option->type === Option::TYPE_ENUM) {
             foreach ($option->enumValues as $enumName => $value) {
                 if ($value instanceof Definition) {
                     $this->definitionTree[$value->commandClass] = array($definition->commandClass, $option->name, $enumName);
                     $this->makeDefinitionsTree($value);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 protected function prepareCommand(Command\Definition $definition)
 {
     $commandClass = $definition->commandClass;
     /** @var Command $command */
     $command = new $commandClass();
     $command->setResponse($this->response);
     $command->setRequestMapper($this->requestMapper);
     $command->setIo($this);
     $commandOptions = $definition->optionsArray();
     $commandState = new State();
     $commandState->setIo($this);
     $commandState->commandClass = $commandClass;
     $requestState = new State();
     $requestState->setIo($this);
     $requestState->commandClass = $commandClass;
     $this->requestMapper->readOptions($commandOptions, $commandState, $requestState);
     $this->commandStates[$definition->commandClass] = $commandState;
     $this->requestStates[$definition->commandClass] = $requestState;
     foreach ($commandOptions as $option) {
         $this->globalOptions[$option->name] = $option;
         // todo consider managing overlapping options
         if (!$commandState->hasProperty($option->name)) {
             continue;
         }
         $value = $commandState->{$option->name};
         //var_dump($option->name, $value);
         $this->globalState->{$option->name} = $value;
         $command->{$option->name} = $value;
         if ($option->type === Option::TYPE_ENUM) {
             if ($value instanceof Command\Definition) {
                 $command->{$option->name} = $this->prepareCommand($value);
             }
         }
     }
     return $command;
 }