Вот так выглядит Kernel.php
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function getProjectDir(): string
{
return \dirname(__DIR__);
}
public function registerBundles(): array
{
return [
new FrameworkBundle(),
];
}
protected function configureContainer(ContainerConfigurator $container): void
{
$confifDir = $this->getProjectDir() . '/config';
$container->import($confifDir . '/services.php', 'glob');
}
protected function configureRoutes(RoutingConfigurator $routes): void
{
$confifDir = $this->getProjectDir() . '/config';
$routes->import($confifDir . '/routes.php');
}
}
config/services.php выглядит так
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return function (ContainerConfigurator $configurator) {
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure();
$services->load('App\\', '../src/*')
->exclude('../src/{Entities,Kernel2.php}');
};
controller
<?php
namespace App\Controllers;
use App\Repositories\TestRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
/**
* Class OrderController
* @package App\Controllers
*/
class OrderController extends ControllerResolver
{
/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \App\Repositories\TestRepository $testRepository
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index(Request $request, TestRepository $testRepository)
{
/** @var string $t */
$t = $testRepository->build();
return new Response($t);
}
}
Получаю ошибку
Controller "App\Controllers\OrderController::index()" requires that you provide a value for the "$testRepository" 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.
Как подключить autowiring, чтобы в контроллере работало? проект собираю просто из компонентов, не брал skeleton. Роуты работают норм