11<?php
2+
23namespace Semver ;
34
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 ;
68use League \Route \Dispatcher ;
79use 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 ;
913
1014class Application
1115{
1216 /**
13- * @var ContainerInterface
17+ * @var Container
1418 */
1519 private $ container ;
1620
@@ -29,11 +33,12 @@ class Application
2933 ];
3034
3135 /**
32- * @param ContainerInterface $container
36+ * @param Container $container
3337 */
34- public function __construct (ContainerInterface $ container )
38+ public function __construct (Container $ container )
3539 {
3640 $ this ->container = $ container ;
41+ $ this ->container ->delegate (new ReflectionContainer ());
3742
3843 $ this ->setupProviders ();
3944 }
@@ -43,14 +48,15 @@ public function __construct(ContainerInterface $container)
4348 */
4449 public function run ()
4550 {
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);
5056
51- $ response = $ dispatcher ->dispatch ($ request-> getMethod () , $ request -> getPathInfo () );
57+ $ response = $ dispatcher ->dispatch ($ request , $ response );
5258
53- $ response -> send ( );
59+ ( new SapiEmitter ())-> emit ( $ response );
5460 }
5561
5662 /**
@@ -59,18 +65,18 @@ public function run()
5965 private function setupProviders ()
6066 {
6167 foreach ($ this ->serviceProviders as &$ serviceProvider ) {
62- /** @var ServiceProvider $serviceProvider */
68+ /** @var AbstractServiceProvider $serviceProvider */
6369 $ serviceProvider = new $ serviceProvider ();
6470 $ serviceProvider ->setContainer ($ this ->container );
6571 }
6672
6773 // Register the service providers.
68- array_walk ($ this ->serviceProviders , function (ServiceProvider $ serviceProvider ) {
74+ array_walk ($ this ->serviceProviders , function (AbstractServiceProvider $ serviceProvider ) {
6975 $ this ->container ->addServiceProvider ($ serviceProvider );
7076 });
7177
7278 // Call the boot methods.
73- array_walk ($ this ->serviceProviders , function (ServiceProvider $ serviceProvider ) {
79+ array_walk ($ this ->serviceProviders , function (AbstractServiceProvider $ serviceProvider ) {
7480 if (method_exists ($ serviceProvider , 'boot ' )) {
7581 $ this ->container ->call ([$ serviceProvider , 'boot ' ]);
7682 }
0 commit comments