-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.php
57 lines (45 loc) · 1.91 KB
/
Utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace SlimMvcTools;
use \Throwable;
/**
* Description of Utils
*
* @author rotex
*/
class Utils {
public static function getThrowableAsStr(Throwable $e, string $eol=PHP_EOL): string {
$previous_throwable = $e;
$message = '';
do {
$message .= "Exception / Error Code: {$previous_throwable->getCode()}"
. $eol . "Exception / Error Class: " . $previous_throwable::class
. $eol . "File: {$previous_throwable->getFile()}"
. $eol . "Line: {$previous_throwable->getLine()}"
. $eol . "Message: {$previous_throwable->getMessage()}" . $eol
. $eol . "Trace: {$eol}{$previous_throwable->getTraceAsString()}{$eol}{$eol}";
$previous_throwable = $previous_throwable->getPrevious();
} while( $previous_throwable instanceof Throwable );
return $message;
}
public static function createSlimHttpExceptionWithLocalizedDescription(
\Psr\Container\ContainerInterface $container,
SlimHttpExceptionClassNames $exception_class,
\Psr\Http\Message\RequestInterface $req,
string $err_message,
?\Throwable $previous_exception = null
): \Slim\Exception\HttpSpecializedException {
$exception_class_name = $exception_class->value;
$exception = new $exception_class_name($req, $err_message, $previous_exception);
if(
$container->has(ContainerKeys::LOCALE_OBJ)
&& $container->get(ContainerKeys::LOCALE_OBJ) instanceof \Vespula\Locale\Locale
) {
$exception->setDescription(
$container->get(ContainerKeys::LOCALE_OBJ)
->gettext($exception_class->value.'_description')
);
}
return $exception;
}
}