function make_get_data

8.0.x make.utilities.inc make_get_data($data_source)
6.x make.utilities.inc make_get_data($data_source)
7.x make.utilities.inc make_get_data($data_source)
5.x make.utilities.inc make_get_data($data_source)
master make.utilities.inc make_get_data($data_source)

Get data based on the source.

This is a helper function to abstract the retrieval of data, so that it can come from files, STDIN, etc. Currently supports filepath and STDIN.

Parameters

string $data_source: The path to a file, or '-' for STDIN.

Return value

string The raw data as a string.

1 call to make_get_data()
_make_parse_info_file in commands/make/make.utilities.inc
Parse makefile recursively.

File

commands/make/make.utilities.inc, line 509
General utility functions for Drush Make.

Code

function make_get_data($data_source) {
  if ($data_source == '-') {
    // See http://drupal.org/node/499758 before changing this.
    $stdin = fopen('php://stdin', 'r');
    $data = '';
    $has_input = FALSE;

    while ($line = fgets($stdin)) {
      $has_input = TRUE;
      $data .= $line;
    }

    if ($has_input) {
      return $data;
    }
    return FALSE;
  }
  // Local file.
  elseif (!strpos($data_source, '://')) {
    $data = file_get_contents($data_source);
  }
  // Remote file.
  else {
    $file = _make_download_file($data_source);
    $data = file_get_contents($file);
    drush_op('unlink', $file);
  }
  return $data;
}