Hoa central
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Hoa\Core\Exception\Idle Class Reference
Inheritance diagram for Hoa\Core\Exception\Idle:

Public Member Functions

 __construct ($message, $code=0, $arguments=[],\Exception $previous=null)
 
 getBacktrace ()
 
 getPreviousThrow ()
 
 getArguments ()
 
 getRawMessage ()
 
 getFormattedMessage ()
 
 getFrom ()
 
 raise ($previous=false)
 
 __toString ()
 

Static Public Member Functions

static uncaught ($exception)
 
static error ($errno, $errstr, $errfile, $errline)
 

Protected Attributes

 $_tmpArguments = null
 
 $_arguments = null
 
 $_trace = null
 
 $_previous = null
 
 $_rawMessage = null
 

Detailed Description

Class .

is the mother exception class of libraries. The only difference between and its directly child is that the later fires event after beeing constructed.

Definition at line 51 of file Exception.php.

Constructor & Destructor Documentation

Hoa\Core\Exception\Idle::__construct (   $message,
  $code = 0,
  $arguments = [],
\Exception  $previous = null 
)

Create an exception. An exception is built with a formatted message, a code (an ID), and an array that contains the list of formatted string for the message. If chaining, we can add a previous exception.

Parameters
string$messageFormatted message.
int$codeCode (the ID).
array$argumentsArguments to format message.
\Exception$previousPrevious exception in chaining.
Returns
void

Definition at line 102 of file Exception.php.

107  {
108  $this->_tmpArguments = $arguments;
109  parent::__construct($message, $code, $previous);
110  $this->_rawMessage = $message;
111  $this->message = @vsprintf($message, $this->getArguments());
112 
113  return;
114  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Core\Exception\Idle::__toString ( )

String representation of object.

Returns
string

Definition at line 319 of file Exception.php.

320  {
321  return $this->raise();
322  }
static Hoa\Core\Exception\Idle::error (   $errno,
  $errstr,
  $errfile,
  $errline 
)
static

Catch PHP (and PHP_USER) errors and transform them into . Obviously, if code that caused the error is preceeded by @, then we do not thrown any exception.

Parameters
int$errnoLevel.
string$errstrMessage.
string$errfileFile.
int$errlineLine.
Returns
void
Exceptions

Definition at line 301 of file Exception.php.

302  {
303  if (0 === ($errno & error_reporting())) {
304  return;
305  }
306 
307  $trace = debug_backtrace();
308  array_shift($trace);
309  array_shift($trace);
310 
311  throw new Error($errstr, $errno, $errfile, $errline, $trace);
312  }

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getArguments ( )

Get arguments for the message.

Returns
array

Definition at line 151 of file Exception.php.

152  {
153  if (null === $this->_arguments) {
154  $arguments = $this->_tmpArguments;
155 
156  if (!is_array($arguments)) {
157  $arguments = [$arguments];
158  }
159 
160  foreach ($arguments as $key => &$value) {
161  if (null === $value) {
162  $value = '(null)';
163  }
164  }
165 
166  $this->_arguments = $arguments;
167  unset($this->_tmpArguments);
168  }
169 
170  return $this->_arguments;
171  }

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getBacktrace ( )

Get the backtrace. Do not use ::getTrace() any more.

Returns
array

Definition at line 122 of file Exception.php.

123  {
124  if (null === $this->_trace) {
125  $this->_trace = $this->getTrace();
126  }
127 
128  return $this->_trace;
129  }

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getFormattedMessage ( )

Get the message already formatted.

Returns
string

Definition at line 188 of file Exception.php.

189  {
190  return $this->getMessage();
191  }

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getFrom ( )

Get the source of the exception (class, method, function, main etc.).

Returns
string

Definition at line 198 of file Exception.php.

199  {
200  $trace = $this->getBacktrace();
201  $from = '{main}';
202 
203  if (!empty($trace)) {
204  $t = $trace[0];
205  $from = '';
206 
207  if (isset($t['class'])) {
208  $from .= $t['class'] . '::';
209  }
210 
211  if (isset($t['function'])) {
212  $from .= $t['function'] . '()';
213  }
214  }
215 
216  return $from;
217  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getPreviousThrow ( )

Get previous. Do not use ::getPrevious() any more.

Returns

Definition at line 137 of file Exception.php.

138  {
139  if (null === $this->_previous) {
140  $this->_previous = $this->getPrevious();
141  }
142 
143  return $this->_previous;
144  }

Here is the caller graph for this function:

Hoa\Core\Exception\Idle::getRawMessage ( )

Get the raw message.

Returns
string

Definition at line 178 of file Exception.php.

179  {
180  return $this->_rawMessage;
181  }
Hoa\Core\Exception\Idle::raise (   $previous = false)

Raise an exception as a string.

Parameters
bool$previousWhether raise previous exception if exists.
Returns
string

Definition at line 225 of file Exception.php.

226  {
227  $message = $this->getFormattedMessage();
228  $trace = $this->getBacktrace();
229  $file = '/dev/null';
230  $line = -1;
231  $pre = $this->getFrom();
232 
233  if (!empty($trace)) {
234  $file = isset($trace['file']) ? $trace['file'] : null;
235  $line = isset($trace['line']) ? $trace['line'] : null;
236  }
237 
238  $pre .= ': ';
239 
240  try {
241  $out =
242  $pre . '(' . $this->getCode() . ') ' . $message . "\n" .
243  'in ' . $this->getFile() . ' at line ' .
244  $this->getLine() . '.';
245  } catch (\Exception $e) {
246  $out =
247  $pre . '(' . $this->getCode() . ') ' . $message . "\n" .
248  'in ' . $file . ' around line ' . $line . '.';
249  }
250 
251  if (true === $previous &&
252  null !== $previous = $this->getPreviousThrow()) {
253  $out .=
254  "\n\n" . ' ⬇ ' . "\n\n" .
255  'Nested exception (' . get_class($previous) . '):' . "\n" .
256  ($previous instanceof self
257  ? $previous->raise(true)
258  : $previous->getMessage());
259  }
260 
261  return $out;
262  }

Here is the call graph for this function:

static Hoa\Core\Exception\Idle::uncaught (   $exception)
static

Catch uncaught exception (only and children).

Parameters
\BaseException$exceptionThe exception.
Returns
void
Exceptions

Definition at line 271 of file Exception.php.

272  {
273  if (!($exception instanceof self)) {
274  throw $exception;
275  }
276 
277  while (0 < ob_get_level()) {
278  ob_end_flush();
279  }
280 
281  echo
282  'Uncaught exception (' . get_class($exception) . '):' . "\n" .
283  $exception->raise(true);
284 
285  return;
286  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Core\Exception\Idle::$_arguments = null
protected

Definition at line 65 of file Exception.php.

Hoa\Core\Exception\Idle::$_previous = null
protected

Definition at line 79 of file Exception.php.

Hoa\Core\Exception\Idle::$_rawMessage = null
protected

Definition at line 86 of file Exception.php.

Hoa\Core\Exception\Idle::$_tmpArguments = null
protected

Definition at line 58 of file Exception.php.

Hoa\Core\Exception\Idle::$_trace = null
protected

Definition at line 72 of file Exception.php.


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