|
1
|
|
|
<?php |
|
2
|
|
|
namespace examples\routing; |
|
3
|
|
|
use Pimple\ServiceProviderInterface; |
|
4
|
|
|
use Pimple\Container; |
|
5
|
|
|
use Aura\Router\RouterContainer; |
|
6
|
|
|
use Middlewares\AuraRouter; |
|
7
|
|
|
use Middlewares\RequestHandler; |
|
8
|
|
|
use Middlewares\ErrorHandler; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* this configuration reuse middleware and other |
|
12
|
|
|
* components available from https://github.com/middlewares project |
|
13
|
|
|
*/ |
|
14
|
|
|
class MiddlewaresServiceProvider implements ServiceProviderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function register(Container $app) |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
// Error handler middleware configuration |
|
21
|
|
|
// from: https://github.com/middlewares/error-handler |
|
22
|
|
|
$app['errorHandlingMiddleware'] = function() { |
|
23
|
|
|
return (new ErrorHandler())->catchExceptions(true); |
|
24
|
|
|
}; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// aura routing middleware configuration |
|
28
|
|
|
// from: https://github.com/middlewares/aura-router |
|
29
|
|
|
$app['basepath'] = '/'; |
|
30
|
|
|
$app['auraRouterMiddleware'] = function($app) { |
|
31
|
|
|
$routeContainer = new RouterContainer($app['basepath']); |
|
32
|
|
|
$routeMap = $routeContainer->getMap(); |
|
33
|
|
|
|
|
34
|
|
|
include "routes.php"; |
|
35
|
|
|
|
|
36
|
|
|
return new AuraRouter($routeContainer); |
|
37
|
|
|
}; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
// register the RequestHandler |
|
41
|
|
|
// from https://github.com/middlewares/request-handler |
|
42
|
|
|
$app['requestHandlerMiddleware'] = function($app) { |
|
|
|
|
|
|
43
|
|
|
return new RequestHandler(); |
|
44
|
|
|
}; |
|
45
|
|
|
|
|
46
|
|
|
// define middleware queue |
|
47
|
|
|
$app['handler.queue'] = [ |
|
48
|
|
|
'errorHandlingMiddleware', |
|
49
|
|
|
'auraRouterMiddleware', |
|
50
|
|
|
'requestHandlerMiddleware' |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.