-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilderTest.php
More file actions
62 lines (52 loc) · 2.53 KB
/
BuilderTest.php
File metadata and controls
62 lines (52 loc) · 2.53 KB
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
<?php declare(strict_types=1);
/*
* This file is part of Polymorphine/Routing package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Polymorphine\Routing\Tests\ReadmeExampleTest;
use Polymorphine\Routing\Tests\ReadmeExampleTest;
use Polymorphine\Routing\Builder;
use Polymorphine\Routing\Router;
use Polymorphine\Routing\Route\Endpoint;
use Polymorphine\Routing\Tests\Doubles;
class BuilderTest extends ReadmeExampleTest
{
protected function router(): Router
{
if ($this->router) { return $this->router; }
$csrf = $this->csrfMiddleware();
$auth = $this->authMiddleware();
$adminGate = $this->adminGate();
$notFound = $this->notFound();
$builder = new Builder();
$root = $builder->rootNode()->middleware($csrf)->middleware($auth)->responseScan();
$main = $root->defaultRoute()->callbackGate($adminGate)->link($filteredGuestRoute)->pathSwitch();
$main->root()->callback($this->endpoint('HomePage'));
$admin = $main->route('admin')->methodSwitch();
$admin->route('GET')->callback($this->endpoint('AdminPanel'));
$admin->route('POST')->callback($this->endpoint('ApplySettings'));
$main->route('login')->redirect('home');
$main->route('logout')->method('POST')->callback($this->endpoint('Logout'));
$articles = $main->resource('articles')->id('id');
$articles->index()->callback($this->endpoint('ShowArticles'));
$articles->get()->callback($this->endpoint('ShowArticle'));
$articles->post()->callback($this->endpoint('AddArticle'));
$articles->patch()->callback($this->endpoint('UpdateArticle'));
$articles->delete()->callback($this->endpoint('DeleteArticle'));
$articles->add()->callback($this->endpoint('AddArticleForm'));
$articles->edit()->callback($this->endpoint('EditArticleForm'));
$root->route()->path('/login')->methodSwitch([
'GET' => new Endpoint\CallbackEndpoint($this->endpoint('LoginPage')),
'POST' => new Endpoint\CallbackEndpoint($this->endpoint('Login'))
]);
$root->route()->path('/logout')->redirect('home');
$root->route()->path('/admin')->redirect('login');
$root->route()->method('GET')->joinLink($filteredGuestRoute);
$root->route()->callback($notFound);
return $this->router = $builder->router(new Doubles\FakeUri(), new Doubles\FakeResponse(), 'home');
}
}