統計
| ブランチ: | リビジョン:

pictcode / lib / Cake / bootstrap.php @ d37b000c

履歴 | 表示 | アノテート | ダウンロード (13.932 KB)

1 635eef61 spyder1211
<?php
2
/**
3
 * Basic CakePHP functionality.
4
 *
5
 * Handles loading of core files needed on every request
6
 *
7
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
15
 * @link          http://cakephp.org CakePHP(tm) Project
16
 * @package       Cake
17
 * @since         CakePHP(tm) v 0.2.9
18
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
19
 */
20
21
define('TIME_START', microtime(true));
22
23
if (!defined('E_DEPRECATED')) {
24
        define('E_DEPRECATED', 8192);
25
}
26
27
if (!defined('E_USER_DEPRECATED')) {
28
        define('E_USER_DEPRECATED', E_USER_NOTICE);
29
}
30
error_reporting(E_ALL & ~E_DEPRECATED);
31
32
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
33
        define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(__FILE__)));
34
}
35
36
if (!defined('CORE_PATH')) {
37
        define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
38
}
39
40
if (!defined('WEBROOT_DIR')) {
41
        define('WEBROOT_DIR', 'webroot');
42
}
43
44
/**
45
 * Path to the cake directory.
46
 */
47
        define('CAKE', CORE_PATH . 'Cake' . DS);
48
49
/**
50
 * Path to the application's directory.
51
 */
52
if (!defined('APP')) {
53
        define('APP', ROOT . DS . APP_DIR . DS);
54
}
55
56
/**
57
 * Path to the application's libs directory.
58
 */
59
        define('APPLIBS', APP . 'Lib' . DS);
60
61
/**
62
 * Path to the public CSS directory.
63
 */
64
if (!defined('CSS')) {
65
        define('CSS', WWW_ROOT . 'css' . DS);
66
}
67
68
/**
69
 * Path to the public JavaScript directory.
70
 */
71
if (!defined('JS')) {
72
        define('JS', WWW_ROOT . 'js' . DS);
73
}
74
75
/**
76
 * Path to the public images directory.
77
 */
78
if (!defined('IMAGES')) {
79
        define('IMAGES', WWW_ROOT . 'img' . DS);
80
}
81
82
/**
83
 * Path to the tests directory.
84
 */
85
if (!defined('TESTS')) {
86
        define('TESTS', APP . 'Test' . DS);
87
}
88
89
/**
90
 * Path to the temporary files directory.
91
 */
92
if (!defined('TMP')) {
93
        define('TMP', APP . 'tmp' . DS);
94
}
95
96
/**
97
 * Path to the logs directory.
98
 */
99
if (!defined('LOGS')) {
100
        define('LOGS', TMP . 'logs' . DS);
101
}
102
103
/**
104
 * Path to the cache files directory. It can be shared between hosts in a multi-server setup.
105
 */
106
if (!defined('CACHE')) {
107
        define('CACHE', TMP . 'cache' . DS);
108
}
109
110
/**
111
 * Path to the vendors directory.
112
 */
113
if (!defined('VENDORS')) {
114
        define('VENDORS', ROOT . DS . 'vendors' . DS);
115
}
116
117
/**
118
 * Web path to the public images directory.
119
 */
120
if (!defined('IMAGES_URL')) {
121
        define('IMAGES_URL', 'img/');
122
}
123
124
/**
125
 * Web path to the CSS files directory.
126
 */
127
if (!defined('CSS_URL')) {
128
        define('CSS_URL', 'css/');
129
}
130
131
/**
132
 * Web path to the js files directory.
133
 */
134
if (!defined('JS_URL')) {
135
        define('JS_URL', 'js/');
136
}
137
138
require CAKE . 'basics.php';
139
require CAKE . 'Core' . DS . 'App.php';
140
require CAKE . 'Error' . DS . 'exceptions.php';
141
142
spl_autoload_register(array('App', 'load'));
143
144
App::uses('ErrorHandler', 'Error');
145
App::uses('Configure', 'Core');
146
App::uses('CakePlugin', 'Core');
147
App::uses('Cache', 'Cache');
148
App::uses('Object', 'Core');
149
App::uses('Multibyte', 'I18n');
150
151
App::$bootstrapping = true;
152
153
/**
154
 * Full URL prefix
155
 */
