use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Category;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/push", name="push")
* @param Request $request
* @param PublisherInterface $publisher
* @return Response
*/
public function push(Request $request, PublisherInterface $publisher): Response
{
$update = new Update(
'/chat',
json_encode(['message' => 'Hello World!'])
);
$publisher($update);
return new JsonResponse($publisher);
}
I get this error:
Cannot autowire argument $publisher of "App\Controller\MainController::push()": it references interface "Symfony\Component\Mercure\PublisherInterface" but no such service exists. Did you create a class that implements this interface?
/*
* This file is part of the Mercure Component project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Symfony\Component\Mercure;
/**
* @author Vincent Chalamon <[email protected]>
*
* @experimental
*/
interface PublisherInterface
{
public function __invoke(Update $update): string;
}
Why is this happening? The class is already there. I followed Symfony's official docs and saw some tutorials and they don't seem to have this issue. Do you have any idea of what the problem could be there? Thanks!
Did you create a class that implements this interface?- El_Vanjaservices.ymland check thatautowireis set to true, that your controller is in./src/Controller/folder and that in services.yml you have this:App\Controller\: resource: '../src/Controller/' tags: ['controller.service_arguments']- PierrickM