Load the helper files through Composer autoload instead of a boot stage

オープン
#650 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

Start with composer.json (add the 30 helper paths under autoload.files) and LoadHelpersStage, which currently globs src/*/Helpers and runs require_once on each file; keep only the application and module helper loading there. Add a test that compares the files in src/*/Helpers with the autoload.files list in both directions, then run composer dump-autoload and the test suite. Done when every helper is callable after vendor/autoload.php, the boot no longer scans src/*/Helpers, and the CI checks pass.

索引モデルが issue の本文から書いたものです。

説明

refactoring

Summary

Declare the framework's 30 helper files in autoload.files of composer.json, and stop scanning for them in LoadHelpersStage.

Why

  • LoadHelpersStage finds the component helpers on every boot: it scans src/*/Helpers with glob and runs require_once on each file. The root composer.json has no files entry 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 the getallheaders polyfill), which is the shape Composer files expects.
  • 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.json and its own helpers. If the helpers are already declared with autoload.files in the monorepo, extraction only moves each package's list into its own composer.json.

Scope

  1. Add the 30 helper files (26 packages: App has 4, Environment has 2, every other package has 1) to autoload.files in composer.json.
  2. Remove the component part of LoadHelpersStage. It keeps loading the application's helpers/ and each module's helpers/, which are the application's own files.
  3. Add a test that fails when a file in src/*/Helpers is not listed in autoload.files, or when a listed file does not exist. Without it, a new helper file that is not added to composer.json shows up only as "undefined function".
  4. 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.php is included, not at boot. They use DS only inside function bodies, so loading earlier is safe.
  • Adding a helper file needs an entry in composer.json and a composer 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 phpstan and composer rector:check pass on every PHP version in the CI matrix
主要言語
PHP
スター
43
フォーク
22
平均マージ
54分
マージ済み PR(30日)
57

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quantum-php/framework のほかの issue

quantum-php/framework の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。