V
V
vladislav9972021-12-06 16:04:53
PHP
vladislav997, 2021-12-06 16:04:53

Why is there an error when transferring the service to the controller parameters?

Tell me why an error occurs when transferring the service to the controller parameters?

use App\Service\CustomService;

// где "...." - в этом месте еще куча разных сервисов подключаются, но они работают
public function index(...., CustomService $customService): Response
{
        $telegramBot = new \TelegramBot\Api\Client($bot->getToken());
        // logic
        $telegramBot->on(function (\TelegramBot\Api\Types\Update $update) use ($telegramBot, $customService) {
                $customService->customMethod(
                        $parametr1 = '...',
                        $parametr2 = '...',
                        $parametr3 = '...',
                );
        }, function () {
            return true;
        });
}

and this is what it says:

request.CRITICAL: Uncaught PHP Exception RuntimeException: "Controller "App\Controller\TestController::index()" requires that you provide a value for the "$customService" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one." at /var/www/project/vendor/symfony/http-kernel/Controller/ArgumentResolver.php line 80 {"exception":"[object] (RuntimeException(code: 0): Controller \"App\\Controller\\TestController ::index()\" requires that you provide a value for the \"$customService\" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.


How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vladislav997, 2021-12-06
@vladislav997

you just had to do cache:clear

A
Anton Shamanov, 2021-12-06
@SilenceOfWinter

index(...., CustomService $customService)
what version of php does this work in?
+ lost the closing bracket of on(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question