-
Notifications
You must be signed in to change notification settings - Fork 7
/
bootstrap.php
69 lines (55 loc) · 1.8 KB
/
bootstrap.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
define('APP_ENV', getenv('APP_ENV') ?: 'production');
// make sure we are in the correct directory
chdir(__DIR__);
use Laminas\Mvc\Application;
use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
// Composer autoloading
include __DIR__ . '/vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new RuntimeException(
"Unable to load application using composer autoloading.\n"
);
}
class ConsoleRunner
{
/**
* @return array
*/
public static function getConfig(): array
{
// Retrieve configuration
$appConfig = require __DIR__ . '/config/application.config.php';
if (APP_ENV === 'development' && file_exists(__DIR__ . '/config/development.config.php')) {
$appConfig = ArrayUtils::merge($appConfig, require __DIR__ . '/config/development.config.php');
}
return $appConfig;
}
/**
* @return Application
*/
public static function getApplication(): Application
{
// Retrieve configuration
$appConfig = self::getConfig();
// Initialise the application!
return Application::init($appConfig);
}
/**
* @return ServiceManager
*/
public static function getServiceManager(): ServiceManager
{
$appConfig = self::getConfig();
$servicesConfig = $appConfig['service_manager'] ?? [];
$smConfig = new ServiceManagerConfig($servicesConfig);
$serviceManager = new ServiceManager();
$smConfig->configureServiceManager($serviceManager);
$serviceManager->setService('ApplicationConfig', $appConfig);
$moduleManager = $serviceManager->get('ModuleManager');
$moduleManager->loadModules();
return $serviceManager;
}
}