\CodeIgniter\AutoloaderFileLocator

Class FileLocator

Allows loading non-class files in a namespaced manner. Works with Helpers, Views, etc.

Summary

Methods
Properties
Constants
__construct()
locateFile()
getClassname()
search()
findQualifiedNameFromPath()
listFiles()
listNamespaceFiles()
No public properties found
No constants found
ensureExt()
getNamespaces()
legacyLocate()
$autoloader
N/A
No private methods found
No private properties found
N/A

Properties

Methods

locateFile()

locateFile(string  $file, string  $folder = null, string  $ext = 'php') : string|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.

Parameters

string $file

The namespaced file to locate

string $folder

The folder within the namespace that we should look for the file.

string $ext

The file extension the file should have.

Returns

string|false —

The path to the file, or false if not found.

getClassname()

getClassname(string  $file) : string

Examines a file and returns the fully qualified domain name.

Parameters

string $file

Returns

string

search()

search(string  $path, string  $ext = 'php') : array

Searches through all of the defined namespaces looking for a file.

Returns an array of all found locations for the defined file.

Example:

$locator->search('Config/Routes.php'); // Assuming PSR4 namespaces include foo and bar, might return: [ 'app/Modules/foo/Config/Routes.php', 'app/Modules/bar/Config/Routes.php', ]

Parameters

string $path
string $ext

Returns

array

findQualifiedNameFromPath()

findQualifiedNameFromPath(string  $path) : string|false

Find the qualified name of a file according to the namespace of the first matched namespace path.

Parameters

string $path

Returns

string|false —

The qualified name or false if the path is not found

listFiles()

listFiles(string  $path) : array

Scans the defined namespaces, returning a list of all files that are contained within the subpath specified by $path.

Parameters

string $path

Returns

array

listNamespaceFiles()

listNamespaceFiles(string  $prefix, string  $path) : array

Scans the provided namespace, returning a list of all files that are contained within the subpath specified by $path.

Parameters

string $prefix
string $path

Returns

array

ensureExt()

ensureExt(string  $path, string  $ext) : string

Ensures a extension is at the end of a filename

Parameters

string $path
string $ext

Returns

string

getNamespaces()

getNamespaces() : array|string

Return the namespace mappings we know about.

Returns

array|string

legacyLocate()

legacyLocate(string  $file, string|null  $folder = null) : string|false

Checks the application folder to see if the file can be found.

Only for use with filenames that DO NOT include namespacing.

Parameters

string $file
string|null $folder

Returns

string|false —

The path to the file, or false if not found.