forked from dvelum/dvelum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.php
109 lines (95 loc) · 2.81 KB
/
console.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
<?php
/*
* DVelum console application
* Return codes
* 0 - Good
* 1 - Empty URI
* 2 - Wrong URI
* 3 - Application Error
*/
if (isset($_SERVER['argc']) && $_SERVER['argc'] < 2 ){
exit(1);
}
$scriptStart = microtime(true);
$dvelumRoot = str_replace('\\', '/' , __DIR__);
// should be without last slash
if ($dvelumRoot[strlen($dvelumRoot) - 1] == '/')
$dvelumRoot = substr($dvelumRoot, 0, -1);
define('DVELUM', true);
define('DVELUM_ROOT' ,$dvelumRoot);
define('DVELUM_CONSOLE', true);
define('DVELUM_WWW_PATH', DVELUM_ROOT . '/www/');
chdir(DVELUM_ROOT);
//===== loading kernel =========
/*
* Including initial config
*/
$bootCfg = include DVELUM_ROOT . '/application/configs/common/dist/init.php';
/*
* Register composer autoload
*/
require DVELUM_ROOT . '/vendor/autoload.php';
/*
* Including Autoloader class
*/
require DVELUM_ROOT . '/dvelum2/Dvelum/Autoload.php';
$autoloader = new \Dvelum\Autoload($bootCfg['autoloader']);
use \Dvelum\Config\Factory as ConfigFactory;
use \Dvelum\Config;
use \Dvelum\Request;
$configStorage = ConfigFactory::storage();
$configStorage->setConfig($bootCfg['config_storage']);
//==== Loading system ===========
/*
* Reload storage options from local system
*/
$configStorage->setConfig(Config::storage()->get('config_storage.php')->__toArray());
/*
* Connecting main configuration file
*/
$config = Config::storage()->get('main.php');
$config->set('frontend_router', 'Path');
$_SERVER['DOCUMENT_ROOT'] = $config->get('wwwpath');
switch ($config->get('development')){
// production
case 0 :
$configStorage->addPath('./application/configs/prod/');
break;
// development
case 1 :
$configStorage->addPath('./application/configs/dev/');
/*
* Disable op caching for development mode
*/
ini_set('opcache.enable', 0);
$configStorage->setConfig(['debug' => true]);
break;
// test
case 2 :
$configStorage->addPath('./application/configs/test/');
break;
}
/*
* Setting autoloader config
*/
$autoloaderCfg = Config::storage()->get('autoloader.php')->__toArray();
$autoloaderCfg['debug'] = $config->get('development');
if(!isset($autoloaderCfg['useMap']))
$autoloaderCfg['useMap'] = true;
if($autoloaderCfg['useMap'] && $autoloaderCfg['map'])
$autoloaderCfg['map'] = require Config::storage()->getPath($autoloaderCfg['map']);
else
$autoloaderCfg['map'] = false;
$autoloader->setConfig($autoloaderCfg);
/*
* Starting the application
*/
$appClass = $config->get('application');
if(!class_exists($appClass))
throw new Exception('Application class '.$appClass.' does not exist! Check config "application" option!');
$app = new $appClass($config);
$app->setAutoloader($autoloader);
$app->init();
$request = Request::factory();
$request->setUri($_SERVER['argv'][1]);
$app->runConsole();