Ouzo\ExceptionHandling\Error::forException PHP Method

forException() public static method

public static forException ( Exception $exception )
$exception Exception
    public static function forException(Exception $exception)
    {
        if (Config::getValue('debug')) {
            return new Error($exception->getCode(), self::_classNameAndMessage($exception));
        }
        if ($exception instanceof UserException) {
            return new Error($exception->getCode(), $exception->getMessage());
        }
        return new Error($exception->getCode(), I18n::t('exception.unknown'), $exception->getMessage());
    }

Usage Example

Esempio n. 1
0
 /**
  * @test
  */
 public function shouldGetErrorWithClassForDebug()
 {
     //given
     Config::overrideProperty('debug')->with(true);
     $userException = new UserException('Winter is coming!');
     //when
     $error = Error::forException($userException);
     //then
     $this->assertEquals('Ouzo\\UserException: Winter is coming!', $error->message);
 }
All Usage Examples Of Ouzo\ExceptionHandling\Error::forException