FileLocator
in package
implements
FileLocatorInterface
Allows loading non-class files in a namespaced manner.
Works with Helpers, Views, etc.
Tags
Table of Contents
Interfaces
- FileLocatorInterface
- Allows loading non-class files in a namespaced manner.
Properties
- $autoloader : Autoloader
- The Autoloader to use.
- $invalidClassnames : array<int, class-string>
- List of classnames that did not exist.
Methods
- __construct() : mixed
- findQualifiedNameFromPath() : false|string
- Find the qualified name of a file according to the namespace of the first matched namespace path.
- getClassname() : string
- Examines a file and returns the fully qualified class name.
- listFiles() : array<int, string>
- Scans the defined namespaces, returning a list of all files that are contained within the subpath specified by $path.
- listNamespaceFiles() : array<int, string>
- Scans the provided namespace, returning a list of all files that are contained within the sub path specified by $path.
- locateFile() : false|string
- Attempts to locate a file by examining the name for a namespace and looking through the PSR-4 namespaced files that we know about.
- search() : array<int, string>
- Searches through all of the defined namespaces looking for a file.
- ensureExt() : string
- Ensures a extension is at the end of a filename
- getNamespaces() : array<int, array<string, string>>
- Return the namespace mappings we know about.
- legacyLocate() : false|string
- Checks the app folder to see if the file can be found.
Properties
$autoloader
The Autoloader to use.
protected
Autoloader
$autoloader
$invalidClassnames
List of classnames that did not exist.
private
array<int, class-string>
$invalidClassnames
= []
Methods
__construct()
public
__construct(Autoloader $autoloader) : mixed
Parameters
- $autoloader : Autoloader
findQualifiedNameFromPath()
Find the qualified name of a file according to the namespace of the first matched namespace path.
public
findQualifiedNameFromPath(string $path) : false|string
Parameters
- $path : string
Return values
false|string —The qualified name or false if the path is not found
getClassname()
Examines a file and returns the fully qualified class name.
public
getClassname(string $file) : string
Parameters
- $file : string
Return values
stringlistFiles()
Scans the defined namespaces, returning a list of all files that are contained within the subpath specified by $path.
public
listFiles(string $path) : array<int, string>
Parameters
- $path : string
Return values
array<int, string> —List of file paths
listNamespaceFiles()
Scans the provided namespace, returning a list of all files that are contained within the sub path specified by $path.
public
listNamespaceFiles(string $prefix, string $path) : array<int, string>
Parameters
- $prefix : string
- $path : string
Return values
array<int, string> —List of file paths
locateFile()
Attempts to locate a file by examining the name for a namespace and looking through the PSR-4 namespaced files that we know about.
public
locateFile(string $file[, non-empty-string|null $folder = null ][, string $ext = 'php' ]) : false|string
Parameters
- $file : string
-
The relative file path or namespaced file to locate. If not namespaced, search in the app folder.
- $folder : non-empty-string|null = null
-
The folder within the namespace that we should look for the file. If $file does not contain this value, it will be appended to the namespace folder.
- $ext : string = 'php'
-
The file extension the file should have.
Return values
false|string —The path to the file, or false if not found.
search()
Searches through all of the defined namespaces looking for a file.
public
search(string $path[, string $ext = 'php' ][, bool $prioritizeApp = true ]) : array<int, string>
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
- $path : string
- $ext : string = 'php'
- $prioritizeApp : bool = true
Return values
array<int, string>ensureExt()
Ensures a extension is at the end of a filename
protected
ensureExt(string $path, string $ext) : string
Parameters
- $path : string
- $ext : string
Return values
stringgetNamespaces()
Return the namespace mappings we know about.
protected
getNamespaces() : array<int, array<string, string>>
Return values
array<int, array<string, string>>legacyLocate()
Checks the app folder to see if the file can be found.
protected
legacyLocate(string $file[, non-empty-string|null $folder = null ]) : false|string
Only for use with filenames that DO NOT include namespacing.
Parameters
- $file : string
- $folder : non-empty-string|null = null
Return values
false|string —The path to the file, or false if not found.