@@ -43,26 +43,27 @@ public function __construct(array $configFiles, string $cacheFile, FactoryContai
43
43
$ this ->cacheWatcher = new CacheWatcher ;
44
44
}
45
45
46
- public function setCheckExpired (bool $ checkExpired = true ): self
47
- {
48
- $ this ->checkExpired = $ checkExpired ;
49
- return $ this ;
50
- }
51
-
52
- /**
53
- * @return ContainerInterface
54
- * @throws \Exception
55
- */
56
- public function getContainer (): ContainerInterface
57
- {
58
- if ($ this ->container === null ) {
59
- $ container = $ this ->tryGetContainerFromCache ($ this ->cacheFile , $ this ->configFiles );
60
- $ container = $ container ?? $ this ->createContainer ($ this ->configFiles , $ this ->cacheFile , $ this ->classContainer );
46
+ public function setCheckExpired (bool $ checkExpired = true ): self
47
+ {
48
+ $ this ->checkExpired = $ checkExpired ;
49
+ return $ this ;
50
+ }
51
+
52
+ /**
53
+ * @return ContainerInterface
54
+ * @throws \Exception
55
+ */
56
+ public function getContainer (): ContainerInterface
57
+ {
58
+ if ($ this ->container === null ) {
59
+ $ container = $ this ->tryGetContainerFromCache ($ this ->cacheFile , $ this ->configFiles );
60
+ $ container =
61
+ $ container ?? $ this ->createContainer ($ this ->configFiles , $ this ->cacheFile , $ this ->classContainer );
61
62
$ this ->container = $ container ;
62
- }
63
+ }
63
64
64
- return $ this ->container ;
65
- }
65
+ return $ this ->container ;
66
+ }
66
67
67
68
/**
68
69
* @param string[] $configs
@@ -72,20 +73,20 @@ public function getContainer(): ContainerInterface
72
73
* @return ContainerInterface
73
74
* @throws \Exception
74
75
*/
75
- protected function createContainer (array $ configs , string $ cacheFile , string $ class ): ContainerInterface
76
- {
76
+ protected function createContainer (array $ configs , string $ cacheFile , string $ class ): ContainerInterface
77
+ {
77
78
$ appContainer = $ this ->factory ->create ($ configs );
78
79
$ this ->dump ($ cacheFile , $ class , $ appContainer );
79
80
$ this ->dumpMeta ($ cacheFile . '.meta ' , $ configs );
80
81
81
- return $ appContainer ;
82
- }
82
+ return $ appContainer ;
83
+ }
83
84
84
85
/**
85
86
* @param string $filePath
86
87
* @param string[] $configFiles
87
88
*/
88
- protected function dumpMeta (string $ filePath , array $ configFiles ): void
89
+ protected function dumpMeta (string $ filePath , array $ configFiles ): void
89
90
{
90
91
try {
91
92
file_put_contents ($ filePath , serialize ($ configFiles ));
@@ -94,45 +95,45 @@ protected function dumpMeta(string $filePath, array $configFiles): void
94
95
}
95
96
}
96
97
97
- /**
98
- * @param string $filePath
99
- * @param string $className
100
- * @param ContainerBuilder $container
101
- *
102
- * @throws EnvParameterException
103
- */
104
- protected function dump (string $ filePath , string $ className , ContainerBuilder $ container ): void
105
- {
106
- $ dumper = new PhpDumper ($ container );
107
-
108
- try {
98
+ /**
99
+ * @param string $filePath
100
+ * @param string $className
101
+ * @param ContainerBuilder $container
102
+ *
103
+ * @throws EnvParameterException
104
+ */
105
+ protected function dump (string $ filePath , string $ className , ContainerBuilder $ container ): void
106
+ {
107
+ $ dumper = new PhpDumper ($ container );
108
+
109
+ try {
109
110
file_put_contents ($ filePath , $ dumper ->dump ([
110
111
'class ' => $ className ,
111
112
]));
112
113
} catch (\Throwable $ throwable ) {
113
114
throw new \RuntimeException ('Can`t dump cache for DI container ' , 0 , $ throwable );
114
115
}
115
- }
116
+ }
116
117
117
118
/**
118
119
* @param string $fileCache
119
120
* @param string[] $configs
120
121
*
121
122
* @return null|ContainerInterface
122
123
*/
123
- protected function tryGetContainerFromCache (string $ fileCache , array $ configs ): ?ContainerInterface
124
- {
125
- if (!file_exists ($ fileCache )) {
126
- return null ;
127
- }
128
-
129
- if ($ this ->checkExpired && !$ this ->getWatcher ()->isActualCache ($ fileCache , $ configs )) {
130
- return null ;
131
- }
132
-
133
- require_once $ fileCache ;
134
- return new $ this ->classContainer ;
135
- }
124
+ protected function tryGetContainerFromCache (string $ fileCache , array $ configs ): ?ContainerInterface
125
+ {
126
+ if (!file_exists ($ fileCache )) {
127
+ return null ;
128
+ }
129
+
130
+ if ($ this ->checkExpired && !$ this ->getWatcher ()->isActualCache ($ fileCache , $ configs )) {
131
+ return null ;
132
+ }
133
+
134
+ require_once $ fileCache ;
135
+ return new $ this ->classContainer ;
136
+ }
136
137
137
138
protected function getWatcher (): CacheWatcher
138
139
{
0 commit comments