FileLocatorInterface
in
Allows loading non-class files in a namespaced manner.
Works with Helpers, Views, etc.
Table of Contents
Methods
- 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.
Methods
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