Documentation

FileLocator
in package

Class FileLocator

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

Table of Contents

$autoloader  : Autoloader
The Autoloader to use.
__construct()  : mixed
Constructor
findQualifiedNameFromPath()  : string|false
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 domain name.
listFiles()  : array<string|int, mixed>
Scans the defined namespaces, returning a list of all files that are contained within the subpath specified by $path.
listNamespaceFiles()  : array<string|int, mixed>
Scans the provided namespace, returning a list of all files that are contained within the subpath specified by $path.
locateFile()  : 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.
search()  : array<string|int, mixed>
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<string|int, mixed>|string
Return the namespace mappings we know about.
legacyLocate()  : string|false
Checks the app folder to see if the file can be found.

Properties

Methods

findQualifiedNameFromPath()

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

public findQualifiedNameFromPath(string $path) : string|false
Parameters
$path : string
Return values
string|false

The qualified name or false if the path is not found

getClassname()

Examines a file and returns the fully qualified domain name.

public getClassname(string $file) : string
Parameters
$file : string
Return values
string

listFiles()

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

public listFiles(string $path) : array<string|int, mixed>
Parameters
$path : string
Return values
array<string|int, mixed>

listNamespaceFiles()

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

public listNamespaceFiles(string $prefix, string $path) : array<string|int, mixed>
Parameters
$prefix : string
$path : string
Return values
array<string|int, mixed>

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[, string|null $folder = null ][, string $ext = 'php' ]) : string|false
Parameters
$file : string

The namespaced file to locate

$folder : string|null = null

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

$ext : string = 'php'

The file extension the file should have.

Return values
string|false

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

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

public search(string $path[, string $ext = 'php' ][, bool $prioritizeApp = true ]) : array<string|int, mixed>

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<string|int, mixed>

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
string

getNamespaces()

Return the namespace mappings we know about.

protected getNamespaces() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string

legacyLocate()

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

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

Only for use with filenames that DO NOT include namespacing.

Parameters
$file : string
$folder : string|null = null
Return values
string|false

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

Search results