Loader
The Loader package is Quantum's small file-loading utility.
Use it when you need to:
- load a PHP resource file from a module or shared directory
- check whether a module-specific file exists before falling back to shared resources
- include helper directories during bootstrap
Most applications use it indirectly through higher-level packages such as Config, Environment, and Storage uploads. Reach for it directly when you are building package-level resource loading of your own.
Package shape
The package has two runtime classes:
Quantum\Loader\Setupdescribes what file should be resolvedQuantum\Loader\Loaderresolves the path, checks existence, andrequires the file
It also ships LoaderException for missing-file failures.
What it loads
Loader::load() always loads a PHP file and returns whatever that file returns.
That makes it a good fit for resource files such as:
- config arrays
- package metadata arrays
- small PHP bootstrap resources
It is not a template renderer, JSON reader, or recursive filesystem scanner.
Resolution model
A Setup object controls lookup using:
pathPrefixsuch asconfigfileNamesuch asdatabasemodulesuch asBloghierarchicalfallback flag
With new Setup('config', 'database'), lookup order is:
modules/<current-module>/config/database.phpwhen a current module is available<pathPrefix>/<fileName>.phpas the primary non-module path (for this example:config/database.php)shared/config/database.phpwhen hierarchical fallback is enabled
So without a module, Loader first checks the primary path (config/database.php) and only then falls back to shared/config/database.php.
Important constraints
Setupdefaultshierarchicaltotrue, so shared fallback is on unless you disable it.Setupdefaults the module torequest()->getCurrentModule(), so request context changes where Loader looks unless you set the module explicitly.- A
Setupobject cannot be reset back tonullmodule state throughsetModule(). If you want to drop a module override and go back to non-module resolution, create a freshSetup. loadDir()only includes*.phpfiles from the exact directory pattern you pass in. It does not recurse into subdirectories.loadDir()usesrequire_once, whileload()usesrequire. Repeatedload()calls can re-run a file.- Missing files raise
LoaderExceptiononly when you callload()orgetFilePath(). UsefileExists()when absence is expected.