Browse Source

Unified arguments of dd() and debug()

Koji Tanaka 9 years ago
parent
commit
5ca71bce17
1 changed files with 11 additions and 7 deletions
  1. 11 7
      src/basics.php

+ 11 - 7
src/basics.php

@@ -121,22 +121,26 @@ if (!function_exists('dd')) {
      *
      * @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
      */
-    function dd($var, $showHtml = null)
+    function dd($var, $showHtml = null, $showFrom = true)
     {
         if (!Configure::read('debug')) {
             return;
         }
 
-        $trace = Debugger::trace(['start' => 1, 'depth' => 2, 'format' => 'array']);
-        $location = [
-            'line' => $trace[0]['line'],
-            'file' => $trace[0]['file']
-        ];
+        $location = [];
+        if ($showFrom) {
+            $trace = Debugger::trace(['start' => 1, 'depth' => 2, 'format' => 'array']);
+            $location = [
+                'line' => $trace[0]['line'],
+                'file' => $trace[0]['file']
+            ];
+        }
 
-        Debugger::printVar($var, $location);
+        Debugger::printVar($var, $location, $showHtml);
         die(1);
     }
 }