1
1
<?php
2
+
2
3
namespace Semver ;
3
4
4
- use League \Container \ContainerInterface ;
5
- use League \Container \ServiceProvider ;
5
+ use League \Container \Container ;
6
+ use League \Container \ReflectionContainer ;
7
+ use League \Container \ServiceProvider \AbstractServiceProvider ;
6
8
use League \Route \Dispatcher ;
7
9
use League \Route \RouteCollection ;
8
- use Symfony \Component \HttpFoundation \Request ;
10
+ use Psr \Http \Message \ServerRequestInterface ;
11
+ use Zend \Diactoros \Response ;
12
+ use Zend \Diactoros \Response \SapiEmitter ;
9
13
10
14
class Application
11
15
{
12
16
/**
13
- * @var ContainerInterface
17
+ * @var Container
14
18
*/
15
19
private $ container ;
16
20
@@ -29,11 +33,12 @@ class Application
29
33
];
30
34
31
35
/**
32
- * @param ContainerInterface $container
36
+ * @param Container $container
33
37
*/
34
- public function __construct (ContainerInterface $ container )
38
+ public function __construct (Container $ container )
35
39
{
36
40
$ this ->container = $ container ;
41
+ $ this ->container ->delegate (new ReflectionContainer ());
37
42
38
43
$ this ->setupProviders ();
39
44
}
@@ -43,14 +48,15 @@ public function __construct(ContainerInterface $container)
43
48
*/
44
49
public function run ()
45
50
{
46
- /** @var Dispatcher $dispatcher */
47
- /* @type Request $request */
48
- $ dispatcher = $ this ->container ->get (RouteCollection::class)->getDispatcher ();
49
- $ request = $ this ->container ->get (Request::class);
51
+ /* @var Dispatcher $dispatcher */
52
+ /* @type ServerRequestInterface $request */
53
+ $ request = $ this ->container ->get (ServerRequestInterface::class);
54
+ $ response = new Response ();
55
+ $ dispatcher = $ this ->container ->get (RouteCollection::class);
50
56
51
- $ response = $ dispatcher ->dispatch ($ request-> getMethod () , $ request -> getPathInfo () );
57
+ $ response = $ dispatcher ->dispatch ($ request , $ response );
52
58
53
- $ response -> send ( );
59
+ ( new SapiEmitter ())-> emit ( $ response );
54
60
}
55
61
56
62
/**
@@ -59,18 +65,18 @@ public function run()
59
65
private function setupProviders ()
60
66
{
61
67
foreach ($ this ->serviceProviders as &$ serviceProvider ) {
62
- /** @var ServiceProvider $serviceProvider */
68
+ /** @var AbstractServiceProvider $serviceProvider */
63
69
$ serviceProvider = new $ serviceProvider ();
64
70
$ serviceProvider ->setContainer ($ this ->container );
65
71
}
66
72
67
73
// Register the service providers.
68
- array_walk ($ this ->serviceProviders , function (ServiceProvider $ serviceProvider ) {
74
+ array_walk ($ this ->serviceProviders , function (AbstractServiceProvider $ serviceProvider ) {
69
75
$ this ->container ->addServiceProvider ($ serviceProvider );
70
76
});
71
77
72
78
// Call the boot methods.
73
- array_walk ($ this ->serviceProviders , function (ServiceProvider $ serviceProvider ) {
79
+ array_walk ($ this ->serviceProviders , function (AbstractServiceProvider $ serviceProvider ) {
74
80
if (method_exists ($ serviceProvider , 'boot ' )) {
75
81
$ this ->container ->call ([$ serviceProvider , 'boot ' ]);
76
82
}
0 commit comments