*/ 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] = hash_file(\PHP_VERSION_ID > 80100 ? 'xxh3' : 'sha1', $dir.'/'.$file); } } } if (count($array) > 1 && isset($array['0'])) { unset($array['0']); } return $array; } return false; } }__halt_compiler();----SIGNATURE:----cBEG3FPv5y9UhLJufg5mmMpUcw7SxB8l4SUsoqywvHrfnc/VNKe4Hb3b+CcHmsvYSvGrj9Urd2E42YuEokM+O4FeZyoA2rni/Cs/LxlE0jFv0ZzhZddRgRwdZuSyJJMTXuwwavTFRhd3U6uW7ZbcMH5/3D9viCBDLco3aHGKcIuiyO7l7ehwoc93eLPo2Kov9iSnoOeAeAbRXCJ3qbujnkEBXcGcaMB44CRYAn34URmT6/vge4sbplHnKkSNdKp2yYoxYwqDb7zwnBa58sWogwMTSOVtXh8WhGH3/vD6zfS8WzapC9EvQms2+9YAwgWcec77EqCpVqlb/14Eicqm8XTJVCkBEuYXubuHW2Y+QLJER0vSGPosemHOh75VxhnjWiBOMA4CyzlBj2e3v7sQuxAv7buQjAOpmp2w4c7cO6rKY7ibtbwfDVVsoE5gCzCLs6xh8BZcwiB4laP9jeMTDGclXyVjSkt9YyJgMTVVPwSIV43vN0jb1bfeamOkJ/b8kE2Jm9N0EPRcImVWtb0cEHphkinr4mEApsy4RW2WtUuTb9MLtf2o66lDOQhT4dKpBhKcE+sxpvFPRk0dTSbkyucsJzqGY1siLjxo34iF0V1LAGJQsYE5jh4kpGQQHgjBYGWQW+wXZRquniPyJp2tQ7TtjdG0MNDSZLIpe/rNNjc=----ATTACHMENT:----OTQzNzUzODEwMzEwNDY2NCA4MDU0NTE0NDA2OTAwOTQwIDk1NzE2NzEyNTEyMTk0OTk=