Skip to content

Instantly share code, notes, and snippets.

@hyperius
Created September 13, 2016 08:00
Show Gist options
  • Save hyperius/fcf863ed24557422d2e5069ebc0e1140 to your computer and use it in GitHub Desktop.
Save hyperius/fcf863ed24557422d2e5069ebc0e1140 to your computer and use it in GitHub Desktop.
<?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