PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/Utility/Debugger.php

https://github.com/jplante815/meican
PHP | 726 lines | 437 code | 60 blank | 229 comment | 78 complexity | a4abf144536137a04e3a1fb1684efaef MD5 | raw file
  1. <?php
  2. /**
  3. * Framework debugging and PHP error-handling class
  4. *
  5. * Provides enhanced logging, stack traces, and rendering debug views
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2011, 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-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org CakePHP(tm) Project
  17. * @package Cake.Utility
  18. * @since CakePHP(tm) v 1.2.4560
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. //App::uses('CakeLog', 'Log');
  22. //App::uses('String', 'Utility');
  23. include_once 'libs/Log/Log.php';
  24. include_once 'libs/Utility/String.php';
  25. /**
  26. * Provide custom logging and error handling.
  27. *
  28. * Debugger overrides PHP's default error handling to provide stack traces and enhanced logging
  29. *
  30. * @package Cake.Utility
  31. * @link http://book.cakephp.org/2.0/en/development/debugging.html#debugger-class
  32. */
  33. class Debugger {
  34. /**
  35. * A list of errors generated by the application.
  36. *
  37. * @var array
  38. */
  39. public $errors = array();
  40. /**
  41. * The current output format.
  42. *
  43. * @var string
  44. */
  45. protected $_outputFormat = 'js';
  46. /**
  47. * Templates used when generating trace or error strings. Can be global or indexed by the format
  48. * value used in $_outputFormat.
  49. *
  50. * @var string
  51. */
  52. protected $_templates = array(
  53. 'log' => array(
  54. 'trace' => '{:reference} - {:path}, line {:line}',
  55. 'error' => "{:error} ({:code}): {:description} in [{:file}, line {:line}]"
  56. ),
  57. 'js' => array(
  58. 'error' => '',
  59. 'info' => '',
  60. 'trace' => '<pre class="stack-trace">{:trace}</pre>',
  61. 'code' => '',
  62. 'context' => '',
  63. 'links' => array()
  64. ),
  65. 'html' => array(
  66. 'trace' => '<pre class="cake-error trace"><b>Trace</b> <p>{:trace}</p></pre>',
  67. 'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>'
  68. ),
  69. 'txt' => array(
  70. 'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}",
  71. 'code' => '',
  72. 'info' => ''
  73. ),
  74. 'base' => array(
  75. 'traceLine' => '{:reference} - {:path}, line {:line}',
  76. 'trace' => "Trace:\n{:trace}\n",
  77. 'context' => "Context:\n{:context}\n",
  78. ),
  79. 'log' => array(),
  80. );
  81. /**
  82. * Holds current output data when outputFormat is false.
  83. *
  84. * @var string
  85. */
  86. protected $_data = array();
  87. /**
  88. * Constructor.
  89. *
  90. */
  91. public function __construct() {
  92. $docRef = ini_get('docref_root');
  93. if (empty($docRef) && function_exists('ini_set')) {
  94. ini_set('docref_root', 'http://php.net/');
  95. }
  96. if (!defined('E_RECOVERABLE_ERROR')) {
  97. define('E_RECOVERABLE_ERROR', 4096);
  98. }
  99. $e = '<pre class="cake-error">';
  100. $e .= '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
  101. $e .= '.style.display = (document.getElementById(\'{:id}-trace\').style.display == ';
  102. $e .= '\'none\' ? \'\' : \'none\');"><b>{:error}</b> ({:code})</a>: {:description} ';
  103. $e .= '[<b>{:path}</b>, line <b>{:line}</b>]';
  104. $e .= '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
  105. $e .= '{:links}{:info}</div>';
  106. $e .= '</pre>';
  107. $this->_templates['js']['error'] = $e;
  108. $t = '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
  109. $t .= '{:context}{:code}{:trace}</div>';
  110. $this->_templates['js']['info'] = $t;
  111. $links = array();
  112. $link = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-code\')';
  113. $link .= '.style.display = (document.getElementById(\'{:id}-code\').style.display == ';
  114. $link .= '\'none\' ? \'\' : \'none\')">Code</a>';
  115. $links['code'] = $link;
  116. $link = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-context\')';
  117. $link .= '.style.display = (document.getElementById(\'{:id}-context\').style.display == ';
  118. $link .= '\'none\' ? \'\' : \'none\')">Context</a>';
  119. $links['context'] = $link;
  120. $this->_templates['js']['links'] = $links;
  121. $this->_templates['js']['context'] = '<pre id="{:id}-context" class="cake-context" ';
  122. $this->_templates['js']['context'] .= 'style="display: none;">{:context}</pre>';
  123. $this->_templates['js']['code'] = '<pre id="{:id}-code" class="cake-code-dump" ';
  124. $this->_templates['js']['code'] .= 'style="display: none;">{:code}</pre>';
  125. $e = '<pre class="cake-error"><b>{:error}</b> ({:code}) : {:description} ';
  126. $e .= '[<b>{:path}</b>, line <b>{:line}]</b></pre>';
  127. $this->_templates['html']['error'] = $e;
  128. $this->_templates['html']['context'] = '<pre class="cake-context"><b>Context</b> ';
  129. $this->_templates['html']['context'] .= '<p>{:context}</p></pre>';
  130. }
  131. /**
  132. * Returns a reference to the Debugger singleton object instance.
  133. *
  134. * @param string $class
  135. * @return object
  136. */
  137. public static function &getInstance($class = null) {
  138. static $instance = array();
  139. if (!empty($class)) {
  140. if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) {
  141. $instance[0] = new $class();
  142. }
  143. }
  144. if (!$instance) {
  145. $instance[0] = new Debugger();
  146. }
  147. return $instance[0];
  148. }
  149. /**
  150. * Recursively formats and outputs the contents of the supplied variable.
  151. *
  152. *
  153. * @param mixed $var the variable to dump
  154. * @return void
  155. * @see Debugger::exportVar()
  156. * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::dump
  157. */
  158. public static function dump($var) {
  159. pr(self::exportVar($var));
  160. }
  161. /**
  162. * Creates an entry in the log file. The log entry will contain a stack trace from where it was called.
  163. * as well as export the variable using exportVar. By default the log is written to the debug log.
  164. *
  165. * @param mixed $var Variable or content to log
  166. * @param integer $level type of log to use. Defaults to LOG_DEBUG
  167. * @return void
  168. * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::log
  169. */
  170. public static function log($var, $level = LOG_DEBUG) {
  171. $source = self::trace(array('start' => 1)) . "\n";
  172. CakeLog::write($level, "\n" . $source . self::exportVar($var));
  173. }
  174. /**
  175. * Overrides PHP's default error handling.
  176. *
  177. * @param integer $code Code of error
  178. * @param string $description Error description
  179. * @param string $file File on which error occurred
  180. * @param integer $line Line that triggered the error
  181. * @param array $context Context
  182. * @return boolean true if error was handled
  183. * @deprecated This function is superseded by Debugger::outputError()
  184. */
  185. public static function showError($code, $description, $file = null, $line = null, $context = null) {
  186. $_this = Debugger::getInstance();
  187. if (empty($file)) {
  188. $file = '[internal]';
  189. }
  190. if (empty($line)) {
  191. $line = '??';
  192. }
  193. $path = self::trimPath($file);
  194. $info = compact('code', 'description', 'file', 'line');
  195. if (!in_array($info, $_this->errors)) {
  196. $_this->errors[] = $info;
  197. } else {
  198. return;
  199. }
  200. switch ($code) {
  201. case E_PARSE:
  202. case E_ERROR:
  203. case E_CORE_ERROR:
  204. case E_COMPILE_ERROR:
  205. case E_USER_ERROR:
  206. $error = 'Fatal Error';
  207. $level = LOG_ERROR;
  208. break;
  209. case E_WARNING:
  210. case E_USER_WARNING:
  211. case E_COMPILE_WARNING:
  212. case E_RECOVERABLE_ERROR:
  213. $error = 'Warning';
  214. $level = LOG_WARNING;
  215. break;
  216. case E_NOTICE:
  217. case E_USER_NOTICE:
  218. $error = 'Notice';
  219. $level = LOG_NOTICE;
  220. break;
  221. case E_DEPRECATED:
  222. case E_USER_DEPRECATED:
  223. $error = 'Deprecated';
  224. $level = LOG_NOTICE;
  225. break;
  226. default:
  227. return;
  228. break;
  229. }
  230. $data = compact(
  231. 'level', 'error', 'code', 'description', 'file', 'path', 'line', 'context'
  232. );
  233. echo $_this->outputError($data);
  234. if ($error == 'Fatal Error') {
  235. exit();
  236. }
  237. return true;
  238. }
  239. /**
  240. * Outputs a stack trace based on the supplied options.
  241. *
  242. * ### Options
  243. *
  244. * - `depth` - The number of stack frames to return. Defaults to 999
  245. * - `format` - The format you want the return. Defaults to the currently selected format. If
  246. * format is 'array' or 'points' the return will be an array.
  247. * - `args` - Should arguments for functions be shown? If true, the arguments for each method call
  248. * will be displayed.
  249. * - `start` - The stack frame to start generating a trace from. Defaults to 0
  250. *
  251. * @param array $options Format for outputting stack trace
  252. * @return mixed Formatted stack trace
  253. * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::trace
  254. */
  255. public static function trace($options = array()) {
  256. $_this = Debugger::getInstance();
  257. $defaults = array(
  258. 'depth' => 999,
  259. 'format' => $_this->_outputFormat,
  260. 'args' => false,
  261. 'start' => 0,
  262. 'scope' => null,
  263. 'exclude' => array('call_user_func_array', 'trigger_error')
  264. );
  265. $options = Set::merge($defaults, $options);
  266. $backtrace = debug_backtrace();
  267. $count = count($backtrace);
  268. $back = array();
  269. $_trace = array(
  270. 'line' => '??',
  271. 'file' => '[internal]',
  272. 'class' => null,
  273. 'function' => '[main]'
  274. );
  275. for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
  276. $trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]);
  277. $signature = $reference = '[main]';
  278. if (isset($backtrace[$i + 1])) {
  279. $next = array_merge($_trace, $backtrace[$i + 1]);
  280. $signature = $reference = $next['function'];
  281. if (!empty($next['class'])) {
  282. $signature = $next['class'] . '::' . $next['function'];
  283. $reference = $signature . '(';
  284. if ($options['args'] && isset($next['args'])) {
  285. $args = array();
  286. foreach ($next['args'] as $arg) {
  287. $args[] = Debugger::exportVar($arg);
  288. }
  289. $reference .= join(', ', $args);
  290. }
  291. $reference .= ')';
  292. }
  293. }
  294. if (in_array($signature, $options['exclude'])) {
  295. continue;
  296. }
  297. if ($options['format'] == 'points' && $trace['file'] != '[internal]') {
  298. $back[] = array('file' => $trace['file'], 'line' => $trace['line']);
  299. } elseif ($options['format'] == 'array') {
  300. $back[] = $trace;
  301. } else {
  302. if (isset($_this->_templates[$options['format']]['traceLine'])) {
  303. $tpl = $_this->_templates[$options['format']]['traceLine'];
  304. } else {
  305. $tpl = $_this->_templates['base']['traceLine'];
  306. }
  307. $trace['path'] = self::trimPath($trace['file']);
  308. $trace['reference'] = $reference;
  309. unset($trace['object'], $trace['args']);
  310. $back[] = String::insert($tpl, $trace, array('before' => '{:', 'after' => '}'));
  311. }
  312. }
  313. if ($options['format'] == 'array' || $options['format'] == 'points') {
  314. return $back;
  315. }
  316. return implode("\n", $back);
  317. }
  318. /**
  319. * Shortens file paths by replacing the application base path with 'APP', and the CakePHP core
  320. * path with 'CORE'.
  321. *
  322. * @param string $path Path to shorten
  323. * @return string Normalized path
  324. */
  325. public static function trimPath($path) {
  326. if (!defined('CAKE_CORE_INCLUDE_PATH') || !defined('APP')) {
  327. return $path;
  328. }
  329. if (strpos($path, APP) === 0) {
  330. return str_replace(APP, 'APP' . DS, $path);
  331. } elseif (strpos($path, CAKE_CORE_INCLUDE_PATH) === 0) {
  332. return str_replace(CAKE_CORE_INCLUDE_PATH, 'CORE', $path);
  333. } elseif (strpos($path, ROOT) === 0) {
  334. return str_replace(ROOT, 'ROOT', $path);
  335. }
  336. if (strpos($path, CAKE) === 0) {
  337. return str_replace($corePath, 'CORE' . DS, $path);
  338. }
  339. return $path;
  340. }
  341. /**
  342. * Grabs an excerpt from a file and highlights a given line of code.
  343. *
  344. * Usage:
  345. *
  346. * `Debugger::excerpt('/path/to/file', 100, 4);`
  347. *
  348. * The above would return an array of 8 items. The 4th item would be the provided line,
  349. * and would be wrapped in `<span class="code-highlight"></span>`. All of the lines
  350. * are processed with highlight_string() as well, so they have basic PHP syntax highlighting
  351. * applied.
  352. *
  353. * @param string $file Absolute path to a PHP file
  354. * @param integer $line Line number to highlight
  355. * @param integer $context Number of lines of context to extract above and below $line
  356. * @return array Set of lines highlighted
  357. * @see http://php.net/highlight_string
  358. * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::excerpt
  359. */
  360. public static function excerpt($file, $line, $context = 2) {
  361. $lines = array();
  362. if (!file_exists($file)) {
  363. return array();
  364. }
  365. $data = @explode("\n", file_get_contents($file));
  366. if (empty($data) || !isset($data[$line])) {
  367. return;
  368. }
  369. for ($i = $line - ($context + 1); $i < $line + $context; $i++) {
  370. if (!isset($data[$i])) {
  371. continue;
  372. }
  373. $string = str_replace(array("\r\n", "\n"), "", highlight_string($data[$i], true));
  374. if ($i == $line) {
  375. $lines[] = '<span class="code-highlight">' . $string . '</span>';
  376. } else {
  377. $lines[] = $string;
  378. }
  379. }
  380. return $lines;
  381. }
  382. /**
  383. * Converts a variable to a string for debug output.
  384. *
  385. * *Note:* The following keys will have their contents replaced with
  386. * `*****`:
  387. *
  388. * - password
  389. * - login
  390. * - host
  391. * - database
  392. * - port
  393. * - prefix
  394. * - schema
  395. *
  396. * This is done to protect database credentials, which could be accidentally
  397. * shown in an error message if CakePHP is deployed in development mode.
  398. *
  399. * @param string $var Variable to convert
  400. * @param integer $recursion
  401. * @return string Variable as a formatted string
  402. * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::exportVar
  403. */
  404. public static function exportVar($var, $recursion = 0) {
  405. switch (strtolower(gettype($var))) {
  406. case 'boolean':
  407. return ($var) ? 'true' : 'false';
  408. break;
  409. case 'integer':
  410. case 'double':
  411. return $var;
  412. break;
  413. case 'string':
  414. if (trim($var) == "") {
  415. return '""';
  416. }
  417. return '"' . h($var) . '"';
  418. break;
  419. case 'object':
  420. return get_class($var) . "\n" . self::_object($var);
  421. case 'array':
  422. $var = array_merge($var, array_intersect_key(array(
  423. 'password' => '*****',
  424. 'login' => '*****',
  425. 'host' => '*****',
  426. 'database' => '*****',
  427. 'port' => '*****',
  428. 'prefix' => '*****',
  429. 'schema' => '*****'
  430. ), $var));
  431. $out = "array(";
  432. $vars = array();
  433. foreach ($var as $key => $val) {
  434. if ($recursion >= 0) {
  435. if (is_numeric($key)) {
  436. $vars[] = "\n\t" . self::exportVar($val, $recursion - 1);
  437. } else {
  438. $vars[] = "\n\t" . self::exportVar($key, $recursion - 1)
  439. . ' => ' . self::exportVar($val, $recursion - 1);
  440. }
  441. }
  442. }
  443. $n = null;
  444. if (!empty($vars)) {
  445. $n = "\n";
  446. }
  447. return $out . implode(",", $vars) . "{$n})";
  448. break;
  449. case 'resource':
  450. return strtolower(gettype($var));
  451. break;
  452. case 'null':
  453. return 'null';
  454. break;
  455. }
  456. }
  457. /**
  458. * Handles object to string conversion.
  459. *
  460. * @param string $var Object to convert
  461. * @return string
  462. * @see Debugger::exportVar()
  463. */
  464. protected static function _object($var) {
  465. $out = array();
  466. if (is_object($var)) {
  467. $className = get_class($var);
  468. $objectVars = get_object_vars($var);
  469. foreach ($objectVars as $key => $value) {
  470. if (is_object($value)) {
  471. $value = get_class($value) . ' object';
  472. } elseif (is_array($value)) {
  473. $value = 'array';
  474. } elseif ($value === null) {
  475. $value = 'NULL';
  476. } elseif (in_array(gettype($value), array('boolean', 'integer', 'double', 'string', 'array', 'resource'))) {
  477. $value = Debugger::exportVar($value);
  478. }
  479. $out[] = "$className::$$key = " . $value;
  480. }
  481. }
  482. return implode("\n", $out);
  483. }
  484. /**
  485. * Get/Set the output format for Debugger error rendering.
  486. *
  487. * @param string $format The format you want errors to be output as.
  488. * Leave null to get the current format.
  489. * @return mixed Returns null when setting. Returns the current format when getting.
  490. * @throws CakeException when choosing a format that doesn't exist.
  491. */
  492. public static function outputAs($format = null) {
  493. $self = Debugger::getInstance();
  494. if ($format === null) {
  495. return $self->_outputFormat;
  496. }
  497. if ($format !== false && !isset($self->_templates[$format])) {
  498. throw new CakeException('Invalid Debugger output format.');
  499. }
  500. $self->_outputFormat = $format;
  501. }
  502. /**
  503. * Add an output format or update a format in Debugger.
  504. *
  505. * `Debugger::addFormat('custom', $data);`
  506. *
  507. * Where $data is an array of strings that use String::insert() variable
  508. * replacement. The template vars should be in a `{:id}` style.
  509. * An error formatter can have the following keys:
  510. *
  511. * - 'error' - Used for the container for the error message. Gets the following template
  512. * variables: `id`, `error`, `code`, `description`, `path`, `line`, `links`, `info`
  513. * - 'info' - A combination of `code`, `context` and `trace`. Will be set with
  514. * the contents of the other template keys.
  515. * - 'trace' - The container for a stack trace. Gets the following template
  516. * variables: `trace`
  517. * - 'context' - The container element for the context variables.
  518. * Gets the following templates: `id`, `context`
  519. * - 'links' - An array of HTML links that are used for creating links to other resources.
  520. * Typically this is used to create javascript links to open other sections.
  521. * Link keys, are: `code`, `context`, `help`. See the js output format for an
  522. * example.
  523. * - 'traceLine' - Used for creating lines in the stacktrace. Gets the following
  524. * template variables: `reference`, `path`, `line`
  525. *
  526. * Alternatively if you want to use a custom callback to do all the formatting, you can use
  527. * the callback key, and provide a callable:
  528. *
  529. * `Debugger::addFormat('custom', array('callback' => array($foo, 'outputError'));`
  530. *
  531. * The callback can expect two parameters. The first is an array of all
  532. * the error data. The second contains the formatted strings generated using
  533. * the other template strings. Keys like `info`, `links`, `code`, `context` and `trace`
  534. * will be present depending on the other templates in the format type.
  535. *
  536. * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
  537. * straight HTML output, or 'txt' for unformatted text.
  538. * @param array $strings Template strings, or a callback to be used for the output format.
  539. * @return The resulting format string set.
  540. */
  541. public static function addFormat($format, array $strings) {
  542. $self = Debugger::getInstance();
  543. if (isset($self->_templates[$format])) {
  544. if (isset($strings['links'])) {
  545. $self->_templates[$format]['links'] = array_merge(
  546. $self->_templates[$format]['links'],
  547. $strings['links']
  548. );
  549. unset($strings['links']);
  550. }
  551. $self->_templates[$format] = array_merge($self->_templates[$format], $strings);
  552. } else {
  553. $self->_templates[$format] = $strings;
  554. }
  555. return $self->_templates[$format];
  556. }
  557. /**
  558. * Switches output format, updates format strings.
  559. * Can be used to switch the active output format:
  560. *
  561. * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
  562. * straight HTML output, or 'txt' for unformatted text.
  563. * @param array $strings Template strings to be used for the output format.
  564. * @return string
  565. * @deprecated Use Debugger::outputAs() and Debugger::addFormat(). Will be removed
  566. * in 3.0
  567. */
  568. public function output($format = null, $strings = array()) {
  569. $_this = Debugger::getInstance();
  570. $data = null;
  571. if (is_null($format)) {
  572. return Debugger::outputAs();
  573. }
  574. if (!empty($strings)) {
  575. return Debugger::addFormat($format, $strings);
  576. }
  577. if ($format === true && !empty($_this->_data)) {
  578. $data = $_this->_data;
  579. $_this->_data = array();
  580. $format = false;
  581. }
  582. Debugger::outputAs($format);
  583. return $data;
  584. }
  585. /**
  586. * Takes a processed array of data from an error and displays it in the chosen format.
  587. *
  588. * @param string $data
  589. * @return void
  590. */
  591. public function outputError($data) {
  592. $defaults = array(
  593. 'level' => 0,
  594. 'error' => 0,
  595. 'code' => 0,
  596. 'description' => '',
  597. 'file' => '',
  598. 'line' => 0,
  599. 'context' => array(),
  600. 'start' => 2,
  601. );
  602. $data += $defaults;
  603. $files = $this->trace(array('start' => $data['start'], 'format' => 'points'));
  604. $code = '';
  605. if (isset($files[0]['file'])) {
  606. $code = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
  607. }
  608. $trace = $this->trace(array('start' => $data['start'], 'depth' => '20'));
  609. $insertOpts = array('before' => '{:', 'after' => '}');
  610. $context = array();
  611. $links = array();
  612. $info = '';
  613. foreach ((array)$data['context'] as $var => $value) {
  614. $context[] = "\${$var}\t=\t" . $this->exportVar($value, 1);
  615. }
  616. switch ($this->_outputFormat) {
  617. case false:
  618. $this->_data[] = compact('context', 'trace') + $data;
  619. return;
  620. case 'log':
  621. $this->log(compact('context', 'trace') + $data);
  622. return;
  623. }
  624. $data['trace'] = $trace;
  625. $data['id'] = 'cakeErr' . uniqid();
  626. $tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]);
  627. $insert = array('context' => join("\n", $context)) + $data;
  628. $detect = array('context');
  629. if (isset($tpl['links'])) {
  630. foreach ($tpl['links'] as $key => $val) {
  631. if (in_array($key, $detect) && empty($insert[$key])) {
  632. continue;
  633. }
  634. $links[$key] = String::insert($val, $insert, $insertOpts);
  635. }
  636. }
  637. foreach (array('code', 'context', 'trace') as $key) {
  638. if (empty($$key) || !isset($tpl[$key])) {
  639. continue;
  640. }
  641. if (is_array($$key)) {
  642. $$key = join("\n", $$key);
  643. }
  644. $info .= String::insert($tpl[$key], compact($key) + $insert, $insertOpts);
  645. }
  646. $links = join(' ', $links);
  647. unset($data['context']);
  648. if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
  649. return call_user_func($tpl['callback'], $data, compact('links', 'info'));
  650. }
  651. echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
  652. }
  653. /**
  654. * Verifies that the application's salt and cipher seed value has been changed from the default value.
  655. *
  656. * @return void
  657. */
  658. public static function checkSecurityKeys() {
  659. if (Configure::read('Security.salt') == 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') {
  660. trigger_error('Please change the value of \'Security.salt\' in app/Config/core.php to a salt value specific to your application', E_USER_NOTICE);
  661. }
  662. if (Configure::read('Security.cipherSeed') === '76859309657453542496749683645') {
  663. trigger_error('Please change the value of \'Security.cipherSeed\' in app/Config/core.php to a numeric (digits only) seed value specific to your application', E_USER_NOTICE);
  664. }
  665. }
  666. }