src/Robo/Common/ComposerMunge.php
public static function mungeFiles($file1, $file2) {
    $default_contents = [];
    $file1_contents = (array) json_decode(file_get_contents($file1), TRUE) + $default_contents;
    $file2_contents = (array) json_decode(file_get_contents($file2), TRUE) + $default_contents;

    $output = self::mergeKeyed($file1_contents, $file2_contents);

    // Ensure that require and require-dev are objects and not arrays.
    if (array_key_exists('require', $output) && is_array($output['require'])) {
      $output['require'] = (object) $output['require'];
    }
    if (array_key_exists('require-dev', $output)&& is_array($output['require-dev'])) {
      $output['require-dev'] = (object) $output['require-dev'];
    }

    $output_json = json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

    return $output_json;
  }
public static function mungeFiles($file1, $file2) {
    $default_contents = [];
    $file1_contents = (array) json_decode(file_get_contents($file1), TRUE) + $default_contents;
    $file2_contents = (array) json_decode(file_get_contents($file2), TRUE) + $default_contents;

    $output = self::mergeKeyed($file1_contents, $file2_contents);

    // Ensure that require and require-dev are objects and not arrays.
    if (array_key_exists('require', $output) && is_array($output['require'])) {
      $output['require'] = (object) $output['require'];
    }
    if (array_key_exists('require-dev', $output)&& is_array($output['require-dev'])) {
      $output['require-dev'] = (object) $output['require-dev'];
    }

    $output_json = json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

    return $output_json;
  }
public static function mungeFiles ( $ file1 , $ file2 ) { $ default_contents = [ ] ; $ file1_contents = ( array ) json_decode ( file_get_contents ( $ file1 ) , TRUE ) + $ default_contents ; $ file2_contents = ( array ) json_decode ( file_get_contents ( $ file2 ) , TRUE ) + $ default_contents ; $ output = self :: mergeKeyed ( $ file1_contents , $ file2_contents ) ; // Ensure that require and require-dev are objects and not arrays. if ( array_key_exists ( 'require' , $ output ) && is_array ( $ output [ 'require' ] ) ) { $ output [ 'require' ] = ( object ) $ output [ 'require' ] ; } if ( array_key_exists ( 'require-dev' , $ output ) && is_array ( $ output [ 'require-dev' ] ) ) { $ output [ 'require-dev' ] = ( object ) $ output [ 'require-dev' ] ; } $ output_json = json_encode ( $ output , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ; return $ output_json ; }
Selectively merges parts of two composer.json files.

@param string $file1
The file path to the first composer.json file.
@param string $file2
The file path to the second composer.json file.

@return string
The new, merged composer.json contents.
Selectively merges parts of two composer . json files .