Get Namespace of the current file.

@param string $file

@return string
162319
protected function getNamespace($file)
    {
        $basename = $this->packageInfo->get('basename');

        if ($this->packageInfo->get('type') == 'module') {
            $namespace = str_replace($this->packagesPath .DS .$basename, '', $file);
        } else {
            $namespace = str_replace($this->packagesPath .DS .$basename .DS .'src', '', $file);
        }

        $find = basename($namespace);

        $namespace = strrev(preg_replace(strrev("/$find/"), '', strrev($namespace), 1));

        $namespace = $this->packageInfo->get('namespace') .'\\' .trim($namespace, '\\/');

        return str_replace('/', '\\', $namespace);
    }
111769
protected static function getTypeFinfoExt($file) {

		$type = (new \finfo(FILEINFO_MIME_TYPE))->file($file);

		if($type) {
			return $type;
		}

		else {
			return self::getTypeFileExtList($file);
		}

	}
942565
public function preparePath(string $file): string
    {
        if (0 === strncmp($file, '$', 1)) {
            return $file;
        }

        $skippable = 0 === strncmp($file, '?', 1) ? '?' : '';
        if ($skippable) {
            $file = substr($file, 1);
        }

        if (!$this->getFilesystem()->isAbsolutePath($file)) {
            $prefix = $this->isRoot()
                ? $this->getBaseDir()
                : $this->getVendorDir() . '/' . $this->getPrettyName();
            $file = $prefix . '/' . $file;
        }

        return $skippable . $this->getFilesystem()->normalizePath($file);
    }
1038361
public function current($file = null)
    {
        $splFileInfo = $file ?: parent::current();

        return $this->transformer->transform($splFileInfo);
    }
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}
276843
public function getFileName() {
        $isTestClass = substr($this->getName(), -4) == 'Test';
        if($isTestClass) {
            $rootDirectory = $this->getConfiguration()->getRootTestDirectory();
        } else {
            $rootDirectory = $this->getConfiguration()->getRootDirectory();
        }
        if(substr($this->getNamespace(), 0, strlen($this->getConfiguration()->getRootNamespace())) != $this->getConfiguration()->getRootNamespace()) {
            throw new \Exception('The Root namespace does not match this classes namespace, could not get the file name'."\n".$this->getNamespace()."\n".$this->getConfiguration()->getRootNamespace());
        }
        if($isTestClass) {
            $namespace = $this->getNamespace();
        } else {
            $namespace = substr($this->getNamespace(), strlen($this->getConfiguration()->getRootNamespace()));
        }
        if(DIRECTORY_SEPARATOR != '\\') {
            $namespace = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
        }
        return $rootDirectory . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . $this->getName() . '.php';
    }
701678
public function getBindingForFile( $file ) {
		$engine_key = $this->default;

		foreach ( $this->bindings as $suffix => $engine ) {
			if ( substr( $file, -strlen( $suffix ) ) === $suffix ) {
				$engine_key = $engine;
				break;
			}
		}

		return $engine_key;
	}
1010430
protected function getFilePath(string $file, ?string $extension = null, ?string $suffix = null): string
	{
		if(strpos($file, '::') === false)
		{
			// No namespace so we'll just use the default path

			$path = $this->path;
		}
		else
		{
			// The file is namespaced so we'll use the namespace path

			[$namespace, $file] = explode('::', $file, 2);

			if(!isset($this->namespaces[$namespace]))
			{
				throw new RuntimeException(vsprintf('The [ %s ] namespace does not exist.', [$namespace]));
			}

			$path = $this->namespaces[$namespace];
		}

		// Append suffix to path if needed

		if($suffix !== null)
		{
			$path .= DIRECTORY_SEPARATOR . $suffix;
		}

		// Return full path to file

		return $path . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $file) . ($extension ?? $this->extension);
	}
350031
private function getManifestFileName($file)
    {
        if (!isset($this->metaCache[$file])) {
            $ds = DIRECTORY_SEPARATOR;
            $base = sha1_file($file) . '_'.basename($file) . '.manifest';
            $name = substr_replace(substr_replace($base, $ds, 4, 0), $ds, 2, 0);

            $this->metaCache[$file] = sprintf('%s%s%s', $this->manifest, $ds, $name);
        }

        return $this->metaCache[$file];
    }
1341065
private function findAvailableName($file)
    {
        $name = basename($file);

        if (!file_exists($this->directory.'/'.$name)) {
            return $name;
        }

        $dotPos = strrpos($name, '.');
        $prefix = substr($name, 0, $dotPos);
        $suffix = substr($name, $dotPos);

        $count = 1;
        do {
            $name = $prefix.'_'.$count.$suffix;
            $count++;
        } while (file_exists($this->directory.'/'.$name));

        return $name;
    }
