-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
80 lines (78 loc) · 2.57 KB
/
routes.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
<?php
use FreeElephants\RestDaemon\Endpoint\Handler\CallableEndpointMethodHandlerWrapper;
use RestDaemon\Example\Endpoint\Greeting\GetAttributeHandler;
use RestDaemon\Example\Endpoint\Greeting\GetHandler as GreetingGetHandler;
use RestDaemon\Example\Endpoint\Greeting\PostHandler;
use RestDaemon\Example\Endpoint\Index\GetHandler;
use RestDaemon\Example\Endpoint\Reusable\HelloHandler;
return [
// Endpoints in base (default or root) module:
'endpoints' => [
'/' => [
'name' => 'Index Endpoint',
'handlers' => [
'GET' => GetHandler::class,
],
],
'/greeting' => [
'name' => 'Greeting by name in params',
'handlers' => [
// You can set handler by method
'GET' => GreetingGetHandler::class,
'POST' => PostHandler::class,
],
'allowHeaders' => [
'X-Greeting',
'X-Some-Not-Simple',
],
],
// Symfony routes patterns are supported
'/greeting/{name}' => [
'name' => 'Greeting by name in path',
'handlers' => [
'GET' => GetAttributeHandler::class
]
],
'/hello' => [
'name' => 'Hello World',
'handlers' => [
'GET' => HelloHandler::class
],
'allowHeaders' => '*',
],
'/exception' => [
'name' => '',
'handlers' => [
// You can use inline functions and instantiating for simple logic instead full-weight DI and implementation
'GET' => new CallableEndpointMethodHandlerWrapper(function () {
throw new \LogicException("Logic exception");
})
],
],
],
'modules' => [
// You can share same handler class between modules: every handler instance get different module context
'/api/v1' => [
'name' => 'Api ver.1',
'endpoints' => [
'/hello' => [
'name' => 'Hello World',
'handlers' => [
'GET' => HelloHandler::class
],
],
],
],
'/api/v2' => [
'name' => 'Api ver.2',
'endpoints' => [
'/hello' => [
'name' => 'Hello World',
'handlers' => [
'GET' => HelloHandler::class
],
],
],
],
],
];