-
Notifications
You must be signed in to change notification settings - Fork 34
/
bootstrap.php
86 lines (69 loc) · 2.36 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
define('APP_ENV', getenv('APP_ENV') ?: 'production');
// `NONCE_REPLACEMENT_STRING` is required for production, if not set we should not continue loading the application.
if (APP_ENV === 'production') {
if (!getenv('NONCE_REPLACEMENT_STRING')) {
throw new RuntimeException(
"Could not find `NONCE_REPLACEMENT_STRING`.\n"
);
}
} else {
// This is necessary, otherwise the open redirect protection does not work locally.
if (isset($_SERVER['SERVER_PORT'])) {
unset($_SERVER['SERVER_PORT']);
}
}
define('NONCE_REPLACEMENT_STRING', getenv('NONCE_REPLACEMENT_STRING') ?: '');
// 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;
}
}