Answer the question
In order to leave comments, you need to log in
Does an abstract class need an interface?
When I make an Interface in a bundle, then I make an abstract class with an implementation and apply this interface to it, and then I create a child inheriting this abstract class, Symphony swears that it cannot find a candidate and asks to explicitly declare an alias for this interface.
But after all, an instance from an abstract class should not be created in principle. And the implementation of the interface in this case is only one. There shouldn't have been any mistakes.
---
services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
Vendor\SomeBundle\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Examples,Repository,Message}'
Vendor\SomeBundle\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
Vendor\SomeBundle\Controller\TokenController:
autowire: false
services:
_defaults:
autowire: true
autoconfigure: true
public: true
Vendor\SomeBundle\Controller\SomeController:
autowire: true
arguments:
$authenticator: Vendor\SomeBundle\Examples\Authenticator
Vendor\SomeBundle\Examples\Authenticator:
calls:
- setIdentityClassName: ...
Cannot autowire service "Vendor\SomeBundle\Controller\SomeController": argument "$authenticator" of method "__construct()" references interface "Vendor\SomeBundle\S
ervices\AuthenticatorInterface" but no such service exists. You should maybe alias this interface to the existing "Vendor\SomeBundle\Examples\Authenticator" service.
Vendor\SomeBundle\Services\AuthenticatorInterface:
'@Vendor\SomeBundle\Examples\Authenticator'
interface AuthenticatorInterface {}
abstract class AbstractAuthenticator implements AuthenticatorInterface {}
class Authenticator extends AbstractAuthenticator {}
Answer the question
In order to leave comments, you need to log in
It's not about the abstract class. Symfony requires explicit registration of interface implementations.
It will look something like this:
services:
...
App/Interfaces/UserRepositoryInterface:
alias: App/Repositories/UserRepository
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question