156
if (!defined('FULL_BASE_URL')) {
157
        $s = null;
158
        if (env('HTTPS')) {
159
                $s = 's';
160
        }
161
162
        $httpHost = env('HTTP_HOST');
163
164
        if (isset($httpHost)) {
165
                define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost);
166
                Configure::write('App.fullBaseUrl', FULL_BASE_URL);
167
        }
168
        unset($httpHost, $s);
169
}
170
171
Configure::write('App.imageBaseUrl', IMAGES_URL);
172
Configure::write('App.cssBaseUrl', CSS_URL);
173
Configure::write('App.jsBaseUrl', JS_URL);
174
175
176
if (!function_exists('mb_stripos')) {
177
178
/**
179
 * Find position of first occurrence of a case-insensitive string.
180
 *
181
 * @param string $haystack The string from which to get the position of the first occurrence of $needle.
182
 * @param string $needle The string to find in $haystack.
183
 * @param int $offset The position in $haystack to start searching.
184
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
185
 * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string, or false
186
 *    if $needle is not found.
187
 */
188
        function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
189
                return Multibyte::stripos($haystack, $needle, $offset);
190
        }
191
192
}
193
194
if (!function_exists('mb_stristr')) {
195
196
/**
197
 * Finds first occurrence of a string within another, case insensitive.
198
 *
199
 * @param string $haystack The string from which to get the first occurrence of $needle.
200
 * @param string $needle The string to find in $haystack.
201
 * @param bool $part Determines which portion of $haystack this function returns.
202
 *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
203
 *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
204
 *    Default value is false.
205
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
206
 * @return string|bool The portion of $haystack, or false if $needle is not found.
207
 */
208
        function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
209
                return Multibyte::stristr($haystack, $needle, $part);
210
        }
211
212
}
213
214
if (!function_exists('mb_strlen')) {
215
216
/**
217
 * Get string length.
218
 *
219
 * @param string $string The string being checked for length.
220
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
221
 * @return int The number of characters in string $string having character encoding encoding.
222
 *    A multi-byte character is counted as 1.
223
 */
224
        function mb_strlen($string, $encoding = null) {
225
                return Multibyte::strlen($string);
226
        }
227
228
}
229
230
if (!function_exists('mb_strpos')) {
231
232
/**
233
 * Find position of first occurrence of a string.
234
 *
235
 * @param string $haystack The string being checked.
236
 * @param string $needle The position counted from the beginning of haystack.
237
 * @param int $offset The search offset. If it is not specified, 0 is used.
238
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
239
 * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string.
240
 *    If $needle is not found, it returns false.
241
 */
242
        function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
243
                return Multibyte::strpos($haystack, $needle, $offset);
244
        }
245
246
}
247
248
if (!function_exists('mb_strrchr')) {
249
250
/**
251
 * Finds the last occurrence of a character in a string within another.
252
 *
253
 * @param string $haystack The string from which to get the last occurrence of $needle.
254
 * @param string $needle The string to find in $haystack.
255
 * @param bool $part Determines which portion of $haystack this function returns.
256
 *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
257
 *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
258
 *    Default value is false.
259
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
260
 * @return string|bool The portion of $haystack. or false if $needle is not found.
261
 */
262
        function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
263
                return Multibyte::strrchr($haystack, $needle, $part);
264
        }
265
266
}
267
268
if (!function_exists('mb_strrichr')) {
269
270
/**
271
 * Finds the last occurrence of a character in a string within another, case insensitive.
272
 *
273
 * @param string $haystack The string from which to get the last occurrence of $needle.
274
 * @param string $needle The string to find in $haystack.
275
 * @param bool $part Determines which portion of $haystack this function returns.
276
 *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
277
 *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
278
 *    Default value is false.
279
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
280
 * @return string|bool The portion of $haystack. or false if $needle is not found.
281
 */
282
        function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
283
                return Multibyte::strrichr($haystack, $needle, $part);
284
        }
285
286
}
287
288
if (!function_exists('mb_strripos')) {
289
290
/**
291
 * Finds position of last occurrence of a string within another, case insensitive
292
 *
293
 * @param string $haystack The string from which to get the position of the last occurrence of $needle.
294
 * @param string $needle The string to find in $haystack.
295
 * @param int $offset The position in $haystack to start searching.
296
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
297
 * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string,
298
 *    or false if $needle is not found.
299
 */
300
        function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
301
                return Multibyte::strripos($haystack, $needle, $offset);
302
        }
