Added $container
This commit is contained in:
@@ -72,10 +72,15 @@ SQL
|
|||||||
);
|
);
|
||||||
|
|
||||||
// -------------------------
|
// -------------------------
|
||||||
// Services (instantiation simple et explicite)
|
// Services (container simple)
|
||||||
// -------------------------
|
// -------------------------
|
||||||
$twig = new Twig(new FilesystemLoader(__DIR__ . '/../views'), ['cache' => false]);
|
$container = [];
|
||||||
$postRepository = new App\Repositories\PostRepositoryMedoo($database);
|
|
||||||
|
// Vue Twig
|
||||||
|
$container['view'] = new Twig(new FilesystemLoader(__DIR__ . '/../views'), ['cache' => false]);
|
||||||
|
|
||||||
|
// Repository Post (Medoo)
|
||||||
|
$container['postRepository'] = new App\Repositories\PostRepositoryMedoo($database);
|
||||||
|
|
||||||
// -------------------------
|
// -------------------------
|
||||||
// Slim app
|
// Slim app
|
||||||
@@ -96,9 +101,9 @@ if (!$isDebug) {
|
|||||||
|
|
||||||
// Middlewares essentiels
|
// Middlewares essentiels
|
||||||
$app->addBodyParsingMiddleware();
|
$app->addBodyParsingMiddleware();
|
||||||
$app->add(TwigMiddleware::create($app, $twig));
|
$app->add(TwigMiddleware::create($app, $container['view']));
|
||||||
|
|
||||||
// Charger routes (web.php reçoit explicitement $twig et $postRepository)
|
// Charger routes (web.php reçoit maintenant le container)
|
||||||
(require __DIR__ . '/../src/Routes/web.php')($app, $twig, $postRepository);
|
(require __DIR__ . '/../src/Routes/web.php')($app, $container);
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|||||||
@@ -7,8 +7,14 @@ use Slim\Views\Twig;
|
|||||||
use App\Repositories\PostRepositoryMedoo;
|
use App\Repositories\PostRepositoryMedoo;
|
||||||
use App\Controllers\PostController;
|
use App\Controllers\PostController;
|
||||||
|
|
||||||
return function (App $app, Twig $twig, PostRepositoryMedoo $repo): void {
|
return function (App $app, array $container): void {
|
||||||
$controller = new PostController($twig, $repo);
|
/** @var Twig $view */
|
||||||
|
$view = $container['view'];
|
||||||
|
/** @var PostRepositoryMedoo $repo */
|
||||||
|
$repo = $container['postRepository'];
|
||||||
|
|
||||||
|
// Instancier le controller une seule fois tout en gardant la modularité
|
||||||
|
$controller = new PostController($view, $repo);
|
||||||
|
|
||||||
$app->get('/', [$controller, 'index']);
|
$app->get('/', [$controller, 'index']);
|
||||||
$app->get('/admin', [$controller, 'admin']);
|
$app->get('/admin', [$controller, 'admin']);
|
||||||
|
|||||||
Reference in New Issue
Block a user