public function locateFile(string $file, string $folder = null, string $ext = 'php')
	{
		$file = $this->ensureExt($file, $ext);

		// Clears the folder name if it is at the beginning of the filename
		if (! empty($folder) && ($pos = strpos($file, $folder)) === 0)
		{
			$file = substr($file, strlen($folder . '/'));
		}

		// Is not namespaced? Try the application folder.
		if (strpos($file, '\\') === false)
		{
			return $this->legacyLocate($file, $folder);
		}

		// Standardize slashes to handle nested directories.
		$file = strtr($file, '/', '\\');

		$segments = explode('\\', $file);

		// The first segment will be empty if a slash started the filename.
		if (empty($segments[0]))
		{
			unset($segments[0]);
		}

		$path     = '';
		$prefix   = '';
		$filename = '';

		// Namespaces always comes with arrays of paths
		$namespaces = $this->autoloader->getNamespace();

		while (! empty($segments))
		{
			$prefix .= empty($prefix)
				? ucfirst(array_shift($segments))
				: '\\' . ucfirst(array_shift($segments));

			if (empty($namespaces[$prefix]))
			{
				continue;
			}
			$path = $this->getNamespaces($prefix);

			$filename = implode('/', $segments);
			break;
		}

		// IF we have a folder name, then the calling function
		// expects this file to be within that folder, like 'Views',
		// or 'libraries'.
		if (! empty($folder) && strpos($path . $filename, '/' . $folder . '/') === false)
		{
			$filename = $folder . '/' . $filename;
		}

		$path .= $filename;

		return is_file($path) ? $path : false;
	}
public function locateFile(string $file, string $folder = null, string $ext = 'php')
	{
		$file = $this->ensureExt($file, $ext);

		// Clears the folder name if it is at the beginning of the filename
		if (! empty($folder) && ($pos = strpos($file, $folder)) === 0)
		{
			$file = substr($file, strlen($folder . '/'));
		}

		// Is not namespaced? Try the application folder.
		if (strpos($file, '\\') === false)
		{
			return $this->legacyLocate($file, $folder);
		}

		// Standardize slashes to handle nested directories.
		$file = strtr($file, '/', '\\');

		$segments = explode('\\', $file);

		// The first segment will be empty if a slash started the filename.
		if (empty($segments[0]))
		{
			unset($segments[0]);
		}

		$path     = '';
		$prefix   = '';
		$filename = '';

		// Namespaces always comes with arrays of paths
		$namespaces = $this->autoloader->getNamespace();

		while (! empty($segments))
		{
			$prefix .= empty($prefix)
				? ucfirst(array_shift($segments))
				: '\\' . ucfirst(array_shift($segments));

			if (empty($namespaces[$prefix]))
			{
				continue;
			}
			$path = $this->getNamespaces($prefix);

			$filename = implode('/', $segments);
			break;
		}

		// IF we have a folder name, then the calling function
		// expects this file to be within that folder, like 'Views',
		// or 'libraries'.
		if (! empty($folder) && strpos($path . $filename, '/' . $folder . '/') === false)
		{
			$filename = $folder . '/' . $filename;
		}

		$path .= $filename;

		return is_file($path) ? $path : false;
	}
public function locateFile ( string $ file , string $ folder = null , string $ ext = 'php' ) { $ file = $ this -> ensureExt ( $ file , $ ext ) ; // Clears the folder name if it is at the beginning of the filename if ( ! empty ( $ folder ) && ( $ pos = strpos ( $ file , $ folder ) ) === 0 ) { $ file = substr ( $ file , strlen ( $ folder . '/' ) ) ; } // Is not namespaced? Try the application folder. if ( strpos ( $ file , '\\' ) === false ) { return $ this -> legacyLocate ( $ file , $ folder ) ; } // Standardize slashes to handle nested directories. $ file = strtr ( $ file , '/' , '\\' ) ; $ segments = explode ( '\\' , $ file ) ; // The first segment will be empty if a slash started the filename. if ( empty ( $ segments [ 0 ] ) ) { unset ( $ segments [ 0 ] ) ; } $ path = '' ; $ prefix = '' ; $ filename = '' ; // Namespaces always comes with arrays of paths $ namespaces = $ this -> autoloader -> getNamespace ( ) ; while ( ! empty ( $ segments ) ) { $ prefix .= empty ( $ prefix ) ? ucfirst ( array_shift ( $ segments ) ) : '\\' . ucfirst ( array_shift ( $ segments ) ) ; if ( empty ( $ namespaces [ $ prefix ] ) ) { continue ; } $ path = $ this -> getNamespaces ( $ prefix ) ; $ filename = implode ( '/' , $ segments ) ; break ; } // IF we have a folder name, then the calling function // expects this file to be within that folder, like 'Views', // or 'libraries'. if ( ! empty ( $ folder ) && strpos ( $ path . $ filename , '/' . $ folder . '/' ) === false ) { $ filename = $ folder . '/' . $ filename ; } $ path .= $ filename ; return is_file ( $ path ) ? $ path : false ; }
Attempts to locate a file by examining the name for a namespace
and looking through the PSR-4 namespaced files that we know about.

@param string $file   The namespaced file to locate
@param string $folder The folder within the namespace that we should look for the file.
@param string $ext    The file extension the file should have.

@return string|false The path to the file, or false if not found.
Attempts to locate a file by examining the name for a namespace and looking through the PSR - 4 namespaced files that we know about .