This repository has been archived by the owner on Mar 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
134 lines (112 loc) · 3.79 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
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
<?php
/**
* General bootstrap
*
* @package Core
* @author Jeremy MOULIN <jeremy.moulin@doonoyz.com>
* @copyright 2008-2009 Doonoyz
* @version Paper
*/
class Gears_Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initHeader() {
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set ( 'Europe/Paris' );
}
protected function _initSession() {
Zend_Session::start();
}
protected function _initRegistry() {
$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
Zend_Registry::setInstance($registry);
return $registry;
}
protected function _initConfig() {
$config = new Zend_Config_Ini ( ROOT_DIR . 'application/application.ini', ENVIRONMENT );
$registry = $this->getResource('registry');
$registry->set ( 'config', $config );
return $config;
}
protected function _initAcl() {
$config = $this->getResource('config');
$registry = $this->getResource('registry');
$registry->acl = new Gears_Acl();
return $registry->acl;
}
protected function _initDatabase() {
$registry = $this->getResource('registry');
$db = $this->getPluginResource('db')->getDbAdapter();
$db->setFetchMode(Zend_Db::FETCH_OBJ);
$registry->database = $db;
Zend_Db_Table::setDefaultAdapter($db);
return $registry->database;
}
protected function _initCache() {
$config = $this->getResource('config');
$cache = Zend_Cache::factory ( $config->cache->front->driver, $config->cache->back->driver, $config->cache->front->options->toArray(), $config->cache->back->options->toArray() );
$registry = $this->getResource('registry');
$registry->cache = $cache;
return $cache;
}
protected function _initLanguage() {
$registry = $this->getResource('registry');
$config = $this->getResource('config');
$cache = $this->getResource('cache');
$registry->languages = $config->language->toArray();
$session = new Zend_Session_Namespace("Gears_Bootstrap_Language");
if ($config->use_language) {
Zend_Translate::setCache ( $cache );
$tr = new Zend_Translate ( 'Zend_Translate_Adapter_Gettext', ROOT_DIR . 'application/languages/lang.en.mo', 'en' );
foreach ($registry->languages as $lang => $text) {
$tr->addTranslation ( ROOT_DIR . 'application/languages/lang.' . $lang . '.mo', $lang );
}
try {
$locale = new Zend_Locale ( $session->locale );
} catch ( Zend_Locale_Exception $e ) {
$locale = new Zend_Locale ( 'en' );
}
try {
$tr->setLocale ( $locale->getLanguage () );
} catch ( Exception $e ) {
$locale = new Zend_Locale ( 'en' );
$tr->setLocale ( $locale->getLanguage () );
}
$session->locale = $locale->getLanguage ();
$registry->translate = $tr;
if (! function_exists ( 'tr' )) {
function tr($text) {
$tr = Zend_Registry::getInstance ()->translate;
return $tr->_ ( $text );
}
}
} else {
$session->locale = 'en';
if (! function_exists ( 'tr' )) {
function tr($text) {
return $text;
}
}
}
}
protected function _initMail() {
$config = $this->getResource('config');
$tr = new Zend_Mail_Transport_Smtp ( $config->mail->smtp, $config->mail->config->toArray () );
Zend_Mail::setDefaultTransport ( $tr );
}
protected function _initLayout() {
$config = new Zend_Config_Ini ( ROOT_DIR . 'application/application.ini', ENVIRONMENT );
$layout = Zend_Layout::startMvc($config->views);
return $layout;
}
protected function _initFront() {
$config = $this->getResource('config');
if ($config->router) {
// setup controller
$frontController = Zend_Controller_Front::getInstance ();
// load routing rules configuration
$config = new Zend_Config_Ini ( ROOT_DIR . 'application/routes.ini', 'all' );
$router = $frontController->getRouter ();
$router->addConfig ( $config, 'routes' );
$frontController->setRouter ( $router );
}
}
}