protected function _cleanUp($path = null)
{
$resources = Libraries::get(true, 'resources');
$path = $path ?: $resources . '/tmp/tests';
$path = preg_match('/^\\w:|^\\//', $path) ? $path : $resources . '/tmp/' . $path;
if (!is_dir($path)) {
return;
}
$dirs = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($dirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $item) {
$empty = $item->getPathname() === $path . DIRECTORY_SEPARATOR . 'empty';
if ($empty || $iterator->isDot()) {
continue;
}
if ($item->isDir()) {
rmdir($item->getPathname());
continue;
}
if (!$item->isWritable()) {
chmod($item->getPathname(), 0777);
}
unlink($item->getPathname());
}
}