/** * @param \ReflectionClass|string * @return self */ public static function from($from) { $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from); if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) { $class = new static('anonymous'); } else { $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName())); } $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class'); $class->final = $from->isFinal() && $class->type === 'class'; $class->abstract = $from->isAbstract() && $class->type === 'class'; $class->implements = $from->getInterfaceNames(); $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array(); if ($from->getParentClass()) { $class->extends = $from->getParentClass()->getName(); $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames()); } foreach ($from->getProperties() as $prop) { if ($prop->getDeclaringClass()->getName() === $from->getName()) { $class->properties[$prop->getName()] = Property::from($prop); } } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass()->getName() === $from->getName()) { $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace); } } return $class; }
/** * @param \ReflectionClass|string * @return self */ public static function from($from) { $from = $from instanceof \ReflectionClass ? $from : new \ReflectionClass($from); $class = new static($from->getShortName()); $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class'); $class->final = $from->isFinal() && $class->type === 'class'; $class->abstract = $from->isAbstract() && $class->type === 'class'; $class->implements = $from->getInterfaceNames(); $class->documents = preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")); $namespace = $from->getNamespaceName(); if ($from->getParentClass()) { $class->extends = $from->getParentClass()->getName(); if ($namespace) { $class->extends = Strings::startsWith($class->extends, "{$namespace}\\") ? substr($class->extends, strlen($namespace) + 1) : '\\' . $class->extends; } $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames()); } if ($namespace) { foreach ($class->implements as &$interface) { $interface = Strings::startsWith($interface, "{$namespace}\\") ? substr($interface, strlen($namespace) + 1) : '\\' . $interface; } } foreach ($from->getProperties() as $prop) { if ($prop->getDeclaringClass() == $from) { // intentionally == $class->properties[$prop->getName()] = Property::from($prop); } } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass() == $from) { // intentionally == $class->methods[$method->getName()] = Method::from($method); } } return $class; }
/** * @return Code\Method */ public function getCode() { return PointcutMethod::expandTypeHints($this->method, Code\Method::from($this->method)); }