Autoloading
Loading PSR-0 compliant files via Composer
webman follows the PSR-4 autoloading specification. If your project needs to load PSR-0 compliant libraries, follow these steps:
- Create an
extenddirectory to store PSR-0 compliant libraries - Edit
composer.jsonand add the following underautoload:
"psr-0" : {
"": "extend/"
}
The final result should look like this:

- Run
composer dumpautoload - Run
php start.php restartto restart webman (Note: a full restart is required for changes to take effect)
Loading specific files via Composer
-
Edit
composer.jsonand add the files to load underautoload.files:"files": [ "./support/helpers.php", "./app/helpers.php" ] -
Run
composer dumpautoload -
Run
php start.php restartto restart webman (Note: a full restart is required for changes to take effect)
Note
Files configured inautoload.filesin composer.json are loaded before webman starts. Files loaded via the framework'sconfig/autoload.phpare loaded after webman starts.
Changes to files in composer.json'sautoload.filesrequire a restart to take effect; reload will not work. Files loaded via the framework'sconfig/autoload.phpsupport hot-reload; changes take effect on reload.
Loading specific files via the framework
Some files may not comply with the PSR specification and cannot be autoloaded. You can load them by configuring config/autoload.php, for example:
return [
'files' => [
base_path() . '/app/functions.php',
base_path() . '/support/Request.php',
base_path() . '/support/Response.php',
]
];
Note
autoload.phpis configured to loadsupport/Request.phpandsupport/Response.phpbecause the same files exist invendor/workerman/webman-framework/src/support/. By loading them viaautoload.php, we prioritize the versions in the project root directory, allowing you to customize these files without modifying the ones invendor. If you do not need to customize them, you can omit these two entries.