/** * @param string $directory * @param string $outputfile */ function create_new_resultfile($directory, $outputdirectory) { $writer = new Robo47_DirectoryHasher_Writer_File_Xml(); if (file_exists($outputdirectory . '/new.xml')) { if (file_exists($outputdirectory . '/old.xml')) { rename($outputdirectory . '/old.xml', $outputdirectory . '/old-' . date('m.d.Y-h-i') . '.xml'); } rename($outputdirectory . '/new.xml', $outputdirectory . '/old.xml'); } // For first run if (!file_exists($outputdirectory . '/old.xml')) { $writer->write(new Robo47_DirectoryHasher_Result(), $outputdirectory . '/old.xml'); } $source = new Robo47_DirectoryHasher_Source_Directory($directory); $multihasher = new Robo47_DirectoryHasher_Hasher_Multi(array(new Robo47_DirectoryHasher_Hasher_MD5(), new Robo47_DirectoryHasher_Hasher_SHA1(), new Robo47_DirectoryHasher_Hasher_FileData())); $hasher = new Robo47_DirectoryHasher($source, $multihasher); $hasher->run(); $writer->write($hasher->getResult(), $outputdirectory . '/new.xml'); }
<?php $time = microtime(true); require_once dirname(__FILE__) . '/../src/Robo47/DirectoryHasher/Autoloader.php'; Robo47_DirectoryHasher_Autoloader::register(); $pathtohash = realpath(dirname(__FILE__) . '/../') . '/src/'; $outputfile = realpath(dirname(__FILE__) . '/../') . '/result.xml'; $ignoredDirectories = array(dirname(__FILE__) . '/subdirectory/', dirname(__FILE__) . '/another/subdirectory/'); $writer = new Robo47_DirectoryHasher_Writer_File_Xml(); $source = new Robo47_DirectoryHasher_Source_Directory($pathtohash, $ignoredDirectories); $hasher = new Robo47_DirectoryHasher_Hasher_Multi(array(new Robo47_DirectoryHasher_Hasher_MD5(), new Robo47_DirectoryHasher_Hasher_SHA1(), new Robo47_DirectoryHasher_Hasher_FileData())); echo 'DirectoryHasher' . PHP_EOL; $hasher = new Robo47_DirectoryHasher($source, $hasher); echo PHP_EOL . 'Creating hashs for Directory: ' . $pathtohash . PHP_EOL; $hasher->run(); echo PHP_EOL . 'Writing result to: ' . $outputfile . PHP_EOL; $writer->write($hasher->getResult(), $outputfile); $runtime = number_format(microtime(true) - $time, 4); $memory = number_format(memory_get_peak_usage(true) / (1024 * 1024), 2); echo PHP_EOL . 'Time: ' . $runtime . ' seconds'; echo ', Memory: ' . $memory . 'Mb' . PHP_EOL;