/** * Takes a processed array of data from an error and displays it in the chosen format. * * @param string $data Data to output. * @return void */ public function outputError($data) { $defaults = ['level' => 0, 'error' => 0, 'code' => 0, 'description' => '', 'file' => '', 'line' => 0, 'context' => [], 'start' => 2]; $data += $defaults; $files = $this->trace(['start' => $data['start'], 'format' => 'points']); $code = ''; $file = null; if (isset($files[0]['file'])) { $file = $files[0]; } elseif (isset($files[1]['file'])) { $file = $files[1]; } if ($file) { $code = $this->excerpt($file['file'], $file['line'] - 1, 1); } $trace = $this->trace(['start' => $data['start'], 'depth' => '20']); $insertOpts = ['before' => '{:', 'after' => '}']; $context = []; $links = []; $info = ''; foreach ((array) $data['context'] as $var => $value) { $context[] = "\${$var} = " . $this->exportVar($value, 3); } switch ($this->_outputFormat) { case false: $this->_data[] = compact('context', 'trace') + $data; return; case 'log': $this->log(compact('context', 'trace') + $data); return; } $data['trace'] = $trace; $data['id'] = 'cakeErr' . uniqid(); $tpl = $this->_templates[$this->_outputFormat] + $this->_templates['base']; if (isset($tpl['links'])) { foreach ($tpl['links'] as $key => $val) { $links[$key] = Text::insert($val, $data, $insertOpts); } } if (!empty($tpl['escapeContext'])) { $context = h($context); } $infoData = compact('code', 'context', 'trace'); foreach ($infoData as $key => $value) { if (empty($value) || !isset($tpl[$key])) { continue; } if (is_array($value)) { $value = implode("\n", $value); } $info .= Text::insert($tpl[$key], [$key => $value] + $data, $insertOpts); } $links = implode(' ', $links); if (isset($tpl['callback']) && is_callable($tpl['callback'])) { return call_user_func($tpl['callback'], $data, compact('links', 'info')); } echo Text::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts); }
public function testReplaceWithQuestionMarkInString() { $string = new Text(':a, :b and :c?'); $expected = ':a, 2 and 3?'; $result = $string->insert(['b' => 2, 'c' => 3]); $this->assertEquals($expected, $result); }