-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHelpers.php
More file actions
98 lines (78 loc) · 2.27 KB
/
Copy pathHelpers.php
File metadata and controls
98 lines (78 loc) · 2.27 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Rareloop\Lumberjack;
use Exception;
use Rareloop\Lumberjack\Exceptions\HandlerInterface;
use Rareloop\Lumberjack\Facades\Config;
use Rareloop\Lumberjack\Facades\Router;
use Rareloop\Lumberjack\Http\Responses\RedirectResponse;
use Rareloop\Lumberjack\Http\Responses\TimberResponse;
use Rareloop\Lumberjack\Facades\Session;
use Rareloop\Lumberjack\Facades\Log;
class Helpers
{
public static function app($key = null)
{
$app = $GLOBALS['__app__'];
if ($key === null) {
return $app;
}
return $app->get($key);
}
public static function config($key, $default = null)
{
if (is_array($key)) {
$keyValues = $key;
foreach ($keyValues as $key => $value) {
Config::set($key, $value);
}
return;
}
return Config::get($key, $default);
}
public static function view($template, $context = [], $statusCode = 200, $headers = [])
{
return static::app()->make(TimberResponse::class, [
'twigTemplate' => $template,
'context' => $context,
'status' => $statusCode,
'headers' => $headers,
]);
}
public static function route($name, $params = [])
{
return Router::url($name, $params);
}
public static function redirect($url, $statusCode = 302, $headers = [])
{
return new RedirectResponse($url, $statusCode, $headers);
}
public static function report(Exception $e)
{
return static::app(HandlerInterface::class)->report($e);
}
public static function request()
{
return static::app('request');
}
public static function session($key = null, $default = null)
{
if (is_null($key)) {
return static::app('session');
}
if (is_array($key)) {
return Session::put($key);
}
return Session::get($key, $default);
}
public static function back()
{
return static::redirect(static::session()->previousUrl());
}
public static function logger($message = null, $context = [])
{
if (is_null($message)) {
return static::app('logger');
}
return Log::debug($message, $context);
}
}