function DebugClassLoader::parsePhpDoc
Parameters
\ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflector:
1 call to DebugClassLoader::parsePhpDoc()
- DebugClassLoader::checkAnnotations in vendor/
symfony/ error-handler/ DebugClassLoader.php
File
-
vendor/
symfony/ error-handler/ DebugClassLoader.php, line 1189
Class
- DebugClassLoader
- Autoloader checking if the class is really defined in the file found.
Namespace
Symfony\Component\ErrorHandlerCode
private function parsePhpDoc(\Reflector $reflector) : array {
if (!($doc = $reflector->getDocComment())) {
return [];
}
$tagName = '';
$tagContent = '';
$tags = [];
foreach (explode("\n", substr($doc, 3, -2)) as $line) {
$line = ltrim($line);
$line = ltrim($line, '*');
if ('' === ($line = trim($line))) {
if ('' !== $tagName) {
$tags[$tagName][] = $tagContent;
}
$tagName = $tagContent = '';
continue;
}
if ('@' === $line[0]) {
if ('' !== $tagName) {
$tags[$tagName][] = $tagContent;
$tagContent = '';
}
if (preg_match('{^@([-a-zA-Z0-9_:]++)(\\s|$)}', $line, $m)) {
$tagName = $m[1];
$tagContent = str_replace("\t", ' ', ltrim(substr($line, 2 + \strlen($tagName))));
}
else {
$tagName = '';
}
}
elseif ('' !== $tagName) {
$tagContent .= ' ' . str_replace("\t", ' ', $line);
}
}
if ('' !== $tagName) {
$tags[$tagName][] = $tagContent;
}
foreach ($tags['method'] ?? [] as $i => $method) {
unset($tags['method'][$i]);
$parts = preg_split('{(\\s++|\\((?:[^()]*+|(?R))*\\)(?: *: *[^ ]++)?|<(?:[^<>]*+|(?R))*>|\\{(?:[^{}]*+|(?R))*\\})}', $method, -1, \PREG_SPLIT_DELIM_CAPTURE);
$returnType = '';
$static = 'static' === $parts[0];
for ($i = $static ? 2 : 0; null !== ($p = $parts[$i] ?? null); $i += 2) {
if (\in_array($p, [
'',
'|',
'&',
'callable',
], true) || \in_array(substr($returnType, -1), [
'|',
'&',
], true)) {
$returnType .= trim($parts[$i - 1] ?? '') . $p;
continue;
}
$signature = '(' === ($parts[$i + 1][0] ?? '(') ? $parts[$i + 1] ?? '()' : null;
if (null === $signature && '' === $returnType) {
$returnType = $p;
continue;
}
if ($static && 2 === $i) {
$static = false;
$returnType = 'static';
}
if (\in_array($description = trim(implode('', \array_slice($parts, 2 + $i))), [
'',
'.',
], true)) {
$description = null;
}
elseif (!preg_match('/[.!]$/', $description)) {
$description .= '.';
}
$tags['method'][$p] = [
$static,
$returnType,
$signature ?? '()',
$description,
];
break;
}
}
foreach ($tags['param'] ?? [] as $i => $param) {
unset($tags['param'][$i]);
if (\strlen($param) !== strcspn($param, '<{(')) {
$param = preg_replace('{\\(([^()]*+|(?R))*\\)(?: *: *[^ ]++)?|<([^<>]*+|(?R))*>|\\{([^{}]*+|(?R))*\\}}', '', $param);
}
if (false === ($i = strpos($param, '$'))) {
continue;
}
$type = 0 === $i ? '' : rtrim(substr($param, 0, $i), ' &');
$param = substr($param, 1 + $i, (strpos($param, ' ', $i) ?: 1 + $i + \strlen($param)) - $i - 1);
$tags['param'][$param] = $type;
}
foreach ([
'var',
'return',
] as $k) {
if (null === ($v = $tags[$k][0] ?? null)) {
continue;
}
if (\strlen($v) !== strcspn($v, '<{(')) {
$v = preg_replace('{\\(([^()]*+|(?R))*\\)(?: *: *[^ ]++)?|<([^<>]*+|(?R))*>|\\{([^{}]*+|(?R))*\\}}', '', $v);
}
$tags[$k] = substr($v, 0, strpos($v, ' ') ?: \strlen($v)) ?: null;
}
return $tags;
}