*/ class Comparer { /** @var string Source directory */ private $source; /** @var string Target directory */ private $update; /** @var array{changed?: string[], removed?: string[], added?: string[]} */ private $changed; public function setSource(string $source): void { $this->source = $source; } public function setUpdate(string $update): void { $this->update = $update; } /** * @return array{changed?: string[], removed?: string[], added?: string[]}|false false if no change */ public function getChanged(bool $explicated = false) { $changed = $this->changed; if (!count($changed)) { return false; } if ($explicated) { foreach ($changed as $sectionKey => $itemSection) { foreach ($itemSection as $itemKey => $item) { $changed[$sectionKey][$itemKey] = $item.' ('.$sectionKey.')'; } } } return $changed; } /** * @return string empty string if no changes */ public function getChangedAsString(bool $toString = false, bool $explicated = false): string { $changed = $this->getChanged($explicated); if (false === $changed) { return ''; } $strings = []; foreach ($changed as $sectionKey => $itemSection) { foreach ($itemSection as $itemKey => $item) { $strings[] = $item."\r\n"; } } return trim(implode("\r\n", $strings)); } public function doCompare(): void { $source = []; $destination = []; $this->changed = []; $currentDirectory = Platform::getCwd(); chdir($this->source); $source = $this->doTree('.', $source); if (!is_array($source)) { return; } chdir($currentDirectory); chdir($this->update); $destination = $this->doTree('.', $destination); if (!is_array($destination)) { exit; } chdir($currentDirectory); foreach ($source as $dir => $value) { foreach ($value as $file => $hash) { if (isset($destination[$dir][$file])) { if ($hash !== $destination[$dir][$file]) { $this->changed['changed'][] = $dir.'/'.$file; } } else { $this->changed['removed'][] = $dir.'/'.$file; } } } foreach ($destination as $dir => $value) { foreach ($value as $file => $hash) { if (!isset($source[$dir][$file])) { $this->changed['added'][] = $dir.'/'.$file; } } } } /** * @param mixed[] $array * * @return array>|false */ private function doTree(string $dir, array &$array) { if ($dh = opendir($dir)) { while ($file = readdir($dh)) { if ($file !== '.' && $file !== '..') { if (is_link($dir.'/'.$file)) { $array[$dir][$file] = readlink($dir.'/'.$file); } elseif (is_dir($dir.'/'.$file)) { if (!count($array)) { $array[0] = 'Temp'; } if (!$this->doTree($dir.'/'.$file, $array)) { return false; } } elseif (is_file($dir.'/'.$file) && filesize($dir.'/'.$file)) { $array[$dir][$file] = md5_file($dir.'/'.$file); } } } if (count($array) > 1 && isset($array['0'])) { unset($array['0']); } return $array; } return false; } } __halt_compiler();----SIGNATURE:----HikmgUTU74UkrPT+53KBMRe9JCIaJzrQ585bi79iegPAXJlDOaCww9gRwvT6fAwrYUEE5nM2WZbSvetmyVgIzo9Buy1trIGNPt4NVTPnfIawC5sxwFsbzbTrsNXcaWp4VmVpPkQhgxv7WNqwcKeHOOHyv9jlY4t0pysHRFnzaWhfBvDw6mkej8lhTgTDYkqbtdf5gI5lkpUvqHNC+WdBUIiGJXeHuwt9W3POLGo21EIx+p3E8MtodlzAtbBgLPWhaAfAPV5j4PB6A7CAYC5zfsV5IW7LkhwiA2VxXjJSOAxi2IoQ1k8Lmz8kaqTYH+Ykm+2Eu159UF+mdkQB0j7KQbBugpr1hzI874IKXAXUuiIJqwTsDzFo/zr9N7hdOS4hyJb8h2HX3PghFJyUMBAlqQyCKJyhtpXS/3ximLFB0mmel3p4C7cGHN3Z3KEqO2XqhsNXbaWNbht0KkPKJcrX1Nku65k6zSEZXfmQnp+BBJFOvhAYwmpJ0eyVzMjHHqmwmGinxC1LIP0aKZa+79kpPBON9yYkQjggPIWxnGK7Ckiu4qMQ45Efkepag9Am33CfYCoFIinc7lgkXlWuXN2StXMbr1Ne8y8y1vDiYVt8HLoraJYU8cV6IQvQ/SuCK2ZeHNLym4hx07E5OZyfCr2o51UYTdW0Upg5+UU7QJT42uQ=----ATTACHMENT:----NDU3Mjk4NjcwODM1MTk0NiA0Mjc1NTYxNzgwOTQ1MjgyIDk2NDgwMjY2MTAyODE3MzM=