X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FInfoToYAML.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FInfoToYAML.php;h=2d0dca4f44522843c9624287e12a70f1c6fe5d87;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hp=0000000000000000000000000000000000000000;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35;p=yaffs-website diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/InfoToYAML.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/InfoToYAML.php new file mode 100644 index 000000000..2d0dca4f4 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/InfoToYAML.php @@ -0,0 +1,97 @@ +getPath('.info'); + + $info = self::parseInfo($info_file); + $info['core'] = '8.x'; + $info['type'] = 'module'; + + if (isset($info['dependencies'])) { + // array_values() is called in order to reindex the array. Issue #2340207 + $info['dependencies'] = array_values(array_diff($info['dependencies'], ['ctools', 'list'])); + } + + unset($info['files'], $info['configure'], $info['datestamp'], $info['version'], $info['project']); + $this->writeInfo($target, 'info', $info); + } + + /** + * Parses a D7 info file. This is copied straight outta the D7 function + * drupal_parse_info_format(). + */ + public static function parseInfo($file) { + $info = []; + $constants = get_defined_constants(); + $data = file_get_contents($file); + + if (preg_match_all(' + @^\s* # Start at the beginning of a line, ignoring leading whitespace + ((?: + [^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets, + \[[^\[\]]*\] # unless they are balanced and not nested + )+?) + \s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space) + (?: + ("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes + (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes + ([^\r\n]*?) # Non-quoted string + )\s*$ # Stop at the next end of a line, ignoring trailing whitespace + @msx', $data, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + // Fetch the key and value string. + $i = 0; + foreach (array('key', 'value1', 'value2', 'value3') as $var) { + $$var = isset($match[++$i]) ? $match[$i] : ''; + } + $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3; + + // Parse array syntax. + $keys = preg_split('/\]?\[/', rtrim($key, ']')); + $last = array_pop($keys); + $parent = &$info; + + // Create nested arrays. + foreach ($keys as $key) { + if ($key == '') { + $key = count($parent); + } + if (!isset($parent[$key]) || !is_array($parent[$key])) { + $parent[$key] = array(); + } + $parent = &$parent[$key]; + } + + // Handle PHP constants. + if (isset($constants[$value])) { + $value = $constants[$value]; + } + + // Insert actual value. + if ($last == '') { + $last = count($parent); + } + $parent[$last] = $value; + } + } + + return $info; + } + +}