Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Static Protected Attributes
Debug Class Reference

Static Public Member Functions

static getRootPath ()
 
static backtrace ($return=false, $html=true, $withArgs=true)
 
static trace (array $trace, $return=false, $html=true, $withArgs=true)
 

Static Public Attributes

static $argLength = 16
 

Static Protected Member Functions

static _formatCalledArgument ($arg)
 

Static Protected Attributes

static $_filePath
 

Detailed Description

Magento Debug methods

Definition at line 11 of file Debug.php.

Member Function Documentation

◆ _formatCalledArgument()

static _formatCalledArgument (   $arg)
staticprotected

Format argument in called method

Parameters
mixed$arg
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 148 of file Debug.php.

149  {
150  $out = '';
151  if (is_object($arg)) {
152  $out .= sprintf("&%s#%s#", get_class($arg), spl_object_hash($arg));
153  } elseif (is_resource($arg)) {
154  $out .= '#[' . get_resource_type($arg) . ']';
155  } elseif (is_array($arg)) {
156  $isAssociative = false;
157  $args = [];
158  foreach ($arg as $k => $v) {
159  if (!is_numeric($k)) {
160  $isAssociative = true;
161  }
162  $args[$k] = self::_formatCalledArgument($v);
163  }
164  if ($isAssociative) {
165  $arr = [];
166  foreach ($args as $k => $v) {
167  $arr[] = self::_formatCalledArgument($k) . ' => ' . $v;
168  }
169  $out .= 'array(' . join(', ', $arr) . ')';
170  } else {
171  $out .= 'array(' . join(', ', $args) . ')';
172  }
173  } elseif ($arg === null) {
174  $out .= 'NULL';
175  } elseif (is_numeric($arg) || is_float($arg)) {
176  $out .= $arg;
177  } elseif (is_string($arg)) {
178  if (strlen($arg) > self::$argLength) {
179  $arg = substr($arg, 0, self::$argLength) . "...";
180  }
181  $arg = strtr($arg, ["\t" => '\t', "\r" => '\r', "\n" => '\n', "'" => '\\\'']);
182  $out .= "'" . $arg . "'";
183  } elseif (is_bool($arg)) {
184  $out .= $arg === true ? 'true' : 'false';
185  }
186 
187  return $out;
188  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static _formatCalledArgument($arg)
Definition: Debug.php:148

◆ backtrace()

static backtrace (   $return = false,
  $html = true,
  $withArgs = true 
)
static

Prints or returns a backtrace

Parameters
bool$returnreturn or print
bool$htmloutput in HTML format
bool$withArgsadd short arguments of methods
Returns
string|bool

Definition at line 50 of file Debug.php.

51  {
52  $trace = debug_backtrace();
53  return self::trace($trace, $return, $html, $withArgs);
54  }
static trace(array $trace, $return=false, $html=true, $withArgs=true)
Definition: Debug.php:67

◆ getRootPath()

static getRootPath ( )
static

Retrieve real root path with last directory separator

Returns
string

Definition at line 30 of file Debug.php.

31  {
32  if (self::$_filePath === null) {
33  if (defined('BP')) {
34  self::$_filePath = BP;
35  } else {
36  self::$_filePath = dirname(__DIR__);
37  }
38  }
39  return self::$_filePath;
40  }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
const BP
Definition: autoload.php:14

◆ trace()

static trace ( array  $trace,
  $return = false,
  $html = true,
  $withArgs = true 
)
static

Prints or return a trace

Parameters
array$tracetrace array
bool$returnreturn or print
bool$htmloutput in HTML format
bool$withArgsadd short arguments of methods
Returns
string|bool @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 67 of file Debug.php.

68  {
69  $out = '';
70  if ($html) {
71  $out .= '<pre>';
72  }
73 
74  foreach ($trace as $i => $data) {
75  // skip self
76  if ($i == 0) {
77  continue;
78  }
79 
80  // prepare method arguments
81  $args = [];
82  if (isset($data['args']) && $withArgs) {
83  foreach ($data['args'] as $arg) {
84  $args[] = self::_formatCalledArgument($arg);
85  }
86  }
87 
88  // prepare method's name
89  if (isset($data['class']) && isset($data['function'])) {
90  if (isset($data['object']) && get_class($data['object']) != $data['class']) {
91  $className = get_class($data['object']) . '[' . $data['class'] . ']';
92  } else {
93  $className = $data['class'];
94  }
95  if (isset($data['object'])) {
96  $className .= sprintf('#%s#', spl_object_hash($data['object']));
97  }
98 
99  $methodName = sprintf(
100  '%s%s%s(%s)',
101  $className,
102  isset($data['type']) ? $data['type'] : '->',
103  $data['function'],
104  join(', ', $args)
105  );
106  } elseif (isset($data['function'])) {
107  $methodName = sprintf('%s(%s)', $data['function'], join(', ', $args));
108  }
109 
110  if (isset($data['file'])) {
111  $pos = strpos($data['file'], self::getRootPath());
112  if ($pos !== false) {
113  $data['file'] = substr($data['file'], strlen(self::getRootPath()) + 1);
114  }
115  $fileName = sprintf('%s:%d', $data['file'], $data['line']);
116  } else {
117  $fileName = false;
118  }
119 
120  if ($fileName) {
121  $out .= sprintf('#%d %s called at [%s]', $i, $methodName, $fileName);
122  } else {
123  $out .= sprintf('#%d %s', $i, $methodName);
124  }
125 
126  $out .= "\n";
127  }
128 
129  if ($html) {
130  $out .= '</pre>';
131  }
132 
133  if ($return) {
134  return $out;
135  } else {
136  echo $out;
137  return true;
138  }
139  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$fileName
Definition: translate.phtml:15
$pos
Definition: list.phtml:42
static _formatCalledArgument($arg)
Definition: Debug.php:148
$i
Definition: gallery.phtml:31
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

Field Documentation

◆ $_filePath

$_filePath
staticprotected

Definition at line 23 of file Debug.php.

◆ $argLength

$argLength = 16
static

Definition at line 16 of file Debug.php.


The documentation for this class was generated from the following file: