diff --git a/src/AppMeta.php b/src/AppMeta.php index 58f85ab..2d87f3e 100644 --- a/src/AppMeta.php +++ b/src/AppMeta.php @@ -30,6 +30,10 @@ public function __construct($name, $context = 'app', $appDir = null) throw new NotWritableException($this->tmpDir); } $this->logDir = $this->appDir . '/var/log'; + $isDevelop = strpos($context, 'prod') === false; + if ($isDevelop) { + $this->clearTmpDirectory($this->tmpDir); + } } /** @@ -42,4 +46,27 @@ public function getResourceListGenerator() return $resourceListGenerator; } + + /** + * @param string $dir + */ + private function clearTmpDirectory($dir) + { + /** + * A flag for clear once because called many times during the unit testing + */ + static $done = false; + + if ($done) { + return; + } + $unlink = function ($path) use (&$unlink) { + foreach (glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*') as $file) { + is_dir($file) ? $unlink($file) : unlink($file); + @rmdir($file); + } + }; + $unlink($dir); + $done = true; + } }