Validate namespace

@param string $namespace

@return bool
558375
public function validateNamespace($namespace)
    {
        if (empty($namespace)) {
            $this->addError('namespace', 'Namespace cannot be empty');
            return false;
        }

        if (substr($namespace, 0, 1) !== '/') {
            $this->addError('namespace', 'The namespace have to start with the character "/".');
            return false;
        }

        if (strlen($namespace) > 255) {
            $this->addError('namespace', 'Namespace length cannot exceed 255 chars');
            return false;
        }

        return true;
    }
131169
protected function getRulesForCustomFields($namespace)
    {
        $rules      = [];
        $brand      = antares('memory')->get('brand.default');
        $collection = app('antares.customfields.model.view')->query()->where('namespace', $namespace)->where('brand_id', $brand)->get();
        if ($collection->isEmpty()) {
            return $rules;
        }
        $collection->each(function($item) use(&$rules) {

            $validators = [];
            $item->config->each(function($config) use(&$validators) {
                $name          = $config->validator->name;
                $name == 'regex' && $config->value = implode('', ['[', $config->value, ']']);
                $rule          = ((!is_null($config->value) ? ':' . $config->value : ''));
                $validators[]  = $name . $rule;
            });

            $rules[$item->name] = $validators;
        });
        return $rules;
    }
509790
public static function classExists($className, $namespace)
    {
        if (class_exists($className)) {
            return $className;
        }

        // add namespace
        $className = sprintf('%s%s', static::getFormatNamespace($namespace, true), $className);

        if (class_exists($className)) {
            return $className;
        }

        return false;
    }
464475
public function canHandle($type, $namespace)
   {
      # no type; namespace must match
      if ($type === null) {
         if ($this->namespace === null || $namespace !== $this->namespace) {
            return false;
         }
      }
      else {
         if ($this->type !== $type) {
            return false;
         }
         else if ($namespace !== null && $this->namespace !== $namespace) {
            return false;
         }
         else if ($namespace === null && $this->namespace !== null) {
            return false;
         }
      }

      return true;
   }
1106048
private function namespace_to_dir( $namespace ) {
		$namespace = ltrim( $namespace, '\\' );
		$dir       = null;
		if ( preg_match( "#\A{$this->app->define->plugin_namespace}#", $namespace ) ) {
			$namespace = preg_replace( "#\A{$this->app->define->plugin_namespace}#", '', $namespace );
			$dir       = $this->app->define->plugin_src_dir;
		} elseif ( preg_match( "#\A{$this->app->define->lib_namespace}#", $namespace ) ) {
			$namespace = preg_replace( "#\A{$this->app->define->lib_namespace}#", '', $namespace );
			$dir       = $this->app->define->lib_src_dir;
		}

		if ( isset( $dir ) ) {
			$namespace = ltrim( $namespace, '\\' );
			$namespace = strtolower( $namespace );
			$path      = $dir . DS . str_replace( '\\', DS, $namespace );
			$path      = rtrim( $path, DS );
			if ( is_dir( $path ) ) {
				return $path;
			}
		}

		return false;
	}
117751
private function allAreGlobal(array $namespaces): bool
    {
        foreach ($namespaces as $namespace) {
            if ($namespace->name && $namespace->name->toString() !== '') {
                return false;
            }
        }
        return true;
    }
918637
protected function loadLanguageFileForNamespace($namespace)
    {
        $loadedLocale = $this->request->getLocale();
        $content = $this->languageFileManager->loadTranslationFileContent($namespace, $loadedLocale);
        
        // If the received content is empty return false
        if ($content === false) {
            return false;
        }
        
        $lines = explode(PHP_EOL, $content);
        
        foreach ($lines as $line) {
            $delimiter = strpos($line, ' = ');
            if ($delimiter === false) {
                continue;
            }
            
            $pattern = substr($line, 0, $delimiter);
            $replacement = substr($line, $delimiter + 3);
            
            if (!isset($this->translatedStrings[$namespace]) || !is_array($this->translatedStrings[$namespace])) {
                $this->translatedStrings[$namespace] = array();
            }
            
            $this->translatedStrings[$namespace][$pattern] = $replacement;
        }
    }
533128
public function lookupPrefix( $namespace )
	{
		foreach ( $this->namespaces as $prefix => $value )
		{
			if ( strcasecmp( $namespace, $value ) === 0 ) return $prefix;
		}

		return false;
	}
