|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Arcesilas\ActiveState; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Blade; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
class ActiveStateServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* {@inheritdoc} |
|
12
|
|
|
*/ |
|
13
|
137 |
|
public function boot() |
|
14
|
|
|
{ |
|
15
|
|
|
/** @codeCoverageIgnoreStart */ |
|
16
|
|
|
|
|
17
|
|
|
// Directive: @url_is(...$url) |
|
18
|
|
|
// Alias of @path_is() |
|
19
|
|
|
// Check current url is one of the given ones |
|
20
|
137 |
|
Blade::if( |
|
21
|
137 |
|
config('active.blade.url_is', 'url_is'), |
|
22
|
|
|
function (...$url) { |
|
23
|
4 |
|
return $this->app['active-state']->checkUrlIs(...$url); |
|
24
|
137 |
|
} |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
// Directive: @not_url_is(...$url) |
|
28
|
|
|
// Alias of @not_path_is |
|
29
|
|
|
// Check current url is NOT one of the given ones |
|
30
|
137 |
|
Blade::if( |
|
31
|
137 |
|
config('active.blade.not_url_is', 'not_url_is'), |
|
32
|
|
|
function (...$url) { |
|
33
|
4 |
|
return ! $this->app['active-state']->checkUrlIs(...$url); |
|
34
|
137 |
|
} |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
// Directive: @url_has($url) |
|
38
|
|
|
// Alias of @path_has |
|
39
|
|
|
// Check current url contains one of the given patterns |
|
40
|
137 |
|
Blade::if( |
|
41
|
137 |
|
config('active.blade.url_has', 'url_has'), |
|
42
|
|
|
function (...$url) { |
|
43
|
6 |
|
return $this->app['active-state']->checkUrlHas(...$url); |
|
44
|
137 |
|
} |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
/** @codeCoverageIgnoreEnd */ |
|
48
|
|
|
|
|
49
|
|
|
// Directive: @url_has_not($url) |
|
50
|
|
|
// Alias of @not_path_has |
|
51
|
137 |
|
Blade::if( |
|
52
|
137 |
|
config('active.blade.not_url_has', 'not_url_has'), |
|
53
|
|
|
function (...$url) { |
|
54
|
6 |
|
return ! $this->app['active-state']->checkUrlHas(...$url); |
|
55
|
137 |
|
} |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
// Directive: @path_is(...$paths) |
|
59
|
|
|
// Check current path is one of the given ones |
|
60
|
137 |
|
Blade::if( |
|
61
|
137 |
|
config('active.blade.path_is', 'path_is'), |
|
62
|
|
|
function (...$paths) { |
|
63
|
4 |
|
return $this->app['active-state']->checkPathIs(...$paths); |
|
64
|
137 |
|
} |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
// Directive: @not_path_is(...$paths) |
|
68
|
|
|
// Check current url is NOT one of the given ones |
|
69
|
137 |
|
Blade::if( |
|
70
|
137 |
|
config('active.blade.not_path_is', 'not_path_is'), |
|
71
|
|
|
function (...$paths) { |
|
72
|
4 |
|
return ! $this->app['active-state']->checkPathIs(...$paths); |
|
73
|
137 |
|
} |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
// Directive: @path_has($paths) |
|
77
|
|
|
// Check current url contains one of the given patterns |
|
78
|
137 |
|
Blade::if( |
|
79
|
137 |
|
config('active.blade.path_has', 'path_has'), |
|
80
|
|
|
function (...$paths) { |
|
81
|
6 |
|
return $this->app['active-state']->checkPathHas(...$paths); |
|
82
|
137 |
|
} |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
// Directive: @path_has_not($paths) |
|
86
|
|
|
// Check current url does not contain the given patterns |
|
87
|
137 |
|
Blade::if( |
|
88
|
137 |
|
config('active.blade.not_path_has', 'not_path_has'), |
|
89
|
|
|
function (...$paths) { |
|
90
|
6 |
|
return ! $this->app['active-state']->checkPathHas(...$paths); |
|
91
|
137 |
|
} |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
// Directive: @route_is($route, $parameters) |
|
95
|
137 |
|
Blade::if( |
|
96
|
137 |
|
config('active.blade.route_is', 'route_is'), |
|
97
|
|
|
function ($route, $parameters) { |
|
98
|
8 |
|
return $this->app['active-state']->checkRouteIs($route, $parameters); |
|
99
|
137 |
|
} |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
// Directive: @not_route_is($route, $parameters) |
|
103
|
137 |
|
Blade::if( |
|
104
|
137 |
|
config('active.blade.not_route_is', 'not_route_is'), |
|
105
|
|
|
function ($route, $parameters) { |
|
106
|
8 |
|
return ! $this->app['active-state']->checkRouteIs($route, $parameters); |
|
107
|
137 |
|
} |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
// Directive: @route_in(...$routes) |
|
111
|
137 |
|
Blade::if( |
|
112
|
137 |
|
config('active.blade.route_in', 'route_in'), |
|
113
|
|
|
function (...$routes) { |
|
114
|
4 |
|
return $this->app['active-state']->checkRouteIn(...$routes); |
|
115
|
137 |
|
} |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
// Directive: @not_route_in(...$routes) |
|
119
|
137 |
|
Blade::if( |
|
120
|
137 |
|
config('active.blade.not_route_in', 'not_route_in'), |
|
121
|
|
|
function (...$routes) { |
|
122
|
4 |
|
return ! $this->app['active-state']->checkRouteIn(...$routes); |
|
123
|
137 |
|
} |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
// Directive: @query_is(...$parameters) |
|
127
|
137 |
|
Blade::if( |
|
128
|
137 |
|
config('active.blade.query_is', 'query_is'), |
|
129
|
|
|
function (...$parameters) { |
|
130
|
10 |
|
return $this->app['active-state']->checkQueryIs(...$parameters); |
|
131
|
137 |
|
} |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
|
|
// Directive: @not_query_is(...$parameters) |
|
135
|
137 |
|
Blade::if( |
|
136
|
137 |
|
config('active.blade.not_query_is', 'not_query_is'), |
|
137
|
|
|
function (...$parameters) { |
|
138
|
10 |
|
return ! $this->app['active-state']->checkQueryIs(...$parameters); |
|
139
|
137 |
|
} |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
// Directive: @query_has(...$parameters) |
|
143
|
137 |
|
Blade::if( |
|
144
|
137 |
|
config('active.blade.query_has', 'query_has'), |
|
145
|
|
|
function (...$parameters) { |
|
146
|
9 |
|
return $this->app['active-state']->checkQueryHas(...$parameters); |
|
147
|
137 |
|
} |
|
148
|
|
|
); |
|
149
|
|
|
|
|
150
|
|
|
// Directive: @not_query_has(...$parameterss) |
|
151
|
137 |
|
Blade::if( |
|
152
|
137 |
|
config('active.blade.not_query_has', 'not_query_has'), |
|
153
|
|
|
function (...$parameters) { |
|
154
|
9 |
|
return ! $this->app['active-state']->checkQueryHas(...$parameters); |
|
155
|
137 |
|
} |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
// Directive: @query_has_only |
|
159
|
137 |
|
Blade::if( |
|
160
|
137 |
|
config('active.blade.query_has_only', 'query_has_only'), |
|
161
|
|
|
function (...$parameters) { |
|
162
|
5 |
|
return $this->app['active-state']->checkQueryHasOnly(...$parameters); |
|
163
|
137 |
|
} |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
|
|
// Directive: @not_query_has_only |
|
167
|
137 |
|
Blade::if( |
|
168
|
137 |
|
config('active.blade.not_query_has_only', 'not_query_has_only'), |
|
169
|
|
|
function (...$parameters) { |
|
170
|
5 |
|
return ! $this->app['active-state']->checkQueryHasOnly(...$parameters); |
|
171
|
137 |
|
} |
|
172
|
|
|
); |
|
173
|
|
|
|
|
174
|
|
|
// Directive: @query_contains |
|
175
|
137 |
|
Blade::if( |
|
176
|
137 |
|
config('active.blade.query_contains', 'query_contains'), |
|
177
|
|
|
function ($parameters) { |
|
178
|
4 |
|
return $this->app['active-state']->checkQueryContains($parameters); |
|
179
|
137 |
|
} |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
// Directive: @not_query_contains |
|
183
|
137 |
|
Blade::if( |
|
184
|
137 |
|
config('active.blade.not_query_contains', 'not_query_contains'), |
|
185
|
|
|
function ($parameters) { |
|
186
|
4 |
|
return ! $this->app['active-state']->checkQueryContains($parameters); |
|
187
|
137 |
|
} |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
137 |
|
$this->publishes([ |
|
191
|
137 |
|
__DIR__ . '/config/active.php' => config_path('active.php'), |
|
192
|
137 |
|
], 'config'); |
|
193
|
137 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* {@inheritdoc} |
|
197
|
|
|
*/ |
|
198
|
137 |
|
public function register() |
|
199
|
|
|
{ |
|
200
|
|
|
$this->app->singleton('active-state', function ($app) { |
|
201
|
120 |
|
return new Active($app->make('request')); |
|
202
|
137 |
|
}); |
|
203
|
|
|
|
|
204
|
137 |
|
$this->mergeConfigFrom( |
|
205
|
137 |
|
__DIR__ . '/../config/active.php', |
|
206
|
137 |
|
'active' |
|
207
|
|
|
); |
|
208
|
137 |
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|