3
3
namespace Reconmap \Services ;
4
4
5
5
use Monolog \Logger ;
6
+ use Psr \Container \ContainerInterface ;
6
7
use Psr \Http \Message \ServerRequestInterface ;
7
8
use Reconmap \CommandOutputParsers \ProcessorFactory ;
8
9
use Reconmap \Database \ConnectionFactory ;
9
10
use Symfony \Component \Config \FileLocator ;
10
11
use Symfony \Component \DependencyInjection \ContainerBuilder ;
11
12
use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
12
13
use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
14
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
13
15
use Symfony \Component \Filesystem \Filesystem ;
14
16
15
17
class ApplicationContainer extends ContainerBuilder
16
18
{
17
- public function __construct (ApplicationConfig $ config , Logger $ logger )
19
+ public function __construct (? ParameterBagInterface $ parameterBag = null )
18
20
{
19
- parent ::__construct ();
21
+ parent ::__construct ($ parameterBag );
20
22
21
- $ this ->initialise ($ config , $ logger );
22
- }
23
-
24
- public function initialise (ApplicationConfig $ config , Logger $ logger )
25
- {
26
23
$ loader = new PhpFileLoader ($ this , new FileLocator (__DIR__ ));
27
24
28
25
$ instanceof = [];
@@ -31,11 +28,15 @@ public function initialise(ApplicationConfig $config, Logger $logger)
31
28
$ this ->configure ($ configurator );
32
29
33
30
$ this ->register (Filesystem::class);
34
- $ this ->compile ();
35
- $ this ->set (ApplicationConfig::class, $ config );
36
- $ this ->set (\mysqli::class, ConnectionFactory::createConnection ($ config ));
37
- $ this ->set (Logger::class, $ logger );
38
- $ this ->set (ProcessorFactory::class, new ProcessorFactory ());
31
+ }
32
+
33
+ public static function initialise (ContainerInterface $ container , ApplicationConfig $ config , Logger $ logger ): void
34
+ {
35
+ $ container ->set (ApplicationConfig::class, $ config );
36
+ $ container ->set (\mysqli::class, ConnectionFactory::createConnection ($ config ));
37
+ $ container ->set (Logger::class, $ logger );
38
+ $ container ->set (ProcessorFactory::class, new ProcessorFactory ());
39
+ $ container ->set (ContainerInterface::class, $ container );
39
40
}
40
41
41
42
private function configure (ContainerConfigurator $ containerConfigurator ): void
@@ -51,19 +52,17 @@ private function configure(ContainerConfigurator $containerConfigurator): void
51
52
->load ('Reconmap \\Services \\' , $ prefix . 'Services/* ' )
52
53
->exclude ([$ prefix . 'Services/QueryParams/OrderByRequestHandler.php ' ])
53
54
->load ('Reconmap \\Repositories \\' , $ prefix . 'Repositories/* ' )
55
+ ->load ('Reconmap \\Database \\' , $ prefix . 'Database/* ' )
56
+ ->load ('Reconmap \\Tasks \\' , $ prefix . 'Tasks/* ' )
54
57
->load ('Reconmap \\Http \\' , $ prefix . 'Http/* ' )
55
58
->exclude ($ prefix . 'Http/ApplicationRequest.php ' )
56
59
->load ('Reconmap \\Controllers \\' , $ prefix . 'Controllers/* ' )
57
- ->set (ServerRequestInterface::class)
58
- ->synthetic ()
59
- ->set (Logger::class)
60
- ->synthetic ()
61
- ->set (ApplicationConfig::class)
62
- ->synthetic ()
63
- ->set (ProcessorFactory::class)
64
- ->synthetic ()
65
- ->set (\mysqli::class)
66
- ->synthetic ();
60
+ ->set (ServerRequestInterface::class)->synthetic ()
61
+ ->set (Logger::class)->synthetic ()
62
+ ->set (ApplicationConfig::class)->synthetic ()
63
+ ->set (ProcessorFactory::class)->synthetic ()
64
+ ->set (ContainerInterface::class)->synthetic ()
65
+ ->set (\mysqli::class)->synthetic ();
67
66
}
68
67
}
69
68
0 commit comments