1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Saxulum\RouteController\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
6
|
|
|
use PhpParser\PrettyPrinter\Standard; |
7
|
|
|
use Saxulum\AnnotationManager\Manager\AnnotationManager; |
8
|
|
|
use Saxulum\RouteController\Manager\RouteControllerManager; |
9
|
|
|
use Saxulum\RouteController\Manager\RouteManager; |
10
|
|
|
use Saxulum\RouteController\Manager\ServiceManager; |
11
|
|
|
use Silex\Application; |
12
|
|
|
use Silex\ServiceProviderInterface; |
13
|
|
|
|
14
|
|
|
class RouteControllerProvider implements ServiceProviderInterface |
15
|
|
|
{ |
16
|
|
|
public function register(Application $app) |
17
|
|
|
{ |
18
|
|
|
$app['route_controller_manager'] = $app->share(function () use ($app) { |
19
|
|
|
return new RouteControllerManager( |
20
|
|
|
$app['route_controller_paths'], |
21
|
|
|
$app['route_controller_cache'], |
22
|
|
|
$app['route_controller_cache_filename'] |
23
|
|
|
); |
24
|
|
|
}); |
25
|
|
|
|
26
|
|
|
$app['route_controller_paths'] = $app->share(function () { |
27
|
|
|
$paths = array(); |
28
|
|
|
|
29
|
|
|
return $paths; |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
$app['route_controller_cache'] = null; |
33
|
|
|
|
34
|
|
|
$app['route_controller_cache_filename'] = 'saxulum-route-controller.php'; |
35
|
|
|
|
36
|
|
|
$app['route_controller_annotation_reader'] = $app->share(function () { |
37
|
|
|
return new AnnotationReader(); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
$app['route_controller_annotation_manager'] = $app->share(function ($app) { |
41
|
|
|
return new AnnotationManager($app['route_controller_annotation_reader']); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$app['route_controller_service_manager'] = $app->share(function () { |
45
|
|
|
return new ServiceManager(); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$app['route_controller_route_manager'] = $app->share(function () { |
49
|
|
|
return new RouteManager(); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$app['route_controller_pretty_printer'] = $app->share(function () { |
53
|
|
|
return new Standard(); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function boot(Application $app) |
58
|
|
|
{ |
59
|
|
|
/** @var RouteControllerManager $routeControllerManager */ |
60
|
|
|
$routeControllerManager = $app['route_controller_manager']; |
61
|
|
|
if (!$routeControllerManager->isCacheValid($app['debug'])) { |
62
|
|
|
$routeControllerManager->updateCache( |
63
|
|
|
$app['route_controller_annotation_manager'], |
64
|
|
|
$app['route_controller_service_manager'], |
65
|
|
|
$app['route_controller_route_manager'], |
66
|
|
|
$app['route_controller_pretty_printer'] |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
$routeControllerManager->loadCache($app); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|