-
Notifications
You must be signed in to change notification settings - Fork 11
/
console.php
94 lines (78 loc) · 2.31 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
<?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/dist/init.php';
/*
* Including Autoloader class
*/
require DVELUM_ROOT . '/dvelum/library/Autoloader.php';
$autoloader = new Autoloader($bootCfg['autoloader']);
$configStorage = Config::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');
$_SERVER['DOCUMENT_ROOT'] = $config->get('wwwpath');
/*
* Disable op caching for development mode
*/
if($config->get('development')){
ini_set('opcache.enable', 0);
}
/*
* Setting autoloader config
*/
$autoloaderCfg = $config->get('autoloader');
$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);
/**
* Enable Zend Framework 1.x library support
*/
set_include_path(get_include_path() . PATH_SEPARATOR . $config->get('vendor_lib'));
Registry::set('main', $config , 'config');
/*
* 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::getInstance()->setUri($_SERVER['argv'][1]);
$app->run();