PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/Utility/Debugger.php

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