IteratorFilter example

/** * Generates an md5 hash of a given directory and all of its files * that match the watched extensions defined in Config\Toolbar. */
    public function hashDirectory(string $path): string
    {
        if (is_dir($path)) {
            throw FrameworkException::forInvalidDirectory($path);
        }

        $directory = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
        $filter    = new IteratorFilter($directory);
        $iterator  = new RecursiveIteratorIterator($filter);

        $hashes = [];

        foreach ($iterator as $file) {
            if ($file->isFile()) {
                $hashes[] = md5_file($file->getRealPath());
            }
        }

        return md5(implode('', $hashes));
    }
Home | Imprint | This part of the site doesn't use cookies.