/** * Magic __isset method. * * @param string $key Variable name * @return boolean */ public final function __isset($key) { return ReflectionBase::exists($this, $key); }
/** * Constructor. * * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * @param \TokenReflection\Broker $broker Reflection broker * @param \TokenReflection\IReflection $parent Parent reflection object * @throws \TokenReflection\Exception\ParseException If an empty token stream was provided */ public final function __construct(Stream $tokenStream, Broker $broker, IReflection $parent = null) { if (0 === $tokenStream->count()) { throw new Exception\ParseException($this, $tokenStream, 'Reflection token stream must not be empty.', Exception\ParseException::INVALID_ARGUMENT); } parent::__construct($tokenStream, $broker, $parent); }
/** * Inherits annotations from parent classes/methods/properties if needed. * * @throws \TokenReflection\Exception\RuntimeException If unsupported reflection was used. */ private function inheritAnnotations() { if ($this->reflection instanceof ReflectionClass) { $declaringClass = $this->reflection; } elseif ($this->reflection instanceof ReflectionMethod || $this->reflection instanceof ReflectionProperty) { $declaringClass = $this->reflection->getDeclaringClass(); } $parents = array_filter(array_merge(array($declaringClass->getParentClass()), $declaringClass->getOwnInterfaces()), function ($class) { return $class instanceof ReflectionClass; }); // In case of properties and methods, look for a property/method of the same name and return // and array of such members. $parentDefinitions = array(); if ($this->reflection instanceof ReflectionProperty) { $name = $this->reflection->getName(); foreach ($parents as $parent) { if ($parent->hasProperty($name)) { $parentDefinitions[] = $parent->getProperty($name); } } $parents = $parentDefinitions; } elseif ($this->reflection instanceof ReflectionMethod) { $name = $this->reflection->getName(); foreach ($parents as $parent) { if ($parent->hasMethod($name)) { $parentDefinitions[] = $parent->getMethod($name); } } $parents = $parentDefinitions; } if (false === $this->docComment) { // Inherit the entire docblock foreach ($parents as $parent) { $annotations = $parent->getAnnotations(); if (!empty($annotations)) { $this->annotations = $annotations; break; } } } else { if (isset($this->annotations[self::LONG_DESCRIPTION]) && false !== stripos($this->annotations[self::LONG_DESCRIPTION], '{@inheritdoc}')) { // Inherit long description foreach ($parents as $parent) { if ($parent->hasAnnotation(self::LONG_DESCRIPTION)) { $this->annotations[self::LONG_DESCRIPTION] = str_ireplace('{@inheritdoc}', $parent->getAnnotation(self::LONG_DESCRIPTION), $this->annotations[self::LONG_DESCRIPTION]); break; } } $this->annotations[self::LONG_DESCRIPTION] = str_ireplace('{@inheritdoc}', '', $this->annotations[self::LONG_DESCRIPTION]); } if (isset($this->annotations[self::SHORT_DESCRIPTION]) && false !== stripos($this->annotations[self::SHORT_DESCRIPTION], '{@inheritdoc}')) { // Inherit short description foreach ($parents as $parent) { if ($parent->hasAnnotation(self::SHORT_DESCRIPTION)) { $this->annotations[self::SHORT_DESCRIPTION] = str_ireplace('{@inheritdoc}', $parent->getAnnotation(self::SHORT_DESCRIPTION), $this->annotations[self::SHORT_DESCRIPTION]); break; } } $this->annotations[self::SHORT_DESCRIPTION] = str_ireplace('{@inheritdoc}', '', $this->annotations[self::SHORT_DESCRIPTION]); } } // In case of properties check if we need and can inherit the data type if ($this->reflection instanceof ReflectionProperty && empty($this->annotations['var'])) { foreach ($parents as $parent) { if ($parent->hasAnnotation('var')) { $this->annotations['var'] = $parent->getAnnotation('var'); break; } } } if ($this->reflection instanceof ReflectionMethod) { if (0 !== $this->reflection->getNumberOfParameters() && (empty($this->annotations['param']) || count($this->annotations['param']) < $this->reflection->getNumberOfParameters())) { // In case of methods check if we need and can inherit parameter descriptions $params = isset($this->annotations['param']) ? $this->annotations['param'] : array(); $complete = false; foreach ($parents as $parent) { if ($parent->hasAnnotation('param')) { $parentParams = array_slice($parent->getAnnotation('param'), count($params)); while (!empty($parentParams) && !$complete) { array_push($params, array_shift($parentParams)); if (count($params) === $this->reflection->getNumberOfParameters()) { $complete = true; } } } if ($complete) { break; } } if (!empty($params)) { $this->annotations['param'] = $params; } } // And check if we need and can inherit the return and throws value foreach (array('return', 'throws') as $paramName) { if (!isset($this->annotations[$paramName])) { foreach ($parents as $parent) { if ($parent->hasAnnotation($paramName)) { $this->annotations[$paramName] = $parent->getAnnotation($paramName); break; } } } } } }
protected function getTrimmedAnnotations(ReflectionBase $object) { //@BUG For some reason long_description and short_description have whitespace in the character keys $annotations = []; foreach ($object->getAnnotations() as $_id => $_value) { //echo $directory; $annotations[trim($_id)] = $_value; } return $annotations; }