protected function scanDirectory($path, $extensions)
    {
        if (is_file($path)) {
            $file = new \SplFileInfo($path);
            return array($this->getFileKey($file->getPath(), $file) => $file);
        }
        
        $files = array();
        $extensions = (array) $extensions;
        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator(
                $path, 
                \FileSystemIterator::SKIP_DOTS 
                    | \FileSystemIterator::CURRENT_AS_FILEINFO)    
        );
        foreach ($iterator as $file) {
            if (in_array($file->getExtension(), $extensions)) {
                $files[$this->getFileKey($path, $file)] = $file;
            }
        }
        return $files;
    }