Example #1
0
 /**
  * Switches output format, updates format strings.
  * Can be used to switch the active output format:
  *
  * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
  *    straight HTML output, or 'txt' for unformatted text.
  * @param array $strings Template strings to be used for the output format.
  * @return string
  * @deprecated Use Debugger::outputAs() and Debugger::addFormat(). Will be removed
  *   in 3.0
  */
 public function output($format = null, array $strings = array())
 {
     $self = Debugger::getInstance();
     $data = null;
     if ($format === null) {
         return Debugger::outputAs();
     }
     if (!empty($strings)) {
         return Debugger::addFormat($format, $strings);
     }
     if ($format === true && !empty($self->_data)) {
         $data = $self->_data;
         $self->_data = array();
         $format = false;
     }
     Debugger::outputAs($format);
     return $data;
 }
Example #2
0
 /**
  * Display an error.
  *
  * Template method of BaseErrorHandler.
  *
  * Only when debug > 2 will a formatted error be displayed.
  *
  * @param array $error An array of error data.
  * @param bool $debug Whether or not the app is in debug mode.
  * @return void
  */
 protected function _displayError($error, $debug)
 {
     if (!$debug) {
         return;
     }
     Debugger::getInstance()->outputError($error);
 }
Example #3
0
    /**
     * Prints out debug information about given variable.
     *
     * Only runs if debug level is greater than zero.
     *
     * @param mixed $var Variable to show debug information for.
     * @param bool $showHtml If set to true, the method prints the debug data in a browser-friendly way.
     * @param bool $showFrom If set to true, the method prints from where the function was called.
     * @return void
     * @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
     * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
     */
    function debug($var, $showHtml = null, $showFrom = true)
    {
        if (Configure::read('debug')) {
            $file = '';
            $line = '';
            $lineInfo = '';
            if ($showFrom) {
                $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
                $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
                $line = $trace[0]['line'];
            }
            $html = <<<HTML
<div class="cake-debug-output">
%s
<pre class="cake-debug">
%s
</pre>
</div>
HTML;
            $text = <<<TEXT
%s
########## DEBUG ##########
%s
###########################

TEXT;
            $template = $html;
            if (php_sapi_name() === 'cli' || $showHtml === false) {
                $template = $text;
                if ($showFrom) {
                    $lineInfo = sprintf('%s (line %s)', $file, $line);
                }
            }
            if ($showHtml === null && $template !== $text) {
                $showHtml = true;
            }
            $var = Debugger::exportVar($var, 25);
            if ($showHtml) {
                $template = $html;
                $var = h($var);
                if ($showFrom) {
                    $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
                }
            }
            printf($template, $lineInfo, $var);
        }
    }
 /**
  * Log an error.
  *
  * @param string $level The level name of the log.
  * @param array $data Array of error data.
  * @return void
  */
 protected function _logError($level, $data)
 {
     $message = sprintf('%s (%s): %s in [%s, line %s]', $data['error'], $data['code'], $data['description'], $data['file'], $data['line']);
     if (!empty($this->_options['trace'])) {
         $trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
         $message .= "\nTrace:\n" . $trace . "\n";
     }
     return Log::write($level, $message);
 }
Example #5
0
    /**
     * Tests that __debugInfo is used when available
     *
     * @return void
     */
    public function testDebugInfo()
    {
        $object = new DebuggableThing();
        $result = Debugger::exportVar($object, 2);
        $expected = <<<eos
object(Cake\\Test\\TestCase\\Utility\\DebuggableThing) {

\t'foo' => 'bar',
\t'inner' => object(Cake\\Test\\TestCase\\Utility\\DebuggableThing) {

\t\t[maximum depth reached]
\t
\t}

}
eos;
        $this->assertEquals($expected, $result);
    }
 /**
  * Initializes AuthComponent for use in the controller.
  *
  * @param Event $event The initialize event.
  * @return void
  */
 public function initialize(Event $event)
 {
     $controller = $event->subject();
     $this->request = $controller->request;
     $this->response = $controller->response;
     $this->_methods = $controller->methods;
     if (Configure::read('debug')) {
         Debugger::checkSecurityKeys();
     }
 }