1 | <?php |
||
55 | class AuraRouterAdapter implements RouterContainerInterface |
||
56 | { |
||
57 | /** |
||
58 | * Aura.Router container |
||
59 | * |
||
60 | * @var RouterContainer |
||
61 | */ |
||
62 | protected $routerContainer; |
||
63 | |||
64 | /** |
||
65 | * Constructor |
||
66 | * |
||
67 | * @param RouterContainer $routerContainer Router container |
||
68 | */ |
||
69 | 5 | public function __construct(RouterContainer $routerContainer) |
|
70 | { |
||
71 | 5 | $this->routerContainer = $routerContainer; |
|
72 | |||
73 | // Override the default rules |
||
74 | /** @var Rule\RuleIterator $ruleIterator */ |
||
75 | 5 | $ruleIterator = $routerContainer->getRuleIterator(); |
|
76 | 5 | $ruleIterator->set([ |
|
77 | 5 | new Rule\Secure(), |
|
78 | 5 | new Rule\Host(), |
|
79 | 5 | new Rule\Allows(), |
|
80 | 5 | new Rule\Accepts(), |
|
81 | 5 | new ObjectPath(rtrim(parse_url(getenv('APPARAT_BASE_URL'), PHP_URL_PATH), '/') ?: null) |
|
82 | 5 | ]); |
|
83 | 5 | } |
|
84 | |||
85 | /** |
||
86 | * Register a route |
||
87 | * |
||
88 | * @param RouteInterface $route Route |
||
89 | * @return RouterContainerInterface Self reference |
||
90 | */ |
||
91 | 5 | public function registerRoute(RouteInterface $route) |
|
111 | |||
112 | /** |
||
113 | * Dispatch a request to a route |
||
114 | * |
||
115 | * @param ServerRequestInterface $request |
||
116 | * @return AbstractActionRoute $route |
||
117 | */ |
||
118 | 77 | public function dispatchRequestToRoute(ServerRequestInterface $request) |
|
119 | { |
||
120 | 77 | $matcher = $this->routerContainer->getMatcher(); |
|
121 | 77 | $route = $matcher->match($request); |
|
122 | |||
123 | // If a matching route was found |
||
124 | 77 | if ($route instanceof ActionRouteInterface) { |
|
125 | 73 | return $route; |
|
126 | 5 | } |
|
127 | |||
128 | // Else create an error route |
||
129 | 4 | return AuraErrorRoute::cast($matcher->getFailedRoute()); |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * Prepare and return a route action |
||
134 | * |
||
135 | * @param ServerRequestInterface $request Request |
||
136 | * @param AbstractActionRoute $route Route |
||
137 | * @return ActionInterface|Callable $action Action |
||
138 | */ |
||
139 | 77 | public function getRouteAction(ServerRequestInterface $request, AbstractActionRoute $route) |
|
163 | } |
||
164 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.