dtrgqjcd877528 2018-04-24 11:29
浏览 84

Symfony 4中的自动装配服务(参数太少)

I do have simple command with constructor requiring LoggerInterface as dependency.

<?php

namespace App\Command;

// use (...)

class ProcessReportCommand extends Command
{
    /** @var LoggerInterface */
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        parent::__construct();
        $this->logger = $logger;
    }
    // (...)
}

My configuration in services.yml looks pretty default:

parameters:

services:
    _defaults:
        autowire: true      
        autoconfigure: true 
        public: false      

    App\:
        resource: '../src/*'
        exclude: '../src/{Entity,Migrations,Exception,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

Unfortunately I am getting PHP Error saying that dependency was not injected.

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Too few arguments to function App\Command\ProcessReportCommand::__construct(), 0 passed in /home/tomasz/project/bin/console on line 40 and exactly 1 expected in /home/tomasz/project/src/Command/ProcessReportCommand.php:17

Even if I will switch this dependency to any other class which I have under App\ it behaves always like that. I literally have no idea what should I do more to make it works, all ways even the one with including explicitly the service inside services.yml does not work for me. Any clues?

  • 写回答

1条回答 默认 最新

  • dongwen1909 2018-04-24 11:33
    关注

    Did you clear the chache? php bin/console cache:clear.

    If that does not work, what are the outputs of php bin/console debug:container Process?

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法