1325847
public function getPrefixForNamespace( $namespace )
	{
		if (
			  ! isset( $this->cacheNamespaces ) ||
			  count( $this->cacheNamespaces ) != count( $this->instance_namespaces )
		   )
		{
			$this->cacheNamespaces = array_flip( $this->instance_namespaces );
			// If the default namespace is one of the standards ones then the prefix may be missing
			$standardNamespaces = array_flip( XBRL_Constants::$standardPrefixes );
			if ( isset( $this->instance_namespaces[''] ) )
			{
				if ( isset( $standardNamespaces[ $this->instance_namespaces[''] ] ) )
				{
					$this->cacheNamespaces[ $this->instance_namespaces[''] ] = $standardNamespaces[ $this->instance_namespaces[''] ];
				}
			}
		}

		return isset( $this->cacheNamespaces[ $namespace ] )
			? $this->cacheNamespaces[ $namespace ]
			: false;
	}
525134
public static function has(string $name, string $namespace = '*'): bool
    {
        self::initialize();
        return isset($_SESSION[$namespace]) && array_key_exists($name, $_SESSION[$namespace]);
    }
1255814
public function setNamespace($namespace)
    {
        if (!is_string($namespace)) {
            throw new \InvalidArgumentException('The attribute namespace on the class Entity has to be string (' . gettype($namespace) . ('object' === gettype($namespace) ? ' ' . get_class($namespace) : '') . ' given).');
        }

        if (strlen($namespace) < 1) {
            throw new \InvalidArgumentException('On the attribute namespace, the length of the string ' . $namespace . ' is ' . strlen($namespace) . ' which is shorter than the minimum allowed (1).');
        }

        $this->namespace = $namespace;

        return $this;
    }
902406
protected static function _namespaceGetAll($namespace)
    {
        $currentData  = (isset($_SESSION[$namespace]) && is_array($_SESSION[$namespace])) ?
            $_SESSION[$namespace] : array();
        $expiringData = (isset(self::$_expiringData[$namespace]) && is_array(self::$_expiringData[$namespace])) ?
            self::$_expiringData[$namespace] : array();
        return array_merge($currentData, $expiringData);
    }
1263210
public static function qualifiedClassName($className, $namespace)
    {
        if (empty($className)) {
            throw new \InvalidArgumentException('Class name cannot be empty.');
        }

        if (empty($namespace)) {
            throw new \InvalidArgumentException('Current namespace cannot be empty.');
        }

        $className = trim($className, '\\');
        $len = strlen($namespace);

        if (strlen($className) > $len && ($namespace . '\\') === substr($className, 0, $len + 1)) {
            return substr($className, $len + 1);
        }

        return $className;
    }
1235270
protected function getNamespaceFromWechatAppId($namespace)
    {
        if (substr($namespace, 0, 2) != 'wx') {
            return false;
        }

        wei()->logger->debug('Got wechat appId', ['appId' => $namespace]);

        $appId = wei()->wechatAccount()->select('appId')->fetchColumn(['applicationId' => $namespace]);
        if (!$appId) {
            return false;
        }

        $namespace = wei()->appRecord()->select('name')->fetchColumn(['id' => $appId]);
        wei()->logger->debug('Convert wechat appId to namespace', ['namespace' => $namespace]);

        return $namespace;
    }
573668
private function setupNamespace($namespace)
	{
		if(!is_null($namespace)) {
			if(!isset($_SESSION[$namespace]) || !is_array($_SESSION[$namespace])) {
				$_SESSION[$namespace] = array();
			}
			$this->data = &$_SESSION[$namespace];
		} else {
			$this->data = &$_SESSION;
		}
	}
452021
public function hasIn($namespace, $key)
    {
        if (isset($_SESSION[$namespace])) {
            $oldNamespace = $this->namespace;
            $this->setNamespace($namespace);
            $result = $this->has($key);
            $this->setNamespace($oldNamespace);

            return $result;
        }
    }
283333
private function namespaceFromLegacyNamespace($namespace, $className)
    {
        $qcn = str_replace('_', '\\', $className);

        $lastBackslash = strrpos($qcn, '\\');
        if ($lastBackslash) {
            $namespace = rtrim($namespace, '\\') . '\\' . substr($qcn, 0, $lastBackslash);
        }

        return $namespace;
    }