/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if (!$parent instanceof ReflectionFileNamespace) { throw new Exception\ParseException($this, $tokenStream, 'The parent object has to be an instance of TokenReflection\\ReflectionFileNamespace.', Exception\ParseException::INVALID_PARENT); } $this->namespaceName = $parent->getName(); $this->aliases = $parent->getNamespaceAliases(); return parent::processParent($parent, $tokenStream); }
/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if ($parent instanceof ReflectionFileNamespace) { $this->namespaceName = $parent->getName(); $this->aliases = $parent->getNamespaceAliases(); } elseif ($parent instanceof ReflectionClass) { $this->declaringClassName = $parent->getName(); } else { throw new Exception\ParseException($this, $tokenStream, sprintf('Invalid parent reflection provided: "%s".', get_class($parent)), Exception\ParseException::INVALID_PARENT); } return parent::processParent($parent, $tokenStream); }
/** * Reduces a reference in a given context * * @access public * @param string $reference The reference to reduce * @param IReflection $context The reflection context for reduction * @return string The reduced reference */ public function reduce($reference, IReflection $context) { $member = NULL; if (strpos($reference, '::') !== FALSE) { list($reference, $member) = explode('::', $reference); } $reduction = $reference; if (!self::isStandardType($reference)) { $parts = explode('\\', $reduction); $reduction = '\\' . $reduction; $aliases = array_merge(['' => $context->getName()], $context->getNamespaceAliases()); foreach ($aliases as $alias => $namespace) { $namespace_parts = explode('\\', $namespace); if (count($parts) < count($namespace_parts)) { continue; } if ($namespace_parts == array_slice($parts, 0, count($namespace_parts))) { $reduction = implode('\\', !$alias ? array_slice($parts, count($namespace_parts)) : array_merge([$alias], array_slice($parts, count($namespace_parts)))); break; } } } return $member ? implode('::', [$reduction, $member]) : $reduction; }