/** * Retrieve the PHP_UML_Metamodel_Package object related to a package path * (ie, to a qualified name, like A\B\C). * Relies on the model->$packages, when references are still named * (= before their resolution) * * @param string $path The path to find * * @return PHP_UML_Metamodel_Package The package to find. Null if not found. */ protected function getPackageByPath($path) { $pkg = $this->topPackage; do { list($pos, $first, $path) = PHP_UML_Metamodel_Helper::getPackagePathParts($path); if ($first != '') { $pkg = PHP_UML_Metamodel_Helper::findSubpackageByName($pkg, $first); } if ($pkg === false) { return false; } } while (!($pos === false)); return $pkg; }
/** * Adds an alias to the list of namespace aliases * * @param string $namespace An imported namespace * @param string $alias Alias ("use ... as ...") */ private function addUse($namespace, $alias = '') { if ($alias == '') { list($pos, $first, $alias) = PHP_UML_Metamodel_Helper::getPackagePathParts($namespace, false); } if (!$alias) { $alias = $first; } if (substr($namespace, 0, 1) == self::T_NS_SEPARATOR) { $this->aliases[$alias] = substr($namespace, 1); } else { $this->aliases[$alias] = $namespace; } }
/** * Does the type resolution for a given element in a given package * * @param PHP_UML_Metamodel_Package $pkg The nesting package * @param string &$element The element to resolve, provided as a name * @param PHP_UML_Metamodel_Type $context The context (the nesting class/interface, which * is the only element to know the nesting file) */ private function resolveType(PHP_UML_Metamodel_Package $pkg, &$element, PHP_UML_Metamodel_NamedElement $context) { // Is there a ns separator (\) in it ? list($pos, $first, $last) = PHP_UML_Metamodel_Helper::getPackagePathParts($element, false); if (!($pos === false)) { $tmpPkg = $this->getPackageByPath($first); if ($tmpPkg === false) { self::resolutionWarning($element, $context); $element = null; } else { // Do we know that type? $_o = PHP_UML_Metamodel_Helper::searchTypeIntoPackage($tmpPkg, $last); if (!($_o === false)) { $element = $_o; } else { self::resolutionWarning($element, $context); //$element = null; } } } else { // Is it in the current package? $_o = PHP_UML_Metamodel_Helper::searchTypeIntoPackage($pkg, $element); if (!($_o === false)) { $element = $_o; } else { // Is it in one of the "default" packages? $found = false; foreach ($this->defaultRepo as $itemPkg) { $_o = PHP_UML_Metamodel_Helper::searchTypeIntoPackage($itemPkg, $element); if (!($_o === false)) { $element = $_o; $found = true; break; } } if (!$found) { self::resolutionWarning($element, $context); //$element = null; } } } }