File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,8 @@ public static function begin(
254254 throw new \PHPStan \Command \InceptionNotSuccessfulException ();
255255 }
256256
257+ $ containerFactory ->clearOldContainers ($ tmpDir );
258+
257259 if (count ($ paths ) === 0 ) {
258260 $ errorOutput ->writeLineFormatted ('At least one path must be specified to analyse. ' );
259261 throw new \PHPStan \Command \InceptionNotSuccessfulException ();
Original file line number Diff line number Diff line change @@ -30,10 +30,15 @@ protected function getDefaultParameters(): array
3030 return [];
3131 }
3232
33+ public function getContainerCacheDirectory (): string
34+ {
35+ return $ this ->getCacheDirectory () . '/nette.configurator ' ;
36+ }
37+
3338 public function loadContainer (): string
3439 {
3540 $ loader = new ContainerLoader (
36- $ this ->getCacheDirectory () . ' /nette.configurator ' ,
41+ $ this ->getContainerCacheDirectory () ,
3742 $ this ->parameters ['debugMode ' ]
3843 );
3944
Original file line number Diff line number Diff line change 1010use PHPStan \Php \PhpVersion ;
1111use Roave \BetterReflection \BetterReflection ;
1212use Roave \BetterReflection \SourceLocator \SourceStubber \PhpStormStubsSourceStubber ;
13+ use Symfony \Component \Finder \Finder ;
1314use function sys_get_temp_dir ;
1415
1516class ContainerFactory
@@ -119,6 +120,38 @@ public function create(
119120 return $ container ->getByType (Container::class);
120121 }
121122
123+ public function clearOldContainers (string $ tempDirectory ): void
124+ {
125+ $ configurator = new Configurator (new LoaderFactory (
126+ $ this ->fileHelper ,
127+ $ this ->rootDirectory ,
128+ $ this ->currentWorkingDirectory ,
129+ null
130+ ));
131+ $ configurator ->setDebugMode (true );
132+ $ configurator ->setTempDirectory ($ tempDirectory );
133+
134+ $ finder = new Finder ();
135+ $ finder ->name ('Container_* ' )->in ($ configurator ->getContainerCacheDirectory ());
136+ $ twoDaysAgo = time () - 24 * 60 * 60 * 2 ;
137+
138+ foreach ($ finder as $ containerFile ) {
139+ if ($ containerFile ->getATime () > $ twoDaysAgo ) {
140+ continue ;
141+ }
142+ if ($ containerFile ->getCTime () > $ twoDaysAgo ) {
143+ continue ;
144+ }
145+
146+ $ path = $ containerFile ->getRealPath ();
147+ if ($ path === false ) {
148+ continue ;
149+ }
150+
151+ @unlink ($ path );
152+ }
153+ }
154+
122155 public function getCurrentWorkingDirectory (): string
123156 {
124157 return $ this ->currentWorkingDirectory ;
You can’t perform that action at this time.
0 commit comments