This repository has been archived by the owner on Jan 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutoLoader.php
executable file
·247 lines (192 loc) · 8.23 KB
/
AutoLoader.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
namespace Raman;
use Raman\Config\Raman_Config_Consts;
use Raman\Config\Raman_Config_Configs;
use Raman\Config\Raman_Config_Adapter;
class AutoLoader
{
/**
*
* @var \Zend_Application_Bootstrap_Bootstrap
*/
protected $_bootstrap;
protected $_siteConfigs;
/**
* @param \Zend_Application_Bootstrap_Bootstrap $bootstrap
*/
public function __construct($bootstrap)
{
$this->_bootstrap = $bootstrap;
}
public function init()
{
mb_internal_encoding("UTF-8");
date_default_timezone_set('UTC');
$this->addAutoLoader();
$this->includePaths();
$this->bootDoctrine();
$this->bootView();
$this->configure();
$this->initView();
$this->initRoutes();
$this->initSecurity();
$this->initFrontControllerOutput();
}
/**
* Add Raman Autoloader
* Add Vendor Autoloader
*/
protected function addAutoLoader()
{
include_once 'Raman/AutoLoader.php';
spl_autoload_register('\Raman\autoload');
}
protected function includePaths()
{
// Vendor
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . 'Vendor' . DIRECTORY_SEPARATOR);
// Add Entity to include path
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'Application' . DIRECTORY_SEPARATOR . 'Entity' . DIRECTORY_SEPARATOR);
// Add Models to include path
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPLICATION_PATH . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR);
// Add Forms to include path
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPLICATION_PATH . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR);
}
protected function bootDoctrine()
{
/* Using Doctrine with Bisna */
$this->_bootstrap->bootstrap('doctrine');
$doctrine = $this->_bootstrap->getResource('doctrine');
$config = new \Doctrine\ORM\Configuration();
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());
$config->setResultCacheImpl(new \Doctrine\Common\Cache\ApcCache());
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache());
\Zend_Registry::set('doctrine' , $doctrine);
\Zend_Registry::set('cacheDataEnable' , true);
\Zend_Registry::set('cacheDataType' , 'APC');
\Zend_Registry::set('cacheDataLifeTime', 3600);
}
protected function bootView()
{
if(!\Zend_Registry::isRegistered('view'))
{
$view = new \Zend_View();
\Zend_Registry::set('view', $view);
}
}
protected function configure()
{
$configsXml = file_get_contents(APPLICATION_PATH . '/configs/configs.xml');
$dom = new \Zend_Dom_Query($configsXml);
$dbUsername = $dom->query("Database Username")->current()->nodeValue;
$dbPassword = $dom->query("Database Password")->current()->nodeValue;
$dbName = $dom->query("Database Name")->current()->nodeValue;
$dbServer = $dom->query("Database Server")->current()->nodeValue;
$doctrine = \Zend_Registry::get('doctrine');
$ramanConfigAdapter = new Raman_Config_Adapter();
$ramanConfigConfigs = new Raman_Config_Configs();
$this->_siteConfigs = $ramanConfigAdapter->getByProfileName();
$ramanConfigConfigs->configDatabase($dbUsername, $dbPassword, $dbName, $dbServer);
$ramanConfigConfigs->configDataCaching($this->_siteConfigs->get('cacheDataEnable'), $this->_siteConfigs->get('cacheDataType'), $this->_siteConfigs->get('cacheDataLifeTime'));
$ramanConfigConfigs->configDefaultProtocol('http');
$ramanConfigConfigs->configRootUrl(DEFAULT_PROTOCOL . '://' . $this->_siteConfigs->get('domain'));
$ramanConfigConfigs->configSecureRootUrl(DEFAULT_PROTOCOL . 's://' . $this->_siteConfigs->get('domain'));
$ramanConfigConfigs->configSiteTitle($this->_siteConfigs->get('siteTitle'), $this->_siteConfigs->get('siteSeperator'));
$ramanConfigConfigs->configTemplate($this->_siteConfigs->get('siteTemplate')->get('id'), $this->_siteConfigs->get('siteTemplate')->get('name'));
$ramanConfigConfigs->configLanguage($this->_siteConfigs->get('siteLanguage')->get('id'), $this->_siteConfigs->get('siteLanguage')->get('shortName'), $this->_siteConfigs->get('siteLanguage')->get('fullName'));
$ramanConfigConfigs->configPiwik($this->_siteConfigs->get('piwikServer'), $this->_siteConfigs->get('piwikSiteID'));
$ramanConfigConfigs->configDescription($this->_siteConfigs->get('siteDescription'));
$ramanConfigConfigs->configSiteAuthors("Mostafa Lavaei <[email protected]>");
$ramanConfigConfigs->configKeywords($this->_siteConfigs->get('siteKeywords'));
}
protected function initView()
{
$siteMetaTags = array();
$siteStyles = array();
$siteScripts = array();
$view = \Zend_Registry::get('view');
$view->setEncoding('UTF-8');
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headLink()->appendStylesheet(ROOT_URL . 'libPlugins/bootstrap/css/bootstrap.min.css')
->appendStylesheet(ROOT_URL . 'libPlugins/bootstrap/css/bootstrap-theme.min.css')
->appendStylesheet(ROOT_URL . 'libPlugins/bootstrap-dialog/css/bootstrap-dialog.min.css')
->appendStylesheet(ROOT_URL . 'libCss/Raman/Form-Responsive.css');
$view->headScript()->appendFile(ROOT_URL . 'libJs/jquery-1.11.1.min.js')
->appendFile(ROOT_URL . 'libPlugins/bootstrap/js/bootstrap.min.js')
->appendFile(ROOT_URL . 'libPlugins/bootstrap-dialog/js/bootstrap-dialog.min.js');
if($this->_siteConfigs)
{
if($this->_siteConfigs ->get('siteMetaTags'))
$siteMetaTags = json_decode($this->_siteConfigs->get('siteMetaTags'));
if($this->_siteConfigs ->get('siteStyles'))
$siteStyles = json_decode($this->_siteConfigs->get('siteStyles'));
if($this->_siteConfigs ->get('siteScripts'))
$siteScripts = json_decode($this->_siteConfigs->get('siteScripts'));
foreach ($siteMetaTags as $name=>$value)
{
$view->headMeta()->appendHttpEquiv($name, $value);
}
foreach($siteStyles as $style)
{
$view->headLink()->appendStylesheet(str_replace("<ROOT_URL>", ROOT_URL, $style));
}
foreach($siteScripts as $script)
{
$view->headScript()->appendFile(str_replace("<ROOT_URL>", ROOT_URL, $script));
}
}
\Zend_Registry::set('view', $view);
}
protected function initRoutes()
{
$front = \Zend_Controller_Front::getInstance();
$router = $front->getRouter();
/*
* Route Ajax Requests
*/
$router->addRoute('ajaxHandler', new \Zend_Controller_Router_Route('/:controller/ajax/:request/', array(
'controller' => ':controller',
'action' => 'ajax'
)));
$router->addRoute('ajaxHandlerModules', new \Zend_Controller_Router_Route('/:module/:controller/ajax/:request/', array(
'module' => ':module',
'controller' => ':controller',
'action' => 'ajax'
)));
}
protected function initSecurity()
{
new \Raman\Security\Raman_Security_Xss($this->_bootstrap);
new \Raman\Security\Raman_Security_Csrf();
}
protected function initFrontControllerOutput()
{
$this->_bootstrap->bootstrap('FrontController');
$frontController = $this->_bootstrap->getResource('FrontController');
$response = new \Zend_Controller_Response_Http;
$response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
$frontController->setResponse($response);
return $frontController;
}
}
function autoload($className)
{
$extensions = array(".php");//acceptable extentions
$includePaths = explode(PATH_SEPARATOR, get_include_path());//include paths
$exNameSpace = explode('\\', $className);//explode class name
$pureClassName = $exNameSpace[sizeof($exNameSpace) - 1];// get class name witout its namespace
$relativePath = str_replace("_" , DIRECTORY_SEPARATOR, $pureClassName);//the class path from include path
foreach ($includePaths as $iPaths)
{
$absolutePath = $iPaths . DIRECTORY_SEPARATOR . $relativePath; //absolute class path
foreach ($extensions as $ext)
{
if (is_readable($absolutePath . $ext))
{
require_once $absolutePath . $ext;
break;
}
}
}
}