10
10
use Symfony \Component \DependencyInjection \Dumper \PhpDumper ;
11
11
use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
12
12
use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
13
+ use Symfony \Component \Filesystem \Filesystem ;
13
14
use Throwable ;
14
15
15
16
class LoaderContainer implements LoaderContainerInterface
16
17
{
17
18
/** @var string[] */
18
19
protected array $ configFiles = [];
19
20
21
+ protected ?Filesystem $ fs = null ;
20
22
protected FactoryContainer $ factory ;
21
23
protected ?ContainerInterface $ container = null ;
22
24
protected CacheWatcher $ cacheWatcher ;
@@ -84,7 +86,7 @@ protected function createContainer(array $configs, array $extensions = []): Cont
84
86
protected function dumpMeta (string $ filePath , array $ configFiles ): void
85
87
{
86
88
try {
87
- file_put_contents ($ filePath , serialize ($ configFiles ));
89
+ $ this -> getFilesystem ()-> dumpFile ($ filePath , serialize ($ configFiles ));
88
90
} catch (Throwable $ throwable ) {
89
91
throw new RuntimeException ('Can`t dump meta for DI container ' , 0 , $ throwable );
90
92
}
@@ -95,9 +97,9 @@ protected function dump(string $filePath, string $className, ContainerBuilder $c
95
97
$ dumper = new PhpDumper ($ container );
96
98
97
99
try {
98
- file_put_contents ($ filePath , $ dumper ->dump ([
99
- 'class ' => $ className ,
100
- ]));
100
+ $ this -> getFilesystem ()-> dumpFile ($ filePath , $ dumper ->dump ([
101
+ 'class ' => $ className ,
102
+ ]));
101
103
} catch (Throwable $ throwable ) {
102
104
throw new RuntimeException ('Can`t dump cache for DI container ' , 0 , $ throwable );
103
105
}
@@ -127,4 +129,13 @@ protected function getWatcher(): CacheWatcher
127
129
{
128
130
return $ this ->cacheWatcher ;
129
131
}
132
+
133
+ protected function getFilesystem (): Filesystem
134
+ {
135
+ if ($ this ->fs === null ) {
136
+ $ this ->fs = new Filesystem ;
137
+ }
138
+
139
+ return $ this ->fs ;
140
+ }
130
141
}
0 commit comments