当前位置: 首页>>代码示例>>PHP>>正文


PHP Debugger::exportVar方法代码示例

本文整理汇总了PHP中Cake\Error\Debugger::exportVar方法的典型用法代码示例。如果您正苦于以下问题:PHP Debugger::exportVar方法的具体用法?PHP Debugger::exportVar怎么用?PHP Debugger::exportVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Error\Debugger的用法示例。


在下文中一共展示了Debugger::exportVar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: debug

    /**
     * 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|null $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/3.0/en/development/debugging.html#basic-debugging
     * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#debug
     */
    function debug($var, $showHtml = null, $showFrom = true)
    {
        if (!Configure::read('debug')) {
            return;
        }
        $file = '';
        $line = '';
        $lineInfo = '';
        if ($showFrom) {
            $trace = Debugger::trace(['start' => 1, 'depth' => 2, 'format' => 'array']);
            $search = [];
            if (defined('ROOT')) {
                $search = [ROOT];
            }
            if (defined('CAKE_CORE_INCLUDE_PATH')) {
                array_unshift($search, CAKE_CORE_INCLUDE_PATH);
            }
            $file = str_replace($search, '', $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 === 'cli' || PHP_SAPI === 'phpdbg' || $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);
    }
开发者ID:rlugojr,项目名称:cakephp,代码行数:67,代码来源:basics.php

示例2: formatTrace

 /**
  * Formats a stack trace based on the supplied options.
  *
  * ### Options
  *
  * - `depth` - The number of stack frames to return. Defaults to 999
  * - `format` - The format you want the return. Defaults to the currently selected format. If
  *    format is 'array' or 'points' the return will be an array.
  * - `args` - Should arguments for functions be shown?  If true, the arguments for each method call
  *   will be displayed.
  * - `start` - The stack frame to start generating a trace from. Defaults to 0
  *
  * @param array|\Exception $backtrace Trace as array or an exception object.
  * @param array $options Format for outputting stack trace.
  * @return mixed Formatted stack trace.
  * @link http://book.cakephp.org/3.0/en/development/debugging.html#generating-stack-traces
  */
 public static function formatTrace($backtrace, $options = [])
 {
     if ($backtrace instanceof Exception) {
         $backtrace = $backtrace->getTrace();
     }
     $self = Debugger::getInstance();
     $defaults = ['depth' => 999, 'format' => $self->_outputFormat, 'args' => false, 'start' => 0, 'scope' => null, 'exclude' => ['call_user_func_array', 'trigger_error']];
     $options = Hash::merge($defaults, $options);
     $count = count($backtrace);
     $back = [];
     $_trace = ['line' => '??', 'file' => '[internal]', 'class' => null, 'function' => '[main]'];
     for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
         $trace = $backtrace[$i] + ['file' => '[internal]', 'line' => '??'];
         $signature = $reference = '[main]';
         if (isset($backtrace[$i + 1])) {
             $next = $backtrace[$i + 1] + $_trace;
             $signature = $reference = $next['function'];
             if (!empty($next['class'])) {
                 $signature = $next['class'] . '::' . $next['function'];
                 $reference = $signature . '(';
                 if ($options['args'] && isset($next['args'])) {
                     $args = [];
                     foreach ($next['args'] as $arg) {
                         $args[] = Debugger::exportVar($arg);
                     }
                     $reference .= implode(', ', $args);
                 }
                 $reference .= ')';
             }
         }
         if (in_array($signature, $options['exclude'])) {
             continue;
         }
         if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
             $back[] = ['file' => $trace['file'], 'line' => $trace['line']];
         } elseif ($options['format'] === 'array') {
             $back[] = $trace;
         } else {
             if (isset($self->_templates[$options['format']]['traceLine'])) {
                 $tpl = $self->_templates[$options['format']]['traceLine'];
             } else {
                 $tpl = $self->_templates['base']['traceLine'];
             }
             $trace['path'] = static::trimPath($trace['file']);
             $trace['reference'] = $reference;
             unset($trace['object'], $trace['args']);
             $back[] = Text::insert($tpl, $trace, ['before' => '{:', 'after' => '}']);
         }
     }
     if ($options['format'] === 'array' || $options['format'] === 'points') {
         return $back;
     }
     return implode("\n", $back);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:71,代码来源:Debugger.php

示例3: testDebugInfo

    /**
     * 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\\Error\\DebuggableThing) {

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

}
eos;
        $this->assertEquals($expected, $result);
    }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:19,代码来源:DebuggerTest.php

示例4: debug

    /**
     * Prints out debug information about given variable.
     *
     * Only runs if debug level is greater than zero.
     *
     * @param boolean $var Variable to show debug information for.
     * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way.
     * @param boolean $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
     */
    public static function debug($var, $showHtml = null, $showFrom = true)
    {
        if (Configure::read('debug') > 0) {
            //			App::uses('Debugger', 'Utility');
            $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">

<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 = htmlspecialchars($var);
                if ($showFrom) {
                    $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
                }
            }
            printf($template, $var);
        }
    }
开发者ID:OrigamiStructures,项目名称:foldingTime,代码行数:59,代码来源:dmDebug.php


注:本文中的Cake\Error\Debugger::exportVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。