Add a set of namespaces to a list of class names

@param string|array $names
@param array $namespaces
@param array $logs Passed by reference
@return array
198937
protected function _addNamespaces($names, array $namespaces, array &$logs = array())
    {
        if (!is_array($names)) {
            $names = array($names);
        }
        $return_names = array();
        foreach ($names as $_name) {
            foreach ($namespaces as $_namespace) {
                if (CodeHelper::namespaceExists($_namespace)) {
                    $tmp_namespace = rtrim(TextHelper::toCamelCase($_namespace), '\\').'\\';
                    $return_names[] = $tmp_namespace.str_replace($tmp_namespace, '', TextHelper::toCamelCase($_name));
                } else {
                    $logs[] = $this->_getErrorMessage('Namespace "%s" not found!', $_namespace);
                }
            }
        }
        return $return_names;
    }
1174923
public void addNameSpace(Set<String> names) {
		for (String name : names) {
			this.nameSpace.add(name.replace('.', '/'));
		}
	}
1157320
protected static function _toArray($xml, &$parentData, $ns, $namespaces)
    {
        $data = [];

        foreach ($namespaces as $namespace) {
            foreach ($xml->attributes($namespace, true) as $key => $value) {
                if (!empty($namespace)) {
                    $key = $namespace . ':' . $key;
                }
                $data['@' . $key] = (string)$value;
            }

            foreach ($xml->children($namespace, true) as $child) {
                static::_toArray($child, $data, $namespace, $namespaces);
            }
        }

        $asString = trim((string)$xml);
        if (empty($data)) {
            $data = $asString;
        } elseif (strlen($asString) > 0) {
            $data['@'] = $asString;
        }

        if (!empty($ns)) {
            $ns .= ':';
        }
        $name = $ns . $xml->getName();
        if (isset($parentData[$name])) {
            if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
                $parentData[$name] = [$parentData[$name]];
            }
            $parentData[$name][] = $data;
        } else {
            $parentData[$name] = $data;
        }
    }