303
304
}
305
306
if (!function_exists('mb_strrpos')) {
307
308
/**
309
 * Find position of last occurrence of a string in a string.
310
 *
311
 * @param string $haystack The string being checked, for the last occurrence of $needle.
312
 * @param string $needle The string to find in $haystack.
313
 * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
314
 *    Negative values will stop searching at an arbitrary point prior to the end of the string.
315
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
316
 * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string.
317
 *    If $needle is not found, it returns false.
318
 */
319
        function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
320
                return Multibyte::strrpos($haystack, $needle, $offset);
321
        }
322
323
}
324
325
if (!function_exists('mb_strstr')) {
326
327
/**
328
 * Finds first occurrence of a string within another
329
 *
330
 * @param string $haystack The string from which to get the first occurrence of $needle.
331
 * @param string $needle The string to find in $haystack
332
 * @param bool $part Determines which portion of $haystack this function returns.
333
 *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
334
 *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
335
 *    Default value is FALSE.
336
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
337
 * @return string|bool The portion of $haystack, or true if $needle is not found.
338
 */
339
        function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
340
                return Multibyte::strstr($haystack, $needle, $part);
341
        }
342
343
}
344
345
if (!function_exists('mb_strtolower')) {
346
347
/**
348
 * Make a string lowercase
349
 *
350
 * @param string $string The string being lowercased.
351
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
352
 * @return string with all alphabetic characters converted to lowercase.
353
 */
354
        function mb_strtolower($string, $encoding = null) {
355
                return Multibyte::strtolower($string);
356
        }
357
358
}
359
360
if (!function_exists('mb_strtoupper')) {
361
362
/**
363
 * Make a string uppercase
364
 *
365
 * @param string $string The string being uppercased.
366
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
367
 * @return string with all alphabetic characters converted to uppercase.
368
 */
369
        function mb_strtoupper($string, $encoding = null) {
370
                return Multibyte::strtoupper($string);
371
        }
372
373
}
374
375
if (!function_exists('mb_substr_count')) {
376
377
/**
378
 * Count the number of substring occurrences
379
 *
380
 * @param string $haystack The string being checked.
381
 * @param string $needle The string being found.
382
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
383
 * @return int The number of times the $needle substring occurs in the $haystack string.
384
 */
385
        function mb_substr_count($haystack, $needle, $encoding = null) {
386
                return Multibyte::substrCount($haystack, $needle);
387
        }
388
389
}
390
391
if (!function_exists('mb_substr')) {
392
393
/**
394
 * Get part of string
395
 *
396
 * @param string $string The string being checked.
397
 * @param int $start The first position used in $string.
398
 * @param int $length The maximum length of the returned string.
399
 * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
400
 * @return string The portion of $string specified by the $string and $length parameters.
401
 */
402
        function mb_substr($string, $start, $length = null, $encoding = null) {
403
                return Multibyte::substr($string, $start, $length);
404
        }
405
406
}
407
408
if (!function_exists('mb_encode_mimeheader')) {
409
410
/**
411
 * Encode string for MIME header
412
 *
413
 * @param string $str The string being encoded
414
 * @param string $charset specifies the name of the character set in which str is represented in.
415
 *    The default value is determined by the current NLS setting (mbstring.language).
416
 * @param string $transferEncoding specifies the scheme of MIME encoding.
417
 *    It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
418
 * @param string $linefeed specifies the EOL (end-of-line) marker with which
419
 *    mb_encode_mimeheader() performs line-folding
420
 *    (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
421
 *    The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
422
 * @param int $indent [definition unknown and appears to have no affect]
423
 * @return string A converted version of the string represented in ASCII.
424
 */
425
        function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
426
                return Multibyte::mimeEncode($str, $charset, $linefeed);
427
        }
428
429
}
430
431
Configure::bootstrap(isset($boot) ? $boot : true);
432
433
if (function_exists('mb_internal_encoding')) {
434
        $encoding = Configure::read('App.encoding');
435
        if (!empty($encoding)) {
436
                mb_internal_encoding($encoding);
437
        }
438
        if (!empty($encoding) && function_exists('mb_regex_encoding')) {
439
                mb_regex_encoding($encoding);
440
        }
441
}