Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

symfony5 - Symfony 5 not finding commands in a given namespace

I'm trying to figure out why I am getting this error for the first command I've written specifically for Symfony5:

  There are no commands defined in the "hitachi" namespace. 

Auto-wiring is on:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

I meticulously followed the docs. The $defaultName is defined. The proper Command class is extended and the constructor overridden for service injection.

namespace IAMDataProcessingBundleCommand;

use IAMDataProcessingBundleServiceHitachiMobileUpdaterService;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;

class HitachiMobileUpdaterCommand extends Command
{
    protected static $defaultName = 'hitachi:mobileupdate';

    protected $hitachiMobileUpdaterService;

    public function __construct(HitachiMobileUpdaterService $hitachiMobileUpdaterService)
    {
        $this->hitachiMobileUpdaterService = $hitachiMobileUpdaterService;

        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setDescription('Update the HitachiId User record mobile field with the first active mobile phone found in Duo.')
        ;
    }

I have tried to go around the auto-wiring and configured the command with <bundle-top>/Resources/config/services.yaml, but it did not help and the error remained the same.

hitachi_mobule_updater_command:
        public: true
        class: IAMDataProcessingBundleCommandHitachiMobileUpdaterCommand
        arguments:
            - "@hitachi_mobile_updater_service"
        tags:
            - {name: 'console.command', command: 'hitachi:mobileupdate'}
question from:https://stackoverflow.com/questions/65912114/symfony-5-not-finding-commands-in-a-given-namespace

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This turned out to be a false alarm brought on by PHPStorm 2019.1.4 (fallback license). False alarm, that is, as far as the root cause being something I did wrong or that Symfony was doing wrong.

I encountered a bug in the IDE where it was not updating a cache of information in .idea/workspace.xml. I develop code from tests and almost always do so with xdebug and PHPstorm. I started running into other issues, similar to the one described in this post, where new configuration or classpaths would not be recognized nor old ones forgotten. I was clearing caches in Symfony, composer, re-running the autoloader, manually rm'ing caches. Nothing was working. With nothing left to consider, I let my mind wander and wondered if xdebug was the problem. So, I turned off xdebug in my PHP config and magically everything worked. So I turned xdebug back on but stopped the IDE from listening for it. Everything still worked. I turned the IDE's listener for xdebug back on and it stopped working again. I removed the .idea directory from the top Symfony directory and created a new PHPStorm project. It was all working once again with xdebug and PHPstorm in the mix.

I have no idea why this happened. I've submitted a bug to JetBrains, which admittedly might not be useful since I'm not really sure what's going on. If I ever hear back, I'll update here. I'm not expecting much as my license/version is fairly out of date.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...