- ⌂ loader
- Static Methods
loader::init_paths()
Initialize the auto-loader using the default configuration, or an optional custom configuration. This method is called automatically internally if it has not been called manually before any other API classes are loaded. So, while init_paths() can be called with no parameters to use the default configuration, there is no need to do so. Calling it multiple times will re-initialize the loader, so only the configuration from the last call will apply to subsequent load actions.
Prototype
void init_paths(string $app_path = '', array $paths = [])
Parameters
- app_path - The folder the auto-loader should use as the base path. All relative paths will be based on this path. If nothing is provided, the folder where the initial PHP file was loaded will be used.
- paths - An associative array of base and package path definitions, where the key is 'base_paths' or 'package_paths' and the value is an array of path strings. The auto-loader will look for packages and configuration files in the specified base_paths and it will look for packages inside the package_paths. The first path provided will be searched first and so on. Paths can be absolute (start with a slash) or relative to the app_path.
Example
require_once('path/to/comand.php');
\io_comand\loader::init_paths('path/to/application',[
'base_paths'=>[
'../relative/path/to/custom',
'/absolute/path/to/another'
],
'package_paths'=>[
'../relative/path/to/custom/packages',
'/absolute/path/to/custom/packages'
]
]);
// try to load config from config folder under the first or second
// custom base paths, or the default path, in that order
$my_config = \io_comand\loader::load_config('my_config');
// Find and launch an app defined in the app_name class within the
// com_example package folder. The first, then second custom
// package paths will be searched, then the default package path(s)
// The first matching package and class found will be used.
\com_example\app_name::launch();