/
index.php
113 lines (85 loc) · 3.66 KB
/
index.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
Plugin Name: Sarcofag
Plugin URI: http://milsdev.com/#portfolio
Description: OOP wrapper for the WordPress
Version: 2.0.2
Author: Mil's
Author URI: http://milsdev.com/
*/
function __registerAutoloaderPaths($loader, $target) {
if (is_string($target)) {
if (!file_exists($target)) {
return false;
}
$paths = include $target;
if (!is_array($paths)) {
throw new \Exception('Autoloader file must return array of [namespace => path]');
}
} else if (is_array($target)) {
$paths = $target;
} else {
throw new \Exception('$target must be string if it is file or array with autoloader paths');
}
foreach ($paths as $namespace => $autoloaderPaths) {
if (is_array($autoloaderPaths)) {
$autoloaderPaths = array_map('realpath', $autoloaderPaths);
} else {
$autoloaderPaths = [realpath($autoloaderPaths)];
}
$loader->setPsr4($namespace, $autoloaderPaths);
}
}
if (defined('TIMER_RUN')) {
define('TIMER_DIFF_INIT_WP', microtime(true) - TIMER_RUN);
}
define('TIMER_INIT_SARCOFAG', microtime(true));
$loader = include ABSPATH . '/vendor/autoload.php';
$loader->setPsr4('Sarcofag\\', [ __DIR__ . '/src' ]);
$cacheStorage = null;
if (defined("SARCOFAG_CACHE_PARAMS")) {
$cacheStorage = \Laminas\Cache\StorageFactory::factory(SARCOFAG_CACHE_PARAMS);
}
if (!is_null($cacheStorage) && $cacheStorage->hasItem('diContainerBuilder')) {
__registerAutoloaderPaths($loader, get_template_directory() . '/src/config/autoloader.inc.php');
$containerBuilder = $cacheStorage->getItem('diContainerBuilder');
} else {
$containerBuilder = new DI\ContainerBuilder();
$definitions = [];
$definitions[] = new \DI\Definition\Source\DefinitionFile(__DIR__ . '/config/di.inc.php');
$activePlugins = get_option('active_plugins');
foreach ($activePlugins as $activePlugin) {
$pluginConfigPath = WP_PLUGIN_DIR . '/' . trim(dirname($activePlugin), '/') . '/config';
$pluginDiConfig = $pluginConfigPath . '/di.inc.php';
__registerAutoloaderPaths($loader, $pluginConfigPath . '/autoloader.inc.php');
if (!file_exists($pluginDiConfig)) {
continue;
}
$definitions[] = new \DI\Definition\Source\DefinitionFile($pluginDiConfig);
}
$themeConfigPath = get_template_directory() . '/src/config';
$iterator = new RegexIterator(new IteratorIterator(
new DirectoryIterator($themeConfigPath)),
'/^di\..*inc\.php$/i',
RegexIterator::MATCH);
__registerAutoloaderPaths($loader, $themeConfigPath . '/autoloader.inc.php');
/* @var $iteratorItem \DirectoryIterator */
foreach ($iterator as $iteratorItem) {
$definitions[] = new \DI\Definition\Source\DefinitionFile($iteratorItem->getRealPath());
}
array_map([$containerBuilder, 'addDefinitions'], $definitions);
if (!is_null($cacheStorage)) {
$cacheStorage->setItem('diContainerBuilder', $containerBuilder);
}
}
define('TIMER_SARCOFAG_BUILD', microtime(true));
$containerBuilder->addDefinitions(['DefaultCacheStorage' => $cacheStorage]);
$di = $containerBuilder->build();
define('TIMER_DIFF_SARCOFAG_BUILD', microtime(true) - TIMER_SARCOFAG_BUILD);
__registerAutoloaderPaths($loader, $di->get('autoloader.paths'));
define('TIMER_DIFF_INIT_SARCOFAG', microtime(true) - TIMER_INIT_SARCOFAG);
define('TIMER_INIT_EVENT_MANAGER', microtime(true));
define('ICL_DEFAULT_LANGUAGE_CODE', $di->get('icl.default.language.code'));
$di->get('EventManager');
define('TIMER_DIFF_INIT_EVENT_MANAGER', microtime(true) - TIMER_INIT_EVENT_MANAGER);
define('TIMER_SARCOFAG_INITIALIZED', microtime(true));