Repository navigation
Open
Labels
Milestone
Description
Summary
Declare the framework's 30 helper files in autoload.files of composer.json, and stop scanning for them in LoadHelpersStage.
Why
LoadHelpersStagefinds the component helpers on every boot: it scanssrc/*/Helperswithgloband runsrequire_onceon each file. The rootcomposer.jsonhas nofilesentry today.- The helper files are plain function definitions. They have no constants and no code that runs when the file is included, and only two files have guards (the
cron_*functions and thegetallheaderspolyfill), which is the shape Composerfilesexpects. - A static list from Composer replaces about 26 directory scans on every boot, and tools such as PHPStan and IDEs see the functions without booting the application.
- The packages are to be extracted into separate Composer packages from 4.0, each with its own
composer.jsonand its own helpers. If the helpers are already declared withautoload.filesin the monorepo, extraction only moves each package's list into its owncomposer.json.
Scope
- Add the 30 helper files (26 packages:
Apphas 4,Environmenthas 2, every other package has 1) toautoload.filesincomposer.json. - Remove the component part of
LoadHelpersStage. It keeps loading the application'shelpers/and each module'shelpers/, which are the application's own files. - Add a test that fails when a file in
src/*/Helpersis not listed inautoload.files, or when a listed file does not exist. Without it, a new helper file that is not added tocomposer.jsonshows up only as "undefined function". - Update the documentation that describes helper loading at boot (the App architecture page) when this is released.
Notes
- The helpers become available as soon as
vendor/autoload.phpis included, not at boot. They useDSonly inside function bodies, so loading earlier is safe. - Adding a helper file needs an entry in
composer.jsonand acomposer dump-autoload, instead of being picked up by the scan. - When a package is later extracted, the paths in its list may change if its folder layout differs from
src/<Package>/Helpers/.
Out of scope
- Extracting any package.
- Loading the application's and the modules' helpers.
- Changing what any helper function does.
Acceptance criteria
- every helper function is available right after
vendor/autoload.php, without booting the application - the boot no longer scans
src/*/Helpers - the application's and the modules' helpers still load, in the same order after the framework's
- the new test fails for an unlisted helper file
composer test,composer cs:check,composer phpstanandcomposer rector:checkpass on every PHP version in the CI matrix
Activity