1 |
6daefa8c
|
Petr Lukašík
|
<?php
|
2 |
|
|
/* SVN FILE: $Id: configure.php 4409 2007-02-02 13:20:59Z phpnut $ */
|
3 |
|
|
/**
|
4 |
|
|
* Short description for file.
|
5 |
|
|
*
|
6 |
|
|
* Long description for file
|
7 |
|
|
*
|
8 |
|
|
* PHP versions 4 and 5
|
9 |
|
|
*
|
10 |
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
11 |
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
12 |
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
13 |
|
|
* Las Vegas, Nevada 89104
|
14 |
|
|
*
|
15 |
|
|
* Licensed under The MIT License
|
16 |
|
|
* Redistributions of files must retain the above copyright notice.
|
17 |
|
|
*
|
18 |
|
|
* @filesource
|
19 |
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
20 |
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
21 |
|
|
* @package cake
|
22 |
|
|
* @subpackage cake.cake.libs
|
23 |
|
|
* @since CakePHP(tm) v 1.0.0.2363
|
24 |
|
|
* @version $Revision: 4409 $
|
25 |
|
|
* @modifiedby $LastChangedBy: phpnut $
|
26 |
|
|
* @lastmodified $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
|
27 |
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
28 |
|
|
*/
|
29 |
|
|
/**
|
30 |
|
|
* Short description for file.
|
31 |
|
|
*
|
32 |
|
|
* Long description for file
|
33 |
|
|
*
|
34 |
|
|
* @package cake
|
35 |
|
|
* @subpackage cake.cake.libs
|
36 |
|
|
*/
|
37 |
|
|
class Configure extends Object {
|
38 |
|
|
/**
|
39 |
|
|
* Hold array with paths to view files
|
40 |
|
|
*
|
41 |
|
|
* @var array
|
42 |
|
|
* @access public
|
43 |
|
|
*/
|
44 |
|
|
var $viewPaths = array();
|
45 |
|
|
/**
|
46 |
|
|
* Hold array with paths to controller files
|
47 |
|
|
*
|
48 |
|
|
* @var array
|
49 |
|
|
* @access public
|
50 |
|
|
*/
|
51 |
|
|
var $controllerPaths = array();
|
52 |
|
|
/**
|
53 |
|
|
* Enter description here...
|
54 |
|
|
*
|
55 |
|
|
* @var array
|
56 |
|
|
* @access public
|
57 |
|
|
*/
|
58 |
|
|
var $modelPaths = array();
|
59 |
|
|
/**
|
60 |
|
|
* Enter description here...
|
61 |
|
|
*
|
62 |
|
|
* @var array
|
63 |
|
|
* @access public
|
64 |
|
|
*/
|
65 |
|
|
var $helperPaths = array();
|
66 |
|
|
/**
|
67 |
|
|
* Enter description here...
|
68 |
|
|
*
|
69 |
|
|
* @var array
|
70 |
|
|
* @access public
|
71 |
|
|
*/
|
72 |
|
|
var $componentPaths = array();
|
73 |
|
|
/**
|
74 |
|
|
* Enter description here...
|
75 |
|
|
*
|
76 |
|
|
* @var integer
|
77 |
|
|
* @access public
|
78 |
|
|
*/
|
79 |
|
|
var $debug = null;
|
80 |
|
|
/**
|
81 |
|
|
* Return a singleton instance of Configure.
|
82 |
|
|
*
|
83 |
|
|
* @return Configure instance
|
84 |
|
|
* @access public
|
85 |
|
|
*/
|
86 |
|
|
function &getInstance() {
|
87 |
|
|
static $instance = array();
|
88 |
|
|
if (!$instance) {
|
89 |
|
|
$instance[0] =& new Configure;
|
90 |
|
|
$instance[0]->__loadBootstrap();
|
91 |
|
|
}
|
92 |
|
|
return $instance[0];
|
93 |
|
|
}
|
94 |
|
|
/**
|
95 |
|
|
* Used to write a dynamic var in the Configure instance.
|
96 |
|
|
*
|
97 |
|
|
* Usage
|
98 |
|
|
* Configure::write('One.key1', 'value of the Configure::One[key1]');
|
99 |
|
|
* Configure::write(array('One.key1' => 'value of the Configure::One[key1]'));
|
100 |
|
|
* Configure::write('One', array('key1'=>'value of the Configure::One[key1]', 'key2'=>'value of the Configure::One[key2]');
|
101 |
|
|
* Configure::write(array('One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]'));
|
102 |
|
|
*
|
103 |
|
|
* @param array $config
|
104 |
|
|
* @return void
|
105 |
|
|
* @access public
|
106 |
|
|
*/
|
107 |
|
|
function write($config, $value = null){
|
108 |
|
|
$_this =& Configure::getInstance();
|
109 |
|
|
|
110 |
|
|
if(!is_array($config) && $value !== null) {
|
111 |
|
|
$name = $_this->__configVarNames($config);
|
112 |
|
|
|
113 |
|
|
if(count($name) > 1){
|
114 |
|
|
$_this->{$name[0]}[$name[1]] = $value;
|
115 |
|
|
} else {
|
116 |
|
|
$_this->{$name[0]} = $value;
|
117 |
|
|
}
|
118 |
|
|
} else {
|
119 |
|
|
|
120 |
|
|
foreach($config as $names => $value){
|
121 |
|
|
$name = $_this->__configVarNames($names);
|
122 |
|
|
if(count($name) > 1){
|
123 |
|
|
$_this->{$name[0]}[$name[1]] = $value;
|
124 |
|
|
} else {
|
125 |
|
|
$_this->{$name[0]} = $value;
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
if ($config == 'debug' || (is_array($config) && in_array('debug', $config))) {
|
131 |
|
|
if ($_this->debug) {
|
132 |
|
|
//upraveno
|
133 |
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
134 |
|
|
|
135 |
|
|
if (function_exists('ini_set')) {
|
136 |
|
|
ini_set('display_errors', 1);
|
137 |
|
|
}
|
138 |
|
|
} else {
|
139 |
|
|
error_reporting(0);
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
/**
|
144 |
|
|
* Used to read Configure::$var
|
145 |
|
|
*
|
146 |
|
|
* Usage
|
147 |
|
|
* Configure::read('Name'); will return all values for Name
|
148 |
|
|
* Configure::read('Name.key'); will return only the value of Configure::Name[key]
|
149 |
|
|
*
|
150 |
|
|
* @param string $var
|
151 |
|
|
* @return string value of Configure::$var
|
152 |
|
|
* @access public
|
153 |
|
|
*/
|
154 |
|
|
function read($var = 'debug'){
|
155 |
|
|
$_this =& Configure::getInstance();
|
156 |
|
|
if($var === 'debug') {
|
157 |
|
|
if(!isset($_this->debug)){
|
158 |
|
|
$_this->debug = DEBUG;
|
159 |
|
|
}
|
160 |
|
|
return $_this->debug;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
$name = $_this->__configVarNames($var);
|
164 |
|
|
if(count($name) > 1){
|
165 |
|
|
if(isset($_this->{$name[0]}[$name[1]])) {
|
166 |
|
|
return $_this->{$name[0]}[$name[1]];
|
167 |
|
|
}
|
168 |
|
|
return null;
|
169 |
|
|
} else {
|
170 |
|
|
if(isset($_this->{$name[0]})) {
|
171 |
|
|
return $_this->{$name[0]};
|
172 |
|
|
}
|
173 |
|
|
return null;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
/**
|
177 |
|
|
* Used to delete a var from the Configure instance.
|
178 |
|
|
*
|
179 |
|
|
* Usage:
|
180 |
|
|
* Configure::delete('Name'); will delete the entire Configure::Name
|
181 |
|
|
* Configure::delete('Name.key'); will delete only the Configure::Name[key]
|
182 |
|
|
*
|
183 |
|
|
* @param string $var the var to be deleted
|
184 |
|
|
* @return void
|
185 |
|
|
* @access public
|
186 |
|
|
*/
|
187 |
|
|
function delete($var = null){
|
188 |
|
|
$_this =& Configure::getInstance();
|
189 |
|
|
|
190 |
|
|
$name = $_this->__configVarNames($var);
|
191 |
|
|
if(count($name) > 1){
|
192 |
|
|
unset($_this->{$name[0]}[$name[1]]);
|
193 |
|
|
} else {
|
194 |
|
|
unset($_this->{$name[0]});
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
/**
|
198 |
|
|
* Will load a file from app/config/configure_file.php
|
199 |
|
|
* variables in the files should be formated like:
|
200 |
|
|
* $config['name'] = 'value';
|
201 |
|
|
* These will be used to create dynamic Configure vars.
|
202 |
|
|
*
|
203 |
|
|
* Usage Configure::load('configure_file');
|
204 |
|
|
*
|
205 |
|
|
* @param string $fileName name of file to load, extension must be .php and only the name should be used, not the extenstion
|
206 |
|
|
* @return Configure::write
|
207 |
|
|
* @access public
|
208 |
|
|
*/
|
209 |
|
|
function load($fileName) {
|
210 |
|
|
$_this =& Configure::getInstance();
|
211 |
|
|
|
212 |
|
|
if(!file_exists(CONFIGS . $fileName . '.php')) {
|
213 |
|
|
trigger_error("Configure::load() - $fileName.php not found", E_USER_WARNING);
|
214 |
|
|
return false;
|
215 |
|
|
}
|
216 |
|
|
include(CONFIGS . $fileName . '.php');
|
217 |
|
|
if(!isset($config)){
|
218 |
|
|
trigger_error("Configure::load() - no variable \$config found in $fileName.php", E_USER_WARNING);
|
219 |
|
|
return false;
|
220 |
|
|
}
|
221 |
|
|
return $_this->write($config);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
/**
|
225 |
|
|
* Used to determine the current version of CakePHP
|
226 |
|
|
*
|
227 |
|
|
* Usage Configure::version();
|
228 |
|
|
*
|
229 |
|
|
* @return string Current version of CakePHP
|
230 |
|
|
* @access public
|
231 |
|
|
*/
|
232 |
|
|
function version() {
|
233 |
|
|
$_this =& Configure::getInstance();
|
234 |
|
|
if(!isset($_this->Cake['version'])){
|
235 |
|
|
require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
|
236 |
|
|
$_this->write($config);
|
237 |
|
|
}
|
238 |
|
|
return $_this->Cake['version'];
|
239 |
|
|
}
|
240 |
|
|
/**
|
241 |
|
|
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
|
242 |
|
|
*
|
243 |
|
|
* @param mixed $name
|
244 |
|
|
* @return array
|
245 |
|
|
* @access private
|
246 |
|
|
*/
|
247 |
|
|
function __configVarNames($name) {
|
248 |
|
|
if (is_string($name)) {
|
249 |
|
|
if (strpos($name, ".")) {
|
250 |
|
|
$name = explode(".", $name);
|
251 |
|
|
} else {
|
252 |
|
|
$name = array($name);
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
return $name;
|
256 |
|
|
}
|
257 |
|
|
/**
|
258 |
|
|
* Sets the var modelPaths
|
259 |
|
|
*
|
260 |
|
|
* @param array $modelPaths
|
261 |
|
|
* @access private
|
262 |
|
|
*/
|
263 |
|
|
function __buildModelPaths($modelPaths) {
|
264 |
|
|
$_this =& Configure::getInstance();
|
265 |
|
|
$_this->modelPaths[] = MODELS;
|
266 |
|
|
if (isset($modelPaths)) {
|
267 |
|
|
foreach($modelPaths as $value) {
|
268 |
|
|
$_this->modelPaths[] = $value;
|
269 |
|
|
}
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
/**
|
273 |
|
|
* Sets the var viewPaths
|
274 |
|
|
*
|
275 |
|
|
* @param array $viewPaths
|
276 |
|
|
* @access private
|
277 |
|
|
*/
|
278 |
|
|
function __buildViewPaths($viewPaths) {
|
279 |
|
|
$_this =& Configure::getInstance();
|
280 |
|
|
$_this->viewPaths[] = VIEWS;
|
281 |
|
|
$_this->viewPaths[] = VIEWS . 'errors' . DS;
|
282 |
|
|
if (isset($viewPaths)) {
|
283 |
|
|
foreach($viewPaths as $value) {
|
284 |
|
|
$_this->viewPaths[] = $value;
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
}
|
288 |
|
|
/**
|
289 |
|
|
* Sets the var controllerPaths
|
290 |
|
|
*
|
291 |
|
|
* @param array $controllerPaths
|
292 |
|
|
* @access private
|
293 |
|
|
*/
|
294 |
|
|
function __buildControllerPaths($controllerPaths) {
|
295 |
|
|
$_this =& Configure::getInstance();
|
296 |
|
|
$_this->controllerPaths[] = CONTROLLERS;
|
297 |
|
|
if (isset($controllerPaths)) {
|
298 |
|
|
foreach($controllerPaths as $value) {
|
299 |
|
|
$_this->controllerPaths[] = $value;
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
}
|
303 |
|
|
/**
|
304 |
|
|
* Sets the var helperPaths
|
305 |
|
|
*
|
306 |
|
|
* @param array $helperPaths
|
307 |
|
|
* @access private
|
308 |
|
|
*/
|
309 |
|
|
function __buildHelperPaths($helperPaths) {
|
310 |
|
|
$_this =& Configure::getInstance();
|
311 |
|
|
$_this->helperPaths[] = HELPERS;
|
312 |
|
|
if (isset($helperPaths)) {
|
313 |
|
|
foreach($helperPaths as $value) {
|
314 |
|
|
$_this->helperPaths[] = $value;
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
|
|
}
|
318 |
|
|
/**
|
319 |
|
|
* Sets the var componentPaths
|
320 |
|
|
*
|
321 |
|
|
* @param array $componentPaths
|
322 |
|
|
* @access private
|
323 |
|
|
*/
|
324 |
|
|
function __buildComponentPaths($componentPaths) {
|
325 |
|
|
$_this =& Configure::getInstance();
|
326 |
|
|
$_this->componentPaths[] = COMPONENTS;
|
327 |
|
|
if (isset($componentPaths)) {
|
328 |
|
|
foreach($componentPaths as $value) {
|
329 |
|
|
$_this->componentPaths[] = $value;
|
330 |
|
|
}
|
331 |
|
|
}
|
332 |
|
|
}
|
333 |
|
|
/**
|
334 |
|
|
* Loads the app/config/bootstrap.php
|
335 |
|
|
* If the alternative paths are set in this file
|
336 |
|
|
* they will be added to the paths vars
|
337 |
|
|
*
|
338 |
|
|
* @access private
|
339 |
|
|
*/
|
340 |
|
|
function __loadBootstrap() {
|
341 |
|
|
$_this =& Configure::getInstance();
|
342 |
|
|
$modelPaths = null;
|
343 |
|
|
$viewPaths = null;
|
344 |
|
|
$controllerPaths = null;
|
345 |
|
|
$helperPaths = null;
|
346 |
|
|
$componentPaths = null;
|
347 |
|
|
require APP_PATH . 'config' . DS . 'bootstrap.php';
|
348 |
|
|
$_this->__buildModelPaths($modelPaths);
|
349 |
|
|
$_this->__buildViewPaths($viewPaths);
|
350 |
|
|
$_this->__buildControllerPaths($controllerPaths);
|
351 |
|
|
$_this->__buildHelperPaths($helperPaths);
|
352 |
|
|
$_this->__buildComponentPaths($componentPaths);
|
353 |
|
|
}
|
354 |
|
|
}
|
355 |
|
|
?>
|