function _make_determine_format

8.0.x make.utilities.inc _make_determine_format($data)
7.x make.utilities.inc _make_determine_format($data)
master make.utilities.inc _make_determine_format($data)

Given data from stdin, determine format.

Return value

array|bool Returns parsed data if it matches any known format.

2 calls to _make_determine_format()
makeMakefileCase::testNoCoreMakefileParsing in tests/makeTest.php
Test that files without a core attribute are correctly identified.
_make_parse_info_file in commands/make/make.utilities.inc
Parse makefile recursively.

File

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

Code

function _make_determine_format($data) {
  // Most .make files will have a `core` attribute. Use this to determine
  // the format.
  if (preg_match('/^\s*core:/m', $data)) {
    $parsed = ParserYaml::parse($data);
    $parsed['format'] = 'yaml';
    return $parsed;
  }
  elseif (preg_match('/^\s*core\s*=/m', $data)) {
    $parsed = ParserIni::parse($data);
    $parsed['format'] = 'ini';
    return $parsed;
  }

  // If the .make file did not have a core attribute, it is being included
  // by another .make file. Test YAML first to avoid segmentation faults from
  // preg_match in INI parser.
  $yaml_parse_exception = FALSE;
  try {
    if ($parsed = ParserYaml::parse($data)) {
      $parsed['format'] = 'yaml';
      return $parsed;
    }
  }
  catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
    // Note that an exception was thrown, and display after .ini parsing.
    $yaml_parse_exception = $e;
  }

  // Try INI format.
  if ($parsed = ParserIni::parse($data)) {
    $parsed['format'] = 'ini';
    return $parsed;
  }

  if ($yaml_parse_exception) {
    throw $e;
  }

  return drush_set_error('MAKE_STDIN_ERROR', dt('Unknown make file format'));
}