bootstrap.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. }
  151. if (!function_exists('mb_stripos')) {
  152. /**
  153. * Find position of first occurrence of a case-insensitive string.
  154. *
  155. * @param string $haystack The string from which to get the position of the first occurrence of $needle.
  156. * @param string $needle The string to find in $haystack.
  157. * @param integer $offset The position in $haystack to start searching.
  158. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  159. * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
  160. * if $needle is not found.
  161. */
  162. function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
  163. return Multibyte::stripos($haystack, $needle, $offset);
  164. }
  165. }
  166. if (!function_exists('mb_stristr')) {
  167. /**
  168. * Finds first occurrence of a string within another, case insensitive.
  169. *
  170. * @param string $haystack The string from which to get the first occurrence of $needle.
  171. * @param string $needle The string to find in $haystack.
  172. * @param boolean $part Determines which portion of $haystack this function returns.
  173. * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  174. * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
  175. * Default value is false.
  176. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  177. * @return string|boolean The portion of $haystack, or false if $needle is not found.
  178. */
  179. function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
  180. return Multibyte::stristr($haystack, $needle, $part);
  181. }
  182. }
  183. if (!function_exists('mb_strlen')) {
  184. /**
  185. * Get string length.
  186. *
  187. * @param string $string The string being checked for length.
  188. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  189. * @return integer The number of characters in string $string having character encoding encoding.
  190. * A multi-byte character is counted as 1.
  191. */
  192. function mb_strlen($string, $encoding = null) {
  193. return Multibyte::strlen($string);
  194. }
  195. }
  196. if (!function_exists('mb_strpos')) {
  197. /**
  198. * Find position of first occurrence of a string.
  199. *
  200. * @param string $haystack The string being checked.
  201. * @param string $needle The position counted from the beginning of haystack.
  202. * @param integer $offset The search offset. If it is not specified, 0 is used.
  203. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  204. * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
  205. * If $needle is not found, it returns false.
  206. */
  207. function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
  208. return Multibyte::strpos($haystack, $needle, $offset);
  209. }
  210. }
  211. if (!function_exists('mb_strrchr')) {
  212. /**
  213. * Finds the last occurrence of a character in a string within another.
  214. *
  215. * @param string $haystack The string from which to get the last occurrence of $needle.
  216. * @param string $needle The string to find in $haystack.
  217. * @param boolean $part Determines which portion of $haystack this function returns.
  218. * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  219. * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
  220. * Default value is false.
  221. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  222. * @return string|boolean The portion of $haystack. or false if $needle is not found.
  223. */
  224. function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
  225. return Multibyte::strrchr($haystack, $needle, $part);
  226. }
  227. }
  228. if (!function_exists('mb_strrichr')) {
  229. /**
  230. * Finds the last occurrence of a character in a string within another, case insensitive.
  231. *
  232. * @param string $haystack The string from which to get the last occurrence of $needle.
  233. * @param string $needle The string to find in $haystack.
  234. * @param boolean $part Determines which portion of $haystack this function returns.
  235. * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  236. * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
  237. * Default value is false.
  238. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  239. * @return string|boolean The portion of $haystack. or false if $needle is not found.
  240. */
  241. function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
  242. return Multibyte::strrichr($haystack, $needle, $part);
  243. }
  244. }
  245. if (!function_exists('mb_strripos')) {
  246. /**
  247. * Finds position of last occurrence of a string within another, case insensitive
  248. *
  249. * @param string $haystack The string from which to get the position of the last occurrence of $needle.
  250. * @param string $needle The string to find in $haystack.
  251. * @param integer $offset The position in $haystack to start searching.
  252. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  253. * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
  254. * or false if $needle is not found.
  255. */
  256. function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
  257. return Multibyte::strripos($haystack, $needle, $offset);
  258. }
  259. }
  260. if (!function_exists('mb_strrpos')) {
  261. /**
  262. * Find position of last occurrence of a string in a string.
  263. *
  264. * @param string $haystack The string being checked, for the last occurrence of $needle.
  265. * @param string $needle The string to find in $haystack.
  266. * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
  267. * Negative values will stop searching at an arbitrary point prior to the end of the string.
  268. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  269. * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
  270. * If $needle is not found, it returns false.
  271. */
  272. function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
  273. return Multibyte::strrpos($haystack, $needle, $offset);
  274. }
  275. }
  276. if (!function_exists('mb_strstr')) {
  277. /**
  278. * Finds first occurrence of a string within another
  279. *
  280. * @param string $haystack The string from which to get the first occurrence of $needle.
  281. * @param string $needle The string to find in $haystack
  282. * @param boolean $part Determines which portion of $haystack this function returns.
  283. * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  284. * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
  285. * Default value is FALSE.
  286. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  287. * @return string|boolean The portion of $haystack, or true if $needle is not found.
  288. */
  289. function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
  290. return Multibyte::strstr($haystack, $needle, $part);
  291. }
  292. }
  293. if (!function_exists('mb_strtolower')) {
  294. /**
  295. * Make a string lowercase
  296. *
  297. * @param string $string The string being lowercased.
  298. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  299. * @return string with all alphabetic characters converted to lowercase.
  300. */
  301. function mb_strtolower($string, $encoding = null) {
  302. return Multibyte::strtolower($string);
  303. }
  304. }
  305. if (!function_exists('mb_strtoupper')) {
  306. /**
  307. * Make a string uppercase
  308. *
  309. * @param string $string The string being uppercased.
  310. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  311. * @return string with all alphabetic characters converted to uppercase.
  312. */
  313. function mb_strtoupper($string, $encoding = null) {
  314. return Multibyte::strtoupper($string);
  315. }
  316. }
  317. if (!function_exists('mb_substr_count')) {
  318. /**
  319. * Count the number of substring occurrences
  320. *
  321. * @param string $haystack The string being checked.
  322. * @param string $needle The string being found.
  323. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  324. * @return integer The number of times the $needle substring occurs in the $haystack string.
  325. */
  326. function mb_substr_count($haystack, $needle, $encoding = null) {
  327. return Multibyte::substrCount($haystack, $needle);
  328. }
  329. }
  330. if (!function_exists('mb_substr')) {
  331. /**
  332. * Get part of string
  333. *
  334. * @param string $string The string being checked.
  335. * @param integer $start The first position used in $string.
  336. * @param integer $length The maximum length of the returned string.
  337. * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
  338. * @return string The portion of $string specified by the $string and $length parameters.
  339. */
  340. function mb_substr($string, $start, $length = null, $encoding = null) {
  341. return Multibyte::substr($string, $start, $length);
  342. }
  343. }
  344. if (!function_exists('mb_encode_mimeheader')) {
  345. /**
  346. * Encode string for MIME header
  347. *
  348. * @param string $str The string being encoded
  349. * @param string $charset specifies the name of the character set in which str is represented in.
  350. * The default value is determined by the current NLS setting (mbstring.language).
  351. * @param string $transfer_encoding specifies the scheme of MIME encoding.
  352. * It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
  353. * @param string $linefeed specifies the EOL (end-of-line) marker with which
  354. * mb_encode_mimeheader() performs line-folding
  355. * (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
  356. * The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
  357. * @param integer $indent [definition unknown and appears to have no affect]
  358. * @return string A converted version of the string represented in ASCII.
  359. */
  360. function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
  361. return Multibyte::mimeEncode($str, $charset, $linefeed);
  362. }
  363. }