This method tries to find the base namespace of the current app. We try
to look at the composer.json file and use the first psr-4 autoload key

@return string
165576
private static function getBaseNamespace()
    {
        // try to determine the namespace of the
        $composerFile = PSX_PATH_SRC . '/../composer.json';
        $composer = \json_decode(\file_get_contents($composerFile), true);

        if (isset($composer['autoload'])) {
            $paths = $composer['autoload']['psr-4'] ?? [];
            $base  = trim(key($paths), '\\');

            if (!empty($base)) {
                return $base;
            }
        }

        throw new \RuntimeException('Could not determine the base namespace');
    }
522488
public function getNamespace()
    {
        if (isset($this->properties[ 'namespace' ])) {
            return $this->properties[ 'namespace' ];
        }

        $dir = $this->getRealPath();
        $dirParts = explode('Widgets' . DIRECTORY_SEPARATOR, $dir);
        $namespace = loader()->getDirNamespace(reset($dirParts)) . 'Widgets\\' . str_replace(['/', DIRECTORY_SEPARATOR],
                '\\', end($dirParts));

        return $namespace;
    }
1325726
protected function _getAppBase()
    {
        $baseUrl = Configure::read('App.base');
        if (!$baseUrl) {
            $request = Router::getRequest(true);
            if (!$request) {
                $baseUrl = '';
            } else {
                $baseUrl = $request->base;
            }
        }
        return $baseUrl . '/';
    }
590108
protected function getNamespace($name, $withApp = true)
    {
        $path = (strlen($this->settings['namespace']) >= 2 ? $this->settings['namespace'] . '\\' : '');

        // dont add the default namespace if specified not to in config
        if ($this->settingsDirectoryNamespace() === true) {
            $path .= str_replace('/', '\\', $this->getArgumentPath());
        }

        $pieces = array_map('ucfirst', explode('/', $path));

        $namespace = ($withApp === true ? $this->getAppNamespace() : '') . implode('\\', $pieces);

        $namespace = rtrim(ltrim(str_replace('\\\\', '\\', $namespace), '\\'), '\\');

        return $namespace;
    }
1019933
public function getRootNamespace ()
	{
		
		$arr		= explode ('\\', $this->get ('namespace'));
		$table		= explode ('_', $this->get ('table'));
		$ns			= [];
		
		foreach ($arr as $nsSegment)
		{
			$tableSegment	= array_shift ($table);
			if (strtolower ($nsSegment) != strtolower ($tableSegment))
			{
				$ns[]	= $nsSegment;
				array_unshift ($table, $tableSegment);
			}
		}
		
		$namespace	= join ('\\', $ns) . '\\';
		
		return $namespace;
	}
574624
public function getNamespace()
    {
        if (! is_null($this->namespace)) {
            return $this->namespace;
        }

        $composer = json_decode(file_get_contents(base_path('composer.json')), true);

        foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
            foreach ((array) $path as $pathChoice) {
                if (realpath(app()->path()) == realpath(base_path().'/'.$pathChoice)) {
                    return $this->namespace = $namespace;
                }
            }
        }

        throw new RuntimeException('Unable to detect application namespace.');
    }
1249791
public static function base()
	{

		//get the server name from global $_SERVER[] array()
		$base  = $_SERVER['SERVER_NAME']; 

		$url = Registry::getUrl();

		//check if there is a uri string
		if ( ! empty($url) ) 
		{
			//prepend installation folder to server name
			$base .= substr($_SERVER['REQUEST_URI'], 0,  strpos($_SERVER['REQUEST_URI'], Registry::getUrl()));

		}
		//there is no query string, 
		else
		{
			//prepend installation folder to server name
			$base .= substr($_SERVER['REQUEST_URI'], 0);

		}

    	//use https if its defined in the $_SERVER global variable
    	$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") ? "https" : "http";

		//compose the url string
		return $protocol . '://' . $base;

	}
819544
public function getFileNamespace(): string
	{
		if($this->fileNamespace === null)
		{
			$this->fileNamespace = str_replace('/', '-', strtolower($this->packageName));
		}

		return $this->fileNamespace;
	}
1198532
public function getFactoryNamespace()
    {
        $result = $this->_factoryNamespace;

        if ($result && strpos($result, '\\') !== 0) {
            $result = '\\' . $result;
        }

        return $result;
    }
860392
protected function getAutoload()
    {
        $composerPath = base_path('/composer.json');
        if (! file_exists($composerPath)) {
            return [];
        }
        $composer = json_decode(file_get_contents(
            $composerPath
        ), true);

        return Arr::get($composer, 'autoload.psr-4', []);
    }
1339324
protected function getContractNamespace($withApp = true)
    {
        // get path from settings
        $path = config('generators.settings.contract.namespace') . '\\';

        // dont add the default namespace if specified not to in config
        $path .= str_replace('/', '\\', $this->getArgumentPath());

        $pieces = array_map('ucfirst', explode('/', $path));

        $namespace = ($withApp === true ? $this->getAppNamespace() : '') . implode('\\', $pieces);

        $namespace = rtrim(ltrim(str_replace('\\\\', '\\', $namespace), '\\'), '\\');

        return $namespace;
    }
670790
public function getBasePath(): string
	{
		if($this->basePath === null)
		{
			$path = $this->server->get('SCRIPT_NAME');

			$this->basePath = rtrim(str_replace(basename($path), '', $path), '/');
		}

		return $this->basePath;
	}
214186
public function getNamespace()
    {
        $segments = $this->getSegments();
        array_pop($segments);
        $rootNamespace = $this->getRootNamespace();
        if ($rootNamespace == false) {
            return null;
        }

        return 'namespace ' . rtrim($rootNamespace . '\\' . implode($segments, '\\'), '\\') . ';';
    }
611519
protected function getDefaultNamespace($rootNamespace)
    {
        $serviceRootNamespace = Config::get('service-classes.namespace');

        if (! $serviceRootNamespace) {
            throw InvalidNamespaceException::missingServiceNamespace();
        }

        return $rootNamespace.'\\'.$serviceRootNamespace;
    }
1203125
protected function _buildApp()
    {
        $namespaces = '';
        foreach ($this->_namespaces as $namespace => $d) {
            $namespaces .= "\nuse $namespace;";
        }

        $namespaces .= "\n";

        return $this->getContainer()->get('templating')->render('CmsBaseBundle::app.html.twig', array(
        'namespaces' => $namespaces,
        'conststants' => $this->_constans,
        'properties' => $this->_properties,
        'methods' => $this->_methods,
      ));
    }
708755
protected function getVersionNamespace()
    {
        $version = $this->api()->getVersion();
        $supported = $this->getSupportedVersionNamespace();

        if (isset($supported[$version])) {
            return $supported[$version];
        }

        return 'Base';
    }
970088
private function getCommandNamespace()
    {
        $concrete_namespace = $this->getCommandDeclaredNamespace();

        if ($this->hasOption('system-folder')) {

            $concrete_namespace = $concrete_namespace . '\\' . $this->option('system-folder');
        }

        if ($this->hasOption('folder')) {
            
            if ($this->option('folder')) {
                
                $concrete_namespace = $concrete_namespace . '\\' . $this->option('folder'); 
            }
        }

        return $this->sanitizedPath($concrete_namespace);
    }