-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.php
118 lines (101 loc) · 1.91 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
use Core\Actions\methodRoute;
use function PHPUnit\Framework\returnSelf;
/**
* config('app.name')
*
*
* count();
* if > 2;
* 3
* $array[][]
*
* @param string $value
*
* @return string
*/
function config(string $value)
{
$array = explode('.', $value);
$dir = __DIR__ . '/config/' . $array[0] . '.php';
$ars = '';
// foreach ($array as $ar)
// {
// $ars .= "[$ar]";
// }
if (file_exists($dir))
{
$files = include __DIR__ . '/config/' . $array[0] . '.php';
return $files[$array[1]];
}
return null;
}
function kernel(string $arg, string $key)
{
$classes = require __DIR__ . '/app/Kernel.php';
return new $classes[$arg][$key];
}
/**
* functions for routing
*/
/**
* getting view with .php or not
* the directory views in /Views
*
* @param string $view
*
* @return string directory for file
*/
function asset(string $view)
{
$direView = __DIR__ . '/Views/';
if (strrpos($view, '.php')) {
return $direView . $view;
}
return $direView . $view . '.php';
}
/**
* view html in view
* using asset() method
*
* @param string $dir
*
* @return include file
*/
function view($dir, $data = null)
{
if (file_exists(asset($dir)))
return require asset($dir);
http_response_code(404);
return require __DIR__ . '/Views/errors/404.php';
}
function passedUri($url)
{
if (strpos($url, '?'))
{
$url = explode('?', $url);
$get = explode('=', $url[1]);
return ['url' => $url[0], 'get' => $get];
}
return $url;
}
function route(string $name)
{
return new methodRoute;
}
function session($key)
{
if (isset($_SESSION[$key])) {
$errors = $_SESSION[$key];
$_SESSION[$key] = null;
return $errors;
} else
return;
}
function is_true($value)
{
if ($value == TRUE)
return true;
else
return false;
}