/
Router.php
44 lines (36 loc) · 1.18 KB
/
Router.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
<?php
namespace Statamic\Mixins;
use Statamic\Http\Controllers\FrontendController;
class Router
{
public function statamic()
{
return function ($uri, $view, $data = []) {
return $this->get($uri, [FrontendController::class, 'route'])
->defaults('view', $view)
->defaults('data', $data);
};
}
public function amp()
{
return function ($routes) {
$existingRoutes = $this->routes->getRoutesByMethod()['GET'] ?? [];
$routes($this);
if (! config('statamic.amp.enabled')) {
return;
}
$updatedRoutes = $this->routes->getRoutesByMethod()['GET'];
$existingKeys = array_keys($existingRoutes);
collect($updatedRoutes)->reject(function ($route, $key) use ($existingKeys) {
return in_array($key, $existingKeys);
})->each(function ($route) {
$amp = clone $route;
$amp->setUri('amp/'.$route->uri());
if ($amp->getName()) {
$amp->name('.amp');
}
$this->routes->add($amp);
});
};
}
}