Аргумент «X» не существует

0

У меня есть простое консольное приложение Symfony со следующей точкой входа

#!/usr/bin/env php
<?php

include __DIR__ . '/vendor/autoload.php';

use Rkmax\Application;

$app = new Application();
$app->run();

мой класс приложения

class Application extends BaseApplication
{
    public function __construct($name = 'myapp', $version = '0.1')
    {
        parent::__construct($name, $version);

        $this->add(new Command\SingleCommand());
    }
}

и моя команда

class SingleCommand extends Command
{
    const KEYWORDS = 'keywords';

    protected function configure()
    {
        $this
            ->setName("single")
            ->setDescription("Sample")
            ->addArgument(self::KEYWORDS, InputArgument::OPTIONAL, "Keywords for the search")
        ;
    }

    public function run(InputInterface $input, OutputInterface $output)
    {
        $keywords = $input->getArgument(self::KEYWORDS);
        // ...
    }
}

я не могу понять, где проблема, я всегда получаю ошибку

 [InvalidArgumentException]               
 The "keywords" argument does not exist.
  • 0
    как выглядит getArgument?
  • 0
    Я не понимаю твой вопрос
Показать ещё 4 комментария
Теги:
console-application

1 ответ

1
Лучший ответ

Вероятно, вы должны переопределить метод выполнения, который не выполняется.

public function execute(InputInterface $input, OutputInterface $output)
{
    $keywords = $input->getArgument(self::KEYWORDS);
    // ...
}

run инициализирует $ input и output, затем проверяет ввод и вызов execute ($ input, $ output) позже.

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Command/Command.php#L215-L257

  • 0
    да, Томас, я пришел проверить это

Ещё вопросы

Сообщество Overcoder
Наверх
Меню