У меня есть простое консольное приложение 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.
Вероятно, вы должны переопределить метод выполнения, который не выполняется.
public function execute(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}
run инициализирует $ input и output, затем проверяет ввод и вызов execute ($ input, $ output) позже.