public static function getMagicMethods($class)
{
$rc = new \ReflectionClass($class);
preg_match_all('~^
[ \\t*]* @method [ \\t]+
(?: [^\\s(]+ [ \\t]+ )?
(set|get|is|add) ([A-Z]\\w*)
(?: ([ \\t]* \\() [ \\t]* ([^)$\\s]*) )?
()~mx', (string) $rc->getDocComment(), $matches, PREG_SET_ORDER);
$methods = [];
foreach ($matches as list(, $op, $prop, $bracket, $type)) {
if ($bracket !== '(') {
trigger_error("Bracket must be immediately after @method {$op}{$prop}() in class {$class}.", E_USER_WARNING);
}
$name = $op . $prop;
$prop = strtolower($prop[0]) . substr($prop, 1) . ($op === 'add' ? 's' : '');
if ($rc->hasProperty($prop) && ($rp = $rc->getProperty($prop)) && !$rp->isStatic()) {
$rp->setAccessible(TRUE);
if ($op === 'get' || $op === 'is') {
$type = NULL;
$op = 'get';
} elseif (!$type && preg_match('#@var[ \\t]+(\\S+)' . ($op === 'add' ? '\\[\\]#' : '#'), (string) $rp->getDocComment(), $m)) {
$type = $m[1];
}
if ($rc->inNamespace() && preg_match('#^[A-Z]\\w+(\\[|\\||\\z)#', (string) $type)) {
$type = $rc->getNamespaceName() . '\\' . $type;
}
$methods[$name] = [$op, $rp, $type];
}
}
return $methods;
}