Method to set path as relative (in Magento directories) or absolute for server

@param string $path
@param null   $basePath
@param bool   $makeDir

@return string
@throws \Exception
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;
    }
1196623
public static function absolute_url($path, $base_url)
    {
        // check if path is an absolute URL
        if (preg_match('/^[fhtps]+:\/\//', $path)) {
            return $path;
        }

        // check if path is a content-id scheme
        if (strpos($path, 'cid:') === 0) {
            return $path;
        }

        $host_url = $base_url;
        $abs_path = $path;

        // cut base_url to the last directory
        if (strrpos($base_url, '/') > 7) {
            $host_url = substr($base_url, 0, strpos($base_url, '/', 7));
            $base_url = substr($base_url, 0, strrpos($base_url, '/'));
        }

        // $path is absolute
        if ($path[0] == '/') {
            $abs_path = $host_url.$path;
        }
        else {
            // strip './' because its the same as ''
            $path = preg_replace('/^\.\//', '', $path);

            if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) {
                $cnt = count($matches);
                while ($cnt--) {
                    if ($pos = strrpos($base_url, '/')) {
                        $base_url = substr($base_url, 0, $pos);
                    }
                    $path = substr($path, 3);
                }
            }

            $abs_path = $base_url.'/'.$path;
        }

        return $abs_path;
    }
478538
public function setBasePath($path) {
		$path = realpath($path);
		
		if ($path === false) {
			throw new NoPath('Path does not exists or is not accessible');
		}
		
		$this->basePath = rtrim($path, DIRECTORY_SEPARATOR);
		
		return $this;
	}
1249106
public function getRealWritingFilePath($path, $rootDir)
    {
        $realDir = $this->getRealDir($path, $rootDir);

        if (!is_string($realDir)) {
            return false;
        }

        return $realDir . DIRECTORY_SEPARATOR . basename($path);
    }
216090
public function base_path($path = null)
    {
        return empty($path) ? $this->path : $this->path . $path;
    }
1348207
public function toAbsolute(\Coast\Path $base)
    {
        if (!$this->isRelative() || !$base->isAbsolute()) {
            throw new \Exception("Path '{$this}' is not relative or base path '{$base}' is not absolute");
        }

        $source = explode('/', (string) $base);
        $target = explode('/', $this->_name);
        
        $name = $source;
        array_pop($name);
        foreach ($target as $part) {
            if ($part == '..') {
                array_pop($name);
            } else if ($part != '.' && $part != '') {
                $name[] = $part;
            }
        }
        $name = implode('/', $name);

        $class = get_class($this);
        return new $class($name);
    }
719187
protected function set_base_path( $base_path ) {
        if ( ! is_string( $base_path ) ) {
            throw new InvalidArgumentException( 'Invalid argument. `$base_path` must be string.' );
        }

        if ( strpos( $base_path, '.php' ) !== false ) {
            $base_path = preg_replace( '/[^\/]*$/', '', $base_path );
        }

        $this->base_path = rtrim( $base_path, '/' );
    }
444249
public function makePath()
    {
        $path = base_path('src');

        if (!File::exists($path)) {
            File::makeDirectory($path, 0775, true);
        }
    }
1081072
protected function findRelativePath($path)
    {
        if (null !== $this->basePath) {
            return strtr($path, array($this->basePath . DIRECTORY_SEPARATOR => ''));
        }

        return $path;
    }
1207039
public function getRealPath($path, $rootDir)
    {
        if (!is_string($path)) {
            return false;
        }

        if ($this->isRelativePath($path)) {
            return realpath($rootDir . DIRECTORY_SEPARATOR . $path);
        }

        return realpath($path);
    }
948014
public static function setBaseDir($path)
    {
        $path = realpath(rtrim($path, '/\\ '));
        if ($path === false) {
            throw new \InvalidArgumentException("cat`t get real path: seems like path does`t exists: $path");
        }

        return static::$baseDir = $path;
    }
862739
public static function folder($path, $relative = false)
		{
		    $path = Paths::make($path, $relative);
		    return rtrim($path, '/') . '/';
		}
248716
public function symlink($originDir, $targetDir, $relative = false)
    {
        if ($relative) {
            $this->filesystem->mkdir(dirname($targetDir));
            $originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir)));
        }
        $this->filesystem->symlink($originDir, $targetDir);

        if (!file_exists($targetDir)) {
            throw new \Exception(
                sprintf('Symbolic link "%s" was created but appears to be broken.', $targetDir),
                0,
                null
            );
        }
    }
109067
public function setBasePath($path) {
		$path = rtrim($path, '\/');
		
		if (preg_match('~^[a-z]+:~', $path)) {
			$this->basePath = $path;
			return;
		}
		
		$this->basePath = realpath($path);
		
		return $this;
	}
455866
public static function combineRelativePathWithBasePath($relativePath, $basePath)
    {
        $relativePath = self::normalizePath($relativePath);
        if ($relativePath == '') {
            return $basePath;
        }
        if ($relativePath[0] == '/') {
            return $relativePath;
        }

        $basePathSegments = explode('/', $basePath);

        preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match);
        $numLevelUp = strlen($match[0]) /3 + 1;
        if ($numLevelUp >= count($basePathSegments)) {
            throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath));
        }

        $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp);
        $path = preg_replace('|^/?(\.\./(\./)*)*|', '', $relativePath);

        return implode('/', $basePathSegments) . '/' . $path;
    }
413383
public function resolve(
        AbsolutePathInterface $basePath,
        PathInterface $path
    ) {
        if ($path instanceof AbsolutePathInterface) {
            return $path;
        }
        if ($path instanceof RelativeWindowsPathInterface) {
            if ($path->isAnchored()) {
                return $path->joinDrive($basePath->drive());
            }
            if ($path->hasDrive() && !$path->matchesDrive($basePath->drive())) {
                return $path->toAbsolute();
            }
        }

        return $basePath->join($path);
    }
134220
public function basePath($basePath = null)
    {
        if (!func_num_args()) {
            return $this->_basePath;
        }
        $this->_basePathTmp = $basePath;
        if ($this->_ignorePath) {
            $basePath = preg_replace($this->_ignorePath, '', $basePath);
        }
        $this->_basePath = $basePath && $basePath !== '/' ? '/' . trim($basePath, '/') : '';
        return $this;
    }