-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoute.php
More file actions
88 lines (79 loc) · 2.91 KB
/
Route.php
File metadata and controls
88 lines (79 loc) · 2.91 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
* 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;
use Polymorphine\Routing\Map\Trace;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
interface Route
{
public const PATH_SEPARATOR = '.';
public const PATH_ATTRIBUTE = 'route.path';
public const WILDCARD_ATTRIBUTE = 'route.path.wildcard';
public const METHODS_ATTRIBUTE = 'route.methods';
/**
* Forward $request and handle it from matching endpoint Route(s).
* Returns the same instance of response prototype if request was not handled.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $prototype
*
* @return ResponseInterface
*/
public function forward(ServerRequestInterface $request, ResponseInterface $prototype): ResponseInterface;
/**
* Route located behind last switch defined with provided identifiers path.
*
* @param string $path by default dot separated switch identifiers relative
* to current position in routing tree
*
* @throws Route\Exception\RouteNotFoundException
*
* @return Route
*/
public function select(string $path): Route;
/**
* Get endpoint call Uri.
*
* Uri itself used for incoming ServerRequest does not guarantee
* reaching current endpoint as other conditions might reject it
* (http method, authorization... etc.), but returned Uri parts
* are required by this endpoint to pass.
*
* Returned Uri segments MUST match those compared in forward() method.
* Other segments SHOULD NOT be added, and $prototype MUST NOT define
* different segments than returned from current route instance.
* If any Uri part defined in $prototype is overwritten with different
* value InvalidUriPrototypeException SHOULD be thrown.
*
* If Route is not an endpoint for any ServerRequestInterface or cannot be
* resolved into endpoint's Uri UndefinedUriException MUST be thrown
*
* Redundant $params SHOULD be ignored, but if Uri cannot be built with
* given $params method MUST throw InvalidUriParamException
*
* @param array $params
* @param UriInterface $prototype
*
* @throws Route\Exception\UriBuildException
*
* @return UriInterface
*/
public function uri(UriInterface $prototype, array $params): UriInterface;
/**
* Gathers and stores inside Map object all routing paths associated with
* information about request methods and URI templates.
*
* @param Trace $trace
*
* @throws Map\Exception\UnreachableEndpointException
*/
public function routes(Trace $trace): void;
}