bootstrap.php 14 KB

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