Example #1
0
 /**
  * Analyzes the given type and returns the FQCN variant.
  *
  * When a type is provided this method checks whether it is not a keyword or
  * Fully Qualified Class Name. If so it will use the given namespace and
  * aliases to expand the type to a FQCN representation.
  *
  * This method only works as expected if the namespace and aliases are set;
  * no dynamic reflection is being performed here.
  *
  * @param string $type The relative or absolute type.
  *
  * @uses getNamespace to determine with what to prefix the type name.
  * @uses getNamespaceAliases to check whether the first part of the relative
  *     type name should not be replaced with another namespace.
  *
  * @return string
  */
 protected function expand($type)
 {
     $type = trim($type);
     if (!$type) {
         return '';
     }
     if ($this->isTypeAnArray($type)) {
         return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
     }
     if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) {
         $type_parts = explode(self::OPERATOR_NAMESPACE, $type, 2);
         $namespace_aliases = $this->context->getNamespaceAliases();
         // if the first segment is not an alias; prepend namespace name and
         // return
         if (!isset($namespace_aliases[$type_parts[0]])) {
             $namespace = $this->context->getNamespace();
             if ('' !== $namespace) {
                 $namespace .= self::OPERATOR_NAMESPACE;
             }
             return self::OPERATOR_NAMESPACE . $namespace . $type;
         }
         $type_parts[0] = $namespace_aliases[$type_parts[0]];
         $type = implode(self::OPERATOR_NAMESPACE, $type_parts);
     }
     return $type;
 }
Example #2
0
 public function getNamespace()
 {
     return $this->context->getNamespace();
 }