Created
September 13, 2016 08:00
-
-
Save hyperius/fcf863ed24557422d2e5069ebc0e1140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = file_get_contents(__DIR__ . '/composer.json'); | |
printf( | |
" \"hash\": \"%s\",\n \"content-hash\": \"%s\",\n", | |
md5($content), | |
getContentHash($content) | |
); | |
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment