public static function getRequirements($className, $methodName)
{
$reflector = new ReflectionClass($className);
$docComment = $reflector->getDocComment();
$reflector = new ReflectionMethod($className, $methodName);
$docComment .= "\n" . $reflector->getDocComment();
$requires = [];
if ($count = preg_match_all(self::REGEX_REQUIRES_OS, $docComment, $matches)) {
$requires['OS'] = sprintf('/%s/i', addcslashes($matches['value'][$count - 1], '/'));
}
if ($count = preg_match_all(self::REGEX_REQUIRES_VERSION, $docComment, $matches)) {
for ($i = 0; $i < $count; $i++) {
$requires[$matches['name'][$i]] = ['version' => $matches['version'][$i], 'operator' => $matches['operator'][$i]];
}
}
// https://bugs.php.net/bug.php?id=63055
$matches = [];
if ($count = preg_match_all(self::REGEX_REQUIRES, $docComment, $matches)) {
for ($i = 0; $i < $count; $i++) {
$name = $matches['name'][$i] . 's';
if (!isset($requires[$name])) {
$requires[$name] = [];
}
$requires[$name][] = $matches['value'][$i];
if (empty($matches['version'][$i]) || $name != 'extensions') {
continue;
}
$requires['extension_versions'][$matches['value'][$i]] = ['version' => $matches['version'][$i], 'operator' => $matches['operator'][$i]];
}
}
return $requires;
}