Neos\Flow\Cli\Command::getArgumentDefinitions PHP Метод

getArgumentDefinitions() публичный Метод

If the command does not expect any arguments, an empty array is returned
public getArgumentDefinitions ( ) : array
Результат array
    public function getArgumentDefinitions()
    {
        if (!$this->hasArguments()) {
            return [];
        }
        $commandArgumentDefinitions = [];
        $commandMethodReflection = $this->getCommandMethodReflection();
        $annotations = $commandMethodReflection->getTagsValues();
        $commandParameters = $this->reflectionService->getMethodParameters($this->controllerClassName, $this->controllerCommandName . 'Command');
        $i = 0;
        foreach ($commandParameters as $commandParameterName => $commandParameterDefinition) {
            $explodedAnnotation = explode(' ', $annotations['param'][$i]);
            array_shift($explodedAnnotation);
            array_shift($explodedAnnotation);
            $description = implode(' ', $explodedAnnotation);
            $required = $commandParameterDefinition['optional'] !== true;
            $commandArgumentDefinitions[] = new CommandArgumentDefinition($commandParameterName, $required, $description);
            $i++;
        }
        return $commandArgumentDefinitions;
    }

Usage Example

 /**
  * @test
  */
 public function getArgumentDefinitionsReturnsArrayOfArgumentDefinitionIfCommandExpectsArguments()
 {
     $parameterReflection = $this->createMock(ParameterReflection::class, [], [[__CLASS__, 'dummyMethod'], 'arg']);
     $mockReflectionService = $this->createMock(ReflectionService::class);
     $mockMethodParameters = ['argument1' => ['optional' => false], 'argument2' => ['optional' => true]];
     $mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue($mockMethodParameters));
     $this->command->injectReflectionService($mockReflectionService);
     $this->methodReflection->expects($this->atLeastOnce())->method('getParameters')->will($this->returnValue([$parameterReflection]));
     $this->methodReflection->expects($this->atLeastOnce())->method('getTagsValues')->will($this->returnValue(['param' => ['@param $argument1 argument1 description', '@param $argument2 argument2 description']]));
     $expectedResult = [new Cli\CommandArgumentDefinition('argument1', true, 'argument1 description'), new Cli\CommandArgumentDefinition('argument2', false, 'argument2 description')];
     $actualResult = $this->command->getArgumentDefinitions();
     $this->assertEquals($expectedResult, $actualResult);
 }
All Usage Examples Of Neos\Flow\Cli\Command::getArgumentDefinitions