function ComposerIntegrationTest::getContentHash

Same name in other branches
  1. 9 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::getContentHash()
  2. 8.9.x core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::getContentHash()
  3. 11.x core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::getContentHash()

Returns the md5 hash of the sorted content of the composer file.

Parameters

string $composerFileContents The contents of the composer file.:

Return value

string

1 call to ComposerIntegrationTest::getContentHash()
ComposerIntegrationTest::testComposerLockHash in core/tests/Drupal/Tests/ComposerIntegrationTest.php
Tests composer.lock content-hash.

File

core/tests/Drupal/Tests/ComposerIntegrationTest.php, line 221

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

protected 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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.