public function clearDirectory($dir)
    {
        if (empty($dir) || !@is_dir($dir)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator($dir);
        $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current) {
            /** @var \SplFileInfo $current */
            $filename = $current->getBasename();
            // Check for files and dirs starting with "dot" (.gitignore, etc)
            return !($filename && $filename[0] === '.');
        });

        /** @var \SplFileInfo[] $listing */
        $listing = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($listing as $item) {
            $path = $item->getPathname();
            $item->isDir() ? rmdir($path) : unlink($path);
        }
        return true;
    }
public function clearDirectory($dir)
    {
        if (empty($dir) || !@is_dir($dir)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator($dir);
        $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current) {
            /** @var \SplFileInfo $current */
            $filename = $current->getBasename();
            // Check for files and dirs starting with "dot" (.gitignore, etc)
            return !($filename && $filename[0] === '.');
        });

        /** @var \SplFileInfo[] $listing */
        $listing = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($listing as $item) {
            $path = $item->getPathname();
            $item->isDir() ? rmdir($path) : unlink($path);
        }
        return true;
    }
public function clearDirectory ( $ dir ) { if ( empty ( $ dir ) || ! @ is_dir ( $ dir ) ) { return false ; } $ iterator = new \ RecursiveDirectoryIterator ( $ dir ) ; $ filter = new \ RecursiveCallbackFilterIterator ( $ iterator , function ( $ current ) { /** @var \SplFileInfo $current */ $ filename = $ current -> getBasename ( ) ; // Check for files and dirs starting with "dot" (.gitignore, etc) return ! ( $ filename && $ filename [ 0 ] === '.' ) ; } ) ; /** @var \SplFileInfo[] $listing */ $ listing = new \ RecursiveIteratorIterator ( $ filter , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ listing as $ item ) { $ path = $ item -> getPathname ( ) ; $ item -> isDir ( ) ? rmdir ( $ path ) : unlink ( $ path ) ; } return true ; }
Removes all files and directories inside a directory.
Used for deleting all cache content.

@param string $dir

@return bool
Removes all files and directories inside a directory . Used for deleting all cache content .