i am trying to Create a basic Command in Symfony.
So i am following this the cookbook in Symfony.
But where it says Test the new console command by running the following
$ php application.php demo:greet Fabien
there i am always getting an error, says ---
Could not open input file: application.php
i have create **GreetCommand.php** file and copy that exact php commands. and also create a application.php file where i follow the instruction.
i have put those two files in the same directory/folder.
What i am doing wrong and why i am getting that error.
Here is code for **GreetCommand.php** ---
<?php
namespace AppBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class GreetCommand extends Command
{
protected function configure()
{
$this
->setName('demo:greet')
->setDescription('Greet someone')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to greet?'
)
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
if ($name) {
$text = 'Hello '.$name;
} else {
$text = 'Hello';
}
if ($input->getOption('yell')) {
$text = strtoupper($text);
}
$output->writeln($text);
}
}
here is the code for application.php ---
#!/usr/bin/env php
<?php
// application.php
require __DIR__.'/vendor/autoload.php';
use AppBundle\Command\GreetCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new GreetCommand());
$application->run();