342066
protected function expandNames(array & $tokens, NamespaceContext $context)
	{
		// Expand name if one of these tokens is found before the name.
		static $beforeTokens = [
			T_NEW, // Object instantiation
			T_INSTANCEOF // Instanceof check
		];
		
		// Expand name if one of these tokens is found after the name
		static $afterTokens = [
			T_DOUBLE_COLON, // Static access or class constant lookup
			T_VARIABLE // Type-hinted function / method argument
		];
		
		$count = count($tokens) - 1;
		$buffer = '';
		
		for($size = count($tokens), $i = 0; $i < $size; $i++)
		{
			if(is_array($tokens[$i]) && ($tokens[$i][0] == T_STRING || $tokens[$i][0] == T_NS_SEPARATOR))
			{
				$pos = $i;
				$before = $pos - 1;
				$after = $pos + 1;
				$name = $tokens[$i][1];
				
				$i++;
				
				// Read name with namespace parts if needed.
				for(; $i < $size; $i++)
				{
					if(is_array($tokens[$i]))
					{
						switch($tokens[$i][0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								continue 2;
							case T_NS_SEPARATOR:
							case T_STRING:
								$name .= $tokens[$i][1];
								continue 2;
						}
					}
					
					break;
				}
				
				// Read first significant token before the name.
				$prev = NULL;
				while($before >= 0)
				{
					$prev = $tokens[$before];
					
					if(is_array($prev))
					{
						switch($prev[0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								$before--;
								continue 2;
						}
					}
					
					break;
				}
				
				// Read first significant token after the name.
				$next = NULL;
				while($after < $count)
				{
					$next = $tokens[$after];
						
					if(is_array($next))
					{
						switch($next[0])
						{
							case T_WHITESPACE:
							case T_COMMENT:
							case T_DOC_COMMENT:
								$after++;
								continue 2;
						}
					}
						
					break;
				}
				
				// Expand names as needed.
				$expand = false;
				
				if(is_array($prev) && in_array($prev[0], $beforeTokens))
				{
					$expand = true;
				}
				
				if(is_array($next) && in_array($next[0], $afterTokens))
				{
					$expand = true;
				}
				
				if($expand)
				{
					$buffer .= '\\' . ltrim($context->lookup($name), '\\');
				}
				else
				{
					$buffer .= $name;
				}
			}
			
			if(is_array($tokens[$i]))
			{
				$buffer .= $tokens[$i][1];
			}
			else
			{
				$buffer .= $tokens[$i];
			}
		}
		
		return $buffer;
	}
1223632
public function setNamespaceAliases(array $namespace_aliases)
    {
        $this->namespace_aliases = array();
        foreach ($namespace_aliases as $alias => $fqnn) {
            $this->setNamespaceAlias($alias, $fqnn);
        }
        return $this;
    }
1021425
public static function extractNamespaces(ClassLoader $classLoader) {
    $namespaces = [];
    foreach ($classLoader->getPrefixes() as $namespace => $directories) {
      $namespaces[$namespace] = $directories[0];
    }
    foreach ($classLoader->getPrefixesPsr4() as $namespace => $directories) {
      $namespaces[$namespace] = $directories[0];
    }
    return new \ArrayIterator($namespaces);
  }
1276177
public static function add_namespaces(array $namespaces, $prepend = false)
	{
		if ( ! $prepend)
		{
			static::$namespaces = array_merge(static::$namespaces, $namespaces);
		}
		else
		{
			static::$namespaces = $namespaces + static::$namespaces;
		}
	}
134687
public function add($alias, array $namespace)
    {
        $alias = Input::checkAlias($alias);
        $props = $this->getNamespace($alias, true);

        foreach ($namespace as $ns) {
            $group = $this->getNamespaceGroup($ns);

            if ('any' === $group) {
                $props = ['any' => true];
                break;
            } else {
                // trim trailing * from path pattern
                $ns = 'path' === $group ? rtrim($ns, '*') : $ns;
                $props[$group][] = $ns;
            }
        }

        $this->setNamespace($alias, $props);
    }
725388
private function buildNamespace(File $file, Namespace_ $namespace): void
    {
        foreach ($file->getClasses() as $class) {
            if ($namespace->getFqsen() . '\\' . $class->getName() === (string) $class->getFqsen()) {
                $namespace->addClass($class->getFqsen());
            }
        }

        foreach ($file->getInterfaces() as $interface) {
            if ($namespace->getFqsen() . '\\' . $interface->getName() === (string) $interface->getFqsen()) {
                $namespace->addInterface($interface->getFqsen());
            }
        }

        foreach ($file->getFunctions() as $function) {
            if ($namespace->getFqsen() . '\\' . $function->getName() . '()' === (string) $function->getFqsen()) {
                $namespace->addFunction($function->getFqsen());
            }
        }

        foreach ($file->getConstants() as $constant) {
            if ($namespace->getFqsen() . '::' . $constant->getName() === (string) $constant->getFqsen()) {
                $namespace->addConstant($constant->getFqsen());
            }
        }

        foreach ($file->getTraits() as $trait) {
            if ($namespace->getFqsen() . '\\' . $trait->getName() === (string) $trait->getFqsen()) {
                $namespace->addTrait($trait->getFqsen());
            }
        }
    }
1000441
public function registerNamespace($namespace, $paths)
    {
        if (false === isset($this->_namespaces[$namespace])) {
            $this->_namespaces[$namespace] = array();
        }

        $this->_namespaces[$namespace] = array_merge($this->_namespaces[$namespace], (array) $paths);

        return $this;
    }
527286
private function writeNamespace($namespace, $files)
    {
        // Initialise:
        
        $result = true;
        
        // Check Namespace Change:
        
        if ($namespace == $this->getConfig('default-app-namespace')) {
            return $result;
        }
        
        // Check Parameters:
        
        if ($namespace && is_array($files)) {
            
            // Iterate Files:
            
            foreach ($files as $file => $escape) {
                
                // Attempt to Process File:
                
                try {
                    
                    // Read File Contents:
                    
                    $contents = file_get_contents($file);
                    
                    // Replace Namespace in Contents:
                    
                    $contents = $this->replaceNamespace($contents, $namespace, $escape);
                    
                    // Write File Contents:
                    
                    file_put_contents($file, $contents);
                    
                    // Define Status:
                    
                    $status = 'success';
                    
                } catch (ErrorException $e) {
                    
                    // Write Debug Info:
                    
                    $this->io()->writeError(
                        sprintf(
                            '<warning>Exception: %s</warning>',
                            $e->getMessage()
                        ),
                        true,
                        IOInterface::DEBUG
                    );
                    
                    // Define Result:
                    
                    $result = false;
                    
                    // Define Status:
                    
                    $status = 'failure';
                    
                }
                
                // Output Status:
                
                $this->io()->write(
                    sprintf(
                        '[%s] %s',
                        $this->color($this->getConfig("text-file-{$status}"), $this->getConfig("fg-{$status}")),
                        $this->color("Writing namespace to '{$file}'...", $this->getConfig('fg-writing'))
                    )
                );
                
            }
            
        }
        
        // Answer Result:
        
        return $result;
    }
976362
public function addNamespace($name)
    {
        if (!Arr::in($name, self::$_namespace)) {
            self::$_namespace[] = $name;
            return true;
        }

        return false;
    }
884387
private function fetchNamespaces (NamespaceRegistry $entryNamespaces) : array
    {
        $namespaces = [];

        foreach ($entryNamespaces as $namespace => $path)
        {
            $namespaces[$namespace] = $this->makePathRelative($path);
        }

        return $namespaces;
    }
657739
public function namespaced($namespace, Closure $callback)
    {
        $attributes = [];

        if (!empty($namespace) && $namespace != '\\') {
            $attributes['namespace'] = $namespace;
        }
        $attributes['middleware'] = ['antares', LoggerMiddleware::class];

        $this->group('antares/foundation', 'antares', $attributes, $callback);
    }
339294
protected function loadNamespaces(){
        $namespaces = [];
        foreach($this->queryXPath('namespace::*') as $node){
            $name = preg_replace('/xmlns(:)?/', '', $node->nodeName);
            if($name !== 'xml'){//always removed the implicit xml namespace
                $namespaces[$name] = $node->nodeValue;
            }
        }
        ksort($namespaces);
        foreach($namespaces as $name => $uri){
            $this->item->addNamespace($name, $uri);
        }
    }
917747
private static function classBelongsToNamespace($className, $namespaces)
    {
        $belongsToNamespace = false;
        $check = array_values($namespaces);
        $lcClassName = strtolower(ltrim($className, '\\'));

        foreach ($check as $namespace) {
            if (false !== strpos($lcClassName, strtolower($namespace))) {
                $belongsToNamespace = true;
                continue;
            }
        }
        return $belongsToNamespace;
    }
1326943
static public function findClass($name, $type=null, $namespaces=null)
	{
	    $name = StringHelper::toClassName($name);
	    if (!$namespaces && strpos($name, '\\') !== false && class_exists($name)) {
	        return $name;
	    }
	    
	    $class_names = [];
	    if (!empty($type)) {
	        $type = StringHelper::toCamelCase($type);
	        if ($pos = strpos($name, '\\')) {
	            $class_names[] = $type . '\\' . $name . $type;
	            $class_names[] = $type . '\\' . $name;
	            
	            $name = substr($name, 0, $pos) . '\\' . $type . '\\' . substr($name, $pos+1);
	        } else {
	            $name = $type . '\\' . $name;
	        }
	        $class_names[] = $name;
	        $class_names[] = $name . $type;
		} else {
		    $class_names[] = $name;
		}
		
		if ($namespaces) {
            $namespaces = (array)static::formatNamespace($namespaces);
		} else {
            //$namespaces = array_unique(array_merge((array)$namespaces, static::getNamespaces()));
		    $namespaces = static::getNamespaces();
		}
		
		foreach ($namespaces as $nss) {
		    foreach ($class_names as $class) { 
		        if (class_exists($nss . $class)) {
		            return $nss . $class;
		        }
		    }
		}
		
		return null;
	}