Я пытаюсь выполнить автоматическое подключение в своей пользовательской сущности Symfony \ Component \ Security \ Core \ Encoder \ UserPasswordEncoderInterface и получение ошибки Слишком мало аргументов для функции App \ Entity \ User :: __ construct ().
public function __construct(UserPasswordEncoderInterface $encoder)
{
$this->packages = new ArrayCollection();
$this->passwordEncoder = $encoder;
}
В моем services.yaml
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.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# 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,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']




Как указано в комментарии, сущности специально не рассматриваются как службы, поэтому не могут использовать автоматическое подключение.
Предполагается, что сущности будут использоваться для простых манипуляций с данными. Если вам нужно получить доступ к другим компонентам Symfony, одним из ваших вариантов является создание класса менеджера, который обрабатывает дополнительную работу или полагается на прослушиватели событий.
Вы видите эту часть services.yaml "exclude: ... Entity ..."? Это, в частности, говорит о том, что НЕ следует автоматически подключать что-либо в каталоге Entity. Сущности доктрины - это не услуги. Для большинства практических целей в них нельзя вводить какие-либо вещества.