72571
public function getNamespace($file, $defaultToPath = false)
    {
        // massage file path into a format compatible with PSR-4 entries
        $file = str_replace('\\', '/', $file);
        $base = str_replace('\\', '/', base_path()) . '/';
        $file = str_replace($base, '', $file);

        // compare file path against existing entries
        foreach($this->namespaces as $ns => $path)
        {
            // convert paths to all use forward slashes
            $path = str_replace('\\', '/', $path);

            // if the file starts with the namespace path
            if(strpos($file, $path) === 0)
            {
                $file   = substr($file, strlen($path));
                $file   = preg_replace('%/[^/]+$%', '', $file);
                $file   = str_replace('/', '\\', $file);

                // defensive trim, in case any double slashes
                return trim($ns . $file, '\\');
            }
        }

        // namespace could not be resolved
        $info = pathinfo($file);

        return $defaultToPath
            ? str_replace('/', '\\', $info['dirname'])
            : null;

    }
305010
public function getPath($file)
    {
        $file = "/".ltrim($file,"/");

        $best = null;
        foreach($this->nodes as $node) {
            $mount = $node->getMountPoint();
            if (strncmp($mount, $file, strlen($mount)) === 0) {
                $nodefile = substr($file, strlen($mount));
                //printf("nodefile=%s mount=%s file=%s\n", $nodefile, $mount, $file);
                if ($node->has($nodefile)) {
                    return $node->getPath($nodefile);
                }
                if (!$best) {
                    $best = $node->getPath($nodefile);
                }
                if ($node->getIsWritable($nodefile)) {
                    $best = $node->getPath($nodefile);
                }
            }
        }
        return $best;

    }
42974
protected function findClass($file)
    {
        $class = false;
        $namespace = false;
        $tokens = token_get_all(file_get_contents($file));

        if (1 === \count($tokens) && T_INLINE_HTML === $tokens[0][0]) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "<?php" start tag at the beginning of the file?', $file));
        }

        for ($i = 0; isset($tokens[$i]); ++$i) {
            $token = $tokens[$i];

            if (!isset($token[1])) {
                continue;
            }

            if (true === $class && T_STRING === $token[0]) {
                return $namespace.'\\'.$token[1];
            }

            if (true === $namespace && T_STRING === $token[0]) {
                $namespace = $token[1];
                while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
                    $namespace .= $tokens[$i][1];
                }
                $token = $tokens[$i];
            }

            if (T_CLASS === $token[0]) {
                // Skip usage of ::class constant and anonymous classes
                $skipClassToken = false;
                for ($j = $i - 1; $j > 0; --$j) {
                    if (!isset($tokens[$j][1])) {
                        break;
                    }

                    if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
                        $skipClassToken = true;
                        break;
                    } elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT])) {
                        break;
                    }
                }

                if (!$skipClassToken) {
                    $class = true;
                }
            }

            if (T_NAMESPACE === $token[0]) {
                $namespace = true;
            }
        }

        return false;
    }
887714
private function lookupNamespace(string $path)
    {
        $content = file_get_contents($path);

        preg_match(
            '#' .
            preg_quote('namespace') .
            '(.+?)' .
            preg_quote(';') .
            '#s',
            $content,
            $matchs
        );

        unset($content);

        return isset($matchs[1]) ? trim($matchs[1]): false;
    }
1007175
private function findFileNamespaces()
    {
        $namespaces = array();

        // namespaces can be only top-level nodes, so we can scan them directly
        foreach ($this->topLevelNodes as $topLevelNode) {
            if ($topLevelNode instanceof Namespace_) {
                $namespaceName = $topLevelNode->name ? $topLevelNode->name->toString() : '';

                $namespaces[$namespaceName] = new ReflectionFileNamespace(
                    $this->fileName,
                    $namespaceName,
                    $topLevelNode
                );
            }
        }

        return $namespaces;
    }
33439
private function getExamplePathFromSource(string $file): string
    {
        return sprintf(
            '%s%s%s',
            trim($this->getSourceDirectory(), '\\/'),
            DIRECTORY_SEPARATOR,
            trim($file, '"')
        );
    }
217807
public function getFilePath($file): string
    {
        if (null === ($fileObj = $this->container->get('huh.utils.file')->getFileFromUuid($file))) {
            return '';
        }

        return $fileObj->path;
    }