-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
99 lines (86 loc) · 2.16 KB
/
helpers.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
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
99
<?php
use Radiate\Foundation\Application;
use Radiate\Http\ResponseFactory;
use Radiate\View\Factory as ViewFactory;
if (!function_exists('app')) {
/**
* Get the available container instance.
*
* @param string|null $abstract
* @param array $parameters
* @return mixed|\Radiate\Foundation\Application
*/
function app(?string $abstract = null, array $parameters = [])
{
if (is_null($abstract)) {
return Application::getInstance();
}
return Application::getInstance()->make($abstract, $parameters);
}
}
if (!function_exists('base_path')) {
/**
* Get a path from the app base path
*
* @param string $path
* @return string
*/
function base_path(?string $path = null)
{
return app()->basePath($path);
}
}
if (!function_exists('env')) {
/**
* Get an "environment" variable with getenv or constant
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env(string $key, $default = null)
{
if ($env = getenv($key)) {
return $env;
}
if (defined($key)) {
return constant($key);
}
return $default;
}
}
if (!function_exists('response')) {
/**
* Create a HTTP response
*
* @param mixed $content
* @param integer $status
* @param array $headers
* @return \Radiate\Http\ResponseFactory|\Radiate\Http\Response
*/
function response($content = '', int $status = 200, array $headers = [])
{
$factory = app(ResponseFactory::class);
if (func_num_args() === 0) {
return $factory;
}
return $factory->make($content, $status, $headers);
}
}
if (!function_exists('view')) {
/**
* Create a view
*
* @param string|null $view
* @param array $data
* @return \Radiate\View\Factory|\Radiate\View\View
*/
function view(?string $view = null, array $data = [])
{
$factory = app(ViewFactory::class);
if (func_num_args() === 0) {
return $factory;
}
return $factory->make($view, $data);
}
}