-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependencies.php
50 lines (42 loc) · 1.33 KB
/
dependencies.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once 'app/config/Database.php';
foreach (glob("app/controller/*") as $filename) {
require_once $filename;
}
foreach (glob("app/repository/*") as $filename) {
require_once $filename;
}
foreach (glob("app/service/*") as $filename) {
require_once $filename;
}
foreach (glob("app/entity/*") as $filename) {
require_once $filename;
}
use Config\Database;
use Controller\AuthController;
use Repository\AdminRepository;
use Repository\AdminRepositoryImpl;
use Service\AuthService;
use Service\AuthServiceImpl;
use Controller\Home;
use function DI\create;
use function DI\get;
use function DI\autowire;
// Dependency injection configuration
$dependencies = [
// Database connection
'database' => fn() => Database::getConnection(),
AdminRepository::class => create(AdminRepositoryImpl::class)->constructor(get('database')),
AuthService::class => autowire(AuthServiceImpl::class),
AuthController::class => autowire(),
];
// ContainerBuilder initialization
$containerBuilder = new DI\ContainerBuilder();
$containerBuilder->addDefinitions($dependencies);
// Build dependency container
$container = $containerBuilder->build();
// Return combined array of dependencies and controllers
return array_merge($dependencies, [
'home' => new Home(),
'authController' => $container->get(AuthController::class),
]);