2016-08-02 17 views
1

私はsymfony3に関する大きなプロジェクトを持っていました。このプロジェクトで私はProjectFrameworkBundleを持っています。"xxx"名前空間に定義されたコマンドがありません

プロジェクト/ FrameworkBundle /コンソール/ Command.php

abstract class Command extends ContainerAwareCommand 
{ 
    //... 

    protected function execute(InputInterface $input, OutputInterface $output) 
    { 
     // do some regular staff 
     $exitCode = $this->executeCommand($input, $output); 
     // do some regular staff 
    } 

    abstract protected function executeCommand(InputInterface $input, OutputInterface $output); 

    //... 
} 

私は任意のコマンドを作ってあげる場合は、Commandクラスから拡張し、それは(テスト)正常に動作します。

しかし、私は別のバンドル

プロジェクト/ FrameworkQueue /コンソール/ Command.php

use Project\FrameworkBundle\Console\Command as BaseCommand; 
abstract class Command extends BaseCommand 
{ 
    // ... 
    protected function executeCommand(InputInterface $input, OutputInterface $output) 
    { 
     // do some regular staff 
     $exitCode = $this->executeJob($input, $output); 
     // do some regular staff 
    } 

    abstract protected function executeJob(InputInterface $input, OutputInterface $output); 

    // ... 
} 

、私はextends Project\FrameworkBundle\Console\Commandからextends Project\QueueBundle\Console\Commandに花子のコマンドを変更すると、それは、コマンドの一覧から隠しています。 executeCommandからQueueBundleに全員を削除しようとしましたが、それは私を助けませんでした。しかし、私はこのコマンドでPHPコードで何か間違いを犯すと、私は例外を参照してください。

何が間違っていますか?私の間違いはどこか、これはバグです。どこで使用可能なコマンドを収集しチェックするsymfonyコードが見つかりましたか?

ありがとうございます!

P.S.問題はファイル名やクラス名に問題がありません。何度もチェックしました。もちろん、私は親クラスを変更するとき、私は関数名を変更します。

答えて

1

__constructメソッドをQueueBundle\Console\Command 。これをやろうとすると:

public function __construct($name) 
{ 
    parent::__construct($name); 
} 

...それは動作しません。なぜか分からないけど、ここからロジックを「実行前」に移動しました。

ありがとうございます!

1

コマンドがContainerAwareCommandを拡張すると、Symfonyはコンテナを挿入します。しかし、そうでなければ、サービスとしてあなたのコマンドを登録する必要があります。

#アプリ/設定/ config.yml サービス:

app.command.your_command: 
     class: Project\FrameworkBundle\Command\Console\YourCommand 
     tags: 
      - { name: console.command } 

カーネルsymfonyはタグconsole.commandしてコマンドを見つけると詳細情報を確認するには、アプリケーションのコマンドリストに

を注入コンパイル時にこのトピックについて公式の文書を確認することができます - https://symfony.com/doc/current/console/commands_as_services.html

+0

質問にお答えしてくれてありがとうございましたが、理由を見つけました。私は以下で書きます。 –

+1

Ahh、ok。ようこそ! – Rinat

関連する問題