Passed
Pull Request — master (#75)
by Arman
03:36
created

route_args()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.8.0
13
 */
14
use Quantum\Router\RouteController;
15
16
/**
17
 * Gets current middlewares
18
 * @return array|null
19
 */
20
function current_middlewares(): ?array
21
{
22
    return RouteController::getCurrentRoute()['middlewares'] ?? null;
23
}
24
25
/**
26
 * Gets current module
27
 * @return string|null
28
 */
29
function current_module(): ?string
30
{
31
    return RouteController::getCurrentRoute()['module'] ?? null;
32
}
33
34
/**
35
 * Get current controller
36
 * @return string|null
37
 */
38
function current_controller(): ?string
39
{
40
    return RouteController::getCurrentRoute()['controller'] ?? null;
41
}
42
43
/**
44
 * Gets current action
45
 * @return string|null
46
 */
47
function current_action(): ?string
48
{
49
    return RouteController::getCurrentRoute()['action'] ?? null;
50
}
51
52
/**
53
 * Get current callback
54
 * @return \Closure $callback|null
55
 */
56
function route_callback(): ?Closure
57
{
58
    return RouteController::getCurrentRoute()['callback'] ?? null;
59
}
60
61
/**
62
 * Gets current route
63
 * @return string|null
64
 */
65
function current_route(): ?string
66
{
67
    return RouteController::getCurrentRoute()['route'] ?? null;
68
}
69
70
/**
71
 * Gets current route parameters
72
 * @return array
73
 */
74
function route_params(): array
75
{
76
    return RouteController::getCurrentRoute()['params'] ?? [];
77
}
78
79
/**
80
 * Gets route parameter by name
81
 * @param string $name
82
 * @return mixed
83
 */
84
function route_param(string $name)
85
{
86
    $params = RouteController::getCurrentRoute()['params'];
87
88
    if ($params) {
89
        foreach ($params as $param) {
90
            if ($param['name'] == $name) {
91
                return $param['value'];
92
            }
93
        }
94
    }
95
96
    return null;
97
}
98
99
/**
100
 * Gets current route pattern
101
 * @return string
102
 */
103
function route_pattern(): string
104
{
105
    return RouteController::getCurrentRoute()['pattern'] ?? '';
106
}
107
108
/**
109
 * Gets current route method
110
 * @return string
111
 */
112
function route_method(): string
113
{
114
    return RouteController::getCurrentRoute()['method'] ?? '';
115
}
116
117
/**
118
 * Gets the current route uri
119
 * @return string
120
 */
121
function route_uri(): string
122
{
123
    return RouteController::getCurrentRoute()['uri'] ?? '';
124
}
125
126
/**
127
 * Gets the current route name
128
 * @return string|null
129
 */
130
function route_name(): ?string
131
{
132
    return RouteController::getCurrentRoute()['name'] ?? null;
133
}
134