The Error
Hello, I am getting the following error:
Type error: Argument 2 passed to ApiExceptionBundle\EventListener\ApiExceptionSubscriber::__construct() must implement interface ApiExceptionBundle\Component\Factory\ResponseFactoryInterface, string given, called in C:\htdocs\projects\myproject\var\cache\dev\appDevDebugProjectContainer.php on line 4293
The Call Stack Showing The Incorrect Parameter Type Being Passed
As can be seen below from the call stack, the second parameter is a string. (But it should actually be an object instantiated of that type).
at ApiExceptionSubscriber->__construct(true, 'ApiExceptionBundle\\Component\\Factory\\ResponseFactoryInterface', true, array('/admin/'))
in appDevDebugProjectContainer.php (line 4293)
The Constructor Definition
The subscriber is located at myproject\src\ApiExceptionBundle\EventListener\ApiExceptionSubscriber.php and its constructor definition is the following:
public function __construct($debug, ResponseFactoryInterface $responseFactory, $enabled = true, $excludedPaths = [])
(Notice above that it is expecting a ResponseFactoryInterface object rather than a string).
The Services.yml Entry
In myproject/src/ApiExceptionBundle/Resources/config/services.yml, the relevant entry is below:
ApiExceptionBundle\EventListener\ApiExceptionSubscriber:
arguments:
$responseFactory: 'ApiExceptionBundle\Component\Factory\ResponseFactoryInterface'
Other Things I've Tried
From the original example I am using, I see that there is actually an @ symbol at the beginning of the $responseFactory argument assignment in the services.yml file.
The original code that I am using as an example, has a services.yml entry similar to this:
$responseFactory: '@ApiExceptionBundle\Component\Factory\ResponseFactoryInterface'
Unfortunately when I try to add the @ symbol in my code (like above), it gives me this error:
PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot dump de
finition because of invalid class name ('@ApiExceptionBundle\\Component\\Factory\\ResponseFactory') in C:\h
tdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Dumper\PhpDumper.ph
p:1568
Questions
So, I have 2 questions:
- What am I doing wrong? (I'm assuming it's the way I'm referencing things in services.yml).
- What does the @ symbol do? Taking a guess, I think it tells the code to instantiate an object of the class referenced rather than just literally using the string. Is that correct?