Cannot autowire service

Asked

Viewed 28 times

-1

How do I resolve the following error: Cannot autowire service "App Service Responseservice": argument "$sucesso" of method "__Construct()" is type-hinted "bool", you should configure its value explicitly.

Responseservice.php

<?php

namespace App\Service;

use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

class ResponseService extends ServiceEntityRepository
{
    /**
     * @var bool
     */
    private $sucesso;

    /**
     * @var int
     */
    private $paginaAtual;

    /**
     * @var int
     */
    private $itensPorPagina;

    private $conteudoResposta;

    public function __construct(
        bool $sucesso /*,
        int $paginaAtual,
        int $itensPorPagina,
        $conteudoResposta*/
    )
    {
        $this->sucesso = $sucesso;
        /*$this->paginaAtual = $paginaAtual;
        $this->itensPorPagina = $itensPorPagina;
        $this->conteudoResposta = $conteudoResposta;*/
    }

    public function getResponse(): JsonResponse
    {
        $conteudoResposta = [
            'sucesso' => $this->sucesso,
            'paginaAtual' => $this->paginaAtual,
            'itensPorPagina' => $this->itensPorPagina,
            'conteudoResposta' => $this->conteudoResposta
        ];

        return new JsonResponse($conteudoResposta);
    }
}

method that calls Responseservice:

public function buscarTodos(Request $request): Response
    {
        $informacoesDeOrdenacao = $this->extratorDadosRequestService->buscarDadosOrdenacao($request);
        $informacoesDeFiltro = $this->extratorDadosRequestService->buscarDadosFiltro($request);
        [$paginaAtual, $itensPorPagina] = $this->extratorDadosRequestService->buscaDadosPaginacao($request);

        $entityList = $this->repository->findBy(
            $informacoesDeFiltro,
            $informacoesDeOrdenacao,
            $itensPorPagina,
            ($paginaAtual - 1) * $itensPorPagina
        );

        $resposta = new ResponseService(
            true,
            $paginaAtual,
            $itensPorPagina,
            $entityList
        );

        return $resposta->getResponse();
    }
  • 1

    https://symfonycasts.com/screencast/symfony-fundamentals/service-config See if it helps

1 answer

0

I managed to solve. no services.yaml add:

App Service Responseservice: Arguments: $success: bool $paginaAtual: int $itensPorPagina: int $countryRespoint: '%kernel.debug%'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.