Init base path, or guess if able

@param string|null $basePath
497206
protected function initBaseDir($basePath)
    {
        if ($basePath) {
            $this->setBaseDir($basePath);
        } elseif (defined('BASE_PATH')) {
            $this->setBaseDir(BASE_PATH);
        } else {
            throw new BadMethodCallException("No BASE_PATH defined");
        }
    }
33460
public function init()
    {
        if (!isset($this->basePath)) {
            $this->basePath = Yii::getPathOfAlias('webroot');
        }
        $this->basePath = rtrim($this->basePath, '/');
    }
830463
protected static function setPath($path = null)
    {
        if (!static::$pathStack) {
            $requestURI = parse_url($_SERVER['REQUEST_URI']);
            static::$pathStack = static::$requestPath = explode('/', ltrim($requestURI['path'], '/'));
        }
    
        static::$_path = isset($path) ? $path : static::$pathStack;
    }
937265
public function match(string $path, $basePath = null) {
        $regex = '(^' . $this->regex . '$)';
        if ($basePath !== null) {
            $length = strlen($basePath);
            if (substr($path, 0, $length) !== $basePath) {
                return false;
            }
            $path = substr($path, $length);
        }
        $result = (bool) preg_match($regex, $path, $matches, 0, (int) $basePath);
        $this->params = [];
        if ($result) {
            $params = [];
            foreach ($matches as $name => $value) {
                if (isset($this->paramMap[$name])) {
                    $params[$this->paramMap[$name]] = $value;
                }
            }
            $this->params = array_merge($this->defaults, $params);
        }
        return $result;
    }
371209
private static function init(): void
    {
        if (static::$initialized === false) {
            $baseClass = Base::getInstance();

            static::$initialized = true;
            static::$logDir = $baseClass->parsePath((string)$baseClass->Log->logDirectory);
            static::$classConfig = $baseClass->Log->classConfig->toArray();

            if (static::$logDir != '') {
                Directory::create(static::$logDir);
            }
        }
    }
1091302
public function setPath( $path )
    {
        // Validate $path, it cant be null and must exist
        if ( ! is_string( $path ) ){ throw new InvalidPathException( 'Path must be of type string' ); }
        if ( is_null( $path ) ){ throw new InvalidPathException( 'Path can not be null' ); }
        if ( ! file_exists( $path )){ throw new InvalidPathException( '('. $path .') is invalid' ); }

        $this->path = $path;
    }
681204
public function baseUrl($targetPath = null)
    {
        if (!isset($this->baseUrl)) {
            throw new RuntimeException(sprintf(
                'The base URI is not defined for [%s]',
                get_class($this)
            ));
        }

        if ($targetPath !== null) {
            return $this->createAbsoluteUrl($this->baseUrl, $targetPath);
        }

        return rtrim($this->baseUrl, '/').'/';
    }
1314051
public static function create(string $basePath): Application {
        self::$instance = new Application($basePath);
        return self::$instance;
    }
901074
private function loadFactories($factoriesPath)
    {
        $factoriesPath = $factoriesPath ?: static::$factoriesPath;

        if ( ! static::$factories) {
            static::$factories = (new FactoriesLoader)->load($factoriesPath);
        }
    }
1065044
private function addBasePath($path)
    {
        if (\strpos($path, $this->basePath) === 0) {
            return $path;
        }

        return \str_replace('//', '/', $this->basePath . '/' . $path);
    }
436558
public function determineFilePath($path, $basePath = null, $makeDir = false)
    {
        $this->logger->debug(sprintf('Search for path: %s with a prefix base path: %s', $path, $basePath));

        if ($this->variable->isEmpty($path)) {
            $this->logger->warning('No Path given to method');
            throw new \Exception('No Path given to method');
        }

        if ($this->variable->isEmpty($basePath)) {
            $basePath = BP;
        }

        // for windows systems
        $path = preg_replace('/\\\\/', '/', $path);

        $path = preg_match('/^\//', $path) || preg_match('/^[a-zA-Z]:\//', $path) ? rtrim($path, '/') :
            rtrim($basePath, '/') . '/' . trim($path, '/');

        $fileCheck = pathinfo($path);
        // Check for last character
        $pathEnding = substr($path, -1);

        if (( ! array_key_exists('extension', $fileCheck) || $this->variable->isEmpty($fileCheck[ 'extension' ])) &&
            $pathEnding != "/" && $pathEnding != "\\"
        ) {
            $path .= '/';
        }

        $dirPath = ! isset($fileCheck[ 'extension' ]) ? $path : dirname($path);

        if ($makeDir && ! is_dir($dirPath)) {
            $this->logger->debug(sprintf('Creating directory with path: %s', $path));

            if ($this->makeDirs($dirPath)) {
                $this->logger->debug(sprintf('Successfully created directory with path: %s', $dirPath));
            } else {
                $this->logger->warning(sprintf('Could not create directory with path: %s', $path));
            }
        }

        $this->logger->debug(sprintf('Created absolute path: %s', $path));

        return $path;
    }
1308464
public function basePath(?string $basePath = null) {
        if ($basePath != null) {
            $this->basePath = $basePath;
        }
        return $this->basePath;
    }
988709
public function setCachePath($cachePath = NULL)
    {
        $this->cachePath = $cachePath;
        $this->debug->debug(__FUNCTION__, 'setCachePath: ', $this->cachePath);
    }
504026
public function setSourcesBasePath($sourcesBasePath) {
		$sourcesBasePath = realpath($sourcesBasePath);
		if(!$sourcesBasePath) {
			throw new \Exception('Path "' . $sourcesBasePath . '" not found');
		}
		$this->sourcesBasePath = $sourcesBasePath;
	}
173654
protected function setSourcePath($path)
    {
        if ($this->sourcePath === self::BASE_PATH) {
            $this->sourcePath = $path;
        } elseif ($this->sourcePath === self::EMPTY_PATH) {
            $this->sourcePath = null;
        }
    }
573293
public function setBasePath( string$basePath ):self
	{
		$this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath;

		return $this;
	}
899905
public function setBasePath($basePath)
    {
        $this['path.app'] = rtrim($basePath);

        foreach (['config', 'views', 'logs'] as $v) {
            $this['path.' . $v] = realpath(rtrim($basePath) . '/' . $v) . DIRECTORY_SEPARATOR;
        }

        $this['namespace.controller'] = '';

        return $this;
    }