Esempio n. 1
0
 /**
  * Init's a new instance.
  *
  * @param string     $arg      The argument/parameter name
  * @param mixed      $value    The argument/parameter value
  * @param string     $package  The optional Beluga package name
  * @param string     $message  The error message (default=null)
  * @param int        $code     The error code (default=\E_USER_ERROR)
  * @param \Throwable $previous A optional previous exception
  */
 public function __construct(string $arg, $value, string $package, string $message = null, $code = \E_USER_ERROR, \Throwable $previous = null)
 {
     // Getting the debug backtrace to find out the method/function that is called with an bad argument.
     $trace = \debug_backtrace();
     // Getting the index of the last trace element.
     $lIdx = \count($trace) - 1;
     // Getting the method or function name.
     $fn = (empty($trace[$lIdx]['class']) ? '' : $trace[$lIdx]['class']) . (empty($trace[$lIdx]['type']) ? '' : $trace[$lIdx]['type']) . (empty($trace[$lIdx]['function']) ? '' : $trace[$lIdx]['function']);
     // Init with parent constructor
     parent::__construct($package, 'Argument $' . \ltrim($arg, '$') . (empty($fn) ? '' : ' of ' . $fn . '(…)') . ' is Invalid! It uses a value of type ' . static::GetTypeStr($value) . static::appendMessage($message), $code, $previous);
     // Remember the parameter name and the function/method name
     $this->argumentName = $arg;
     $this->functionName = $fn;
 }
 /**
  * Init's a new instance.
  *
  * @param string     $extensionName  The name of the missing extension
  * @param string     $package        The optional Beluga package name
  * @param string     $message        The error message (default=null)
  * @param mixed      $code           The error code (default=\E_USER_ERROR)
  * @param \Throwable $previous       A optional previous exception
  */
 public function __construct(string $extensionName, string $package, string $message = null, $code = 0, \Throwable $previous = null)
 {
     parent::__construct($package, \sprintf('PHP extension "%s" is not loaded with current PHP config.', $extensionName) . static::appendMessage($message), $code, $previous);
     $this->extensionName = $extensionName;
 }