-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Console] Always use lazy commands? #8843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Symfony 4.0 I've just encountered this exact same error message without using Maker but instead following the docs everything works up until you require services, unsure if this is a similar issue and the error message is not clear. For example: This works fine <?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TestCommand extends Command
{
protected function configure()
{
$this
->setName('app:test')
->setDescription('Test command');
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
}
} This errors with message: There are no commands defined in the "app" namespace. <?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Service\Test;
class TestCommand extends Command
{
private $test;
public function __construct(Test $test)
{
$this->test = $test;
}
protected function configure()
{
$this
->setName('app:test')
->setDescription('Test command');
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
}
} This should work according to: https://symfony.com/doc/current/console.html#getting-services-from-the-service-container "Getting Services from the Service Container" PHPStorm notices error: Missing parent constructor call, there is a You can change your constructor to:
Which works... Don't really like the parent call. The main frustrations I ran into it:
Using MakerIf you use Maker it should probably be stated somewhere not to add
Once you add |
…ice Container" section (viion) This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #8849). Discussion ---------- Add constructor call to the "Getting Services from the Service Container" section Parent constructor call is required when using auto-wired services in a command constructor, without it you will receive the error: ``` There are no commands defined in the "app" namespace. ``` Some discussion of what I ran into: #8843 Commits ------- 88fd7a7 Update console.rst
Yes please, lazy commands all the time! |
This issue was reported in the Symfony Slack.
make:command
->setName('...')
in the generated command, so he added->setName('app:mycommand')
himself.The problem is:
What should we do here? Should we change all console docs to always use lazy commands?
The text was updated successfully, but these errors were encountered: