getMessage()); } } return $info; } /** @noinspection PhpUnused */ public static function from_str($str) { $info = NULL; if ($str) { try { $info = Yaml::parse($str); } catch (Exception $e) { logger('exception: ' . $e->getMessage()); } } return $info; } public static function from_c_comment($file): array|null { $info = NULL; try { $code = file_get_contents($file); } catch (Exception $e) { logger('exception: ' . $e->getMessage()); } // Match and fetch the first C-style comment $result = preg_match("|/\*.*\*/|msU", $code, $matches); if ($result) { $lines = explode("\n", $matches[0]); foreach ($lines as $line) { $line = trim($line, "\t\n\r */"); if ($line != "") { list($k, $v) = array_map("trim", explode(":", $line, 2)); $k = strtolower($k); // multiple lines with the same key are turned into an array if (isset($info[$k])) { if (is_array($info[$k])) { $info[$k][] = $v; } else { $info[$k] = [ $info[$k], $v ]; } } else { $info[$k] = $v; } } } } return $info; } }