Autoload
Using Composer to Load PSR-0 Compliant Files
Webman follows the PSR-4 autoloading standard. If your business requires loading a codebase that complies with the PSR-0 standard, refer to the following steps.
- Create an
extenddirectory to store thePSR-0compliant codebase. - Edit
composer.json, adding the following content underautoload.
"psr-0" : {
"": "extend/"
}
The final result will look similar to this:

- Run
composer dumpautoload. - Execute
php start.php restartto restart webman (note that it must be restarted for changes to take effect).
Using Composer to Load Certain Files
-
Edit
composer.json, adding the files you want to load underautoload.files."files": [ "./support/helpers.php", "./app/helpers.php" ] -
Run
composer dumpautoload. -
Execute
php start.php restartto restart webman (note that it must be restarted for changes to take effect).
Tip
The files configured inautoload.filesin composer.json will be loaded before webman starts. In contrast, files loaded through the framework'sconfig/autoload.phpare loaded after webman starts.
Changes to files loaded viaautoload.filesin composer.json require a restart to take effect; reload will not suffice. However, files loaded through the framework'sconfig/autoload.phpsupport hot reloading, and changes can take effect with a reload.
Using the Framework to Load Certain Files
Some files may not comply with the SPR standard and may not be autoloaded. We can load these files by configuring config/autoload.php, for example:
return [
'files' => [
base_path() . '/app/functions.php',
base_path() . '/support/Request.php',
base_path() . '/support/Response.php',
]
];
Tip
We see thatautoload.phpis configured to load thesupport/Request.phpandsupport/Response.phpfiles. This is because there are also two identical files invendor/workerman/webman-framework/src/support/. By prioritizing the loading ofsupport/Request.phpandsupport/Response.phpfrom the project root directory, we allow customization of these two files' content without modifying the files invendor. If you do not need to customize them, you can ignore these configurations.