bootstrap.php 14 KB

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