diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index dba5541be..5f491ae9a 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -56,12 +56,51 @@ class Locker $this->repositoryManager = $repositoryManager; $this->installationManager = $installationManager; $this->hash = md5($composerFileContents); - $this->contentHash = $this->getContentHash($composerFileContents); + $this->contentHash = self::getContentHash($composerFileContents); $this->loader = new ArrayLoader(null, true); $this->dumper = new ArrayDumper(); $this->process = new ProcessExecutor($io); } + /** + * Returns the md5 hash of the sorted content of the composer file. + * + * @param string $composerFileContents The contents of the composer file. + * + * @return string + */ + public static function getContentHash($composerFileContents) + { + $content = json_decode($composerFileContents, true); + + $relevantKeys = array( + 'name', + 'version', + 'require', + 'require-dev', + 'conflict', + 'replace', + 'provide', + 'minimum-stability', + 'prefer-stable', + 'repositories', + 'extra', + ); + + $relevantContent = array(); + + foreach (array_intersect($relevantKeys, array_keys($content)) as $key) { + $relevantContent[$key] = $content[$key]; + } + if (isset($content['config']['platform'])) { + $relevantContent['config']['platform'] = $content['config']['platform']; + } + + ksort($relevantContent); + + return md5(json_encode($relevantContent)); + } + /** * Checks whether locker were been locked (lockfile found). * @@ -390,43 +429,4 @@ class Locker return $datetime ? $datetime->format('Y-m-d H:i:s') : null; } - - /** - * Returns the md5 hash of the sorted content of the composer file. - * - * @param string $composerFileContents The contents of the composer file. - * - * @return string - */ - private function getContentHash($composerFileContents) - { - $content = json_decode($composerFileContents, true); - - $relevantKeys = array( - 'name', - 'version', - 'require', - 'require-dev', - 'conflict', - 'replace', - 'provide', - 'minimum-stability', - 'prefer-stable', - 'repositories', - 'extra', - ); - - $relevantContent = array(); - - foreach (array_intersect($relevantKeys, array_keys($content)) as $key) { - $relevantContent[$key] = $content[$key]; - } - if (isset($content['config']['platform'])) { - $relevantContent['config']['platform'] = $content['config']['platform']; - } - - ksort($relevantContent); - - return md5(json_encode($relevantContent)); - } } diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index b06f2842a..ad6b2c6a3 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -16,6 +16,7 @@ use Composer\Config; use Composer\IO\IOInterface; use Composer\Json\JsonFile; use Composer\Package\Loader\ArrayLoader; +use Composer\Package\Locker; use Composer\Package\Version\VersionGuesser; use Composer\Semver\VersionParser; use Composer\Util\ProcessExecutor; @@ -122,7 +123,7 @@ class PathRepository extends ArrayRepository if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) { $package['dist']['reference'] = trim($output); } else { - $package['dist']['reference'] = sha1($json); + $package['dist']['reference'] = Locker::getContentHash($json); } $package = $this->loader->load($package);