app/Plugin/* の services 自動登録がプラグイン同梱の非PSR-4ライブラリ(例: phpseclib)で例外になる
- Dominant language
- PHP
- Stars
- 788
- Forks
- 719
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 39
Description
## 概要
`app/config/eccube/services.yaml` の `Plugin\` リソース定義が `app/Plugin/*` を PSR-4 で自動登録する際、プラグインが同梱する **非 PSR-4 準拠のライブラリファイル**(例: phpseclib の `bootstrap.php`)を拾ってしまい、Symfony DI の `FileLoader::registerClasses` が `Expected to find class "..." but it was not found!` 例外を投げます。
## 再現手順
1. 任意のプラグイン配下に、非 Entity かつ PSR-4 に一致しない PHP ファイルを置く。例:
```
app/Plugin/AmazonPayV2_42_Bundle/phpseclib/bootstrap.php
```
(`bootstrap.php` はクラスを宣言しない手続き的ファイル)
2. コンテナをビルドするコマンドを実行:
```
bin/console cache:warmup
# または
bin/console doctrine:schema:update --dump-sql
```
3. 次の例外が発生:
```
Expected to find class "Plugin\AmazonPayV2_42_Bundle\phpseclib\bootstrap"
in file ".../app/Plugin/AmazonPayV2_42_Bundle/phpseclib/bootstrap.php"
while importing services from resource "../../../app/Plugin/*",
but it was not found! Check the namespace prefix used with the resource
in .../app/config/eccube/services.yaml
```
## 原因
`app/config/eccube/services.yaml`:
```yaml
Plugin\:
resource: '../../../app/Plugin/*'
exclude: '../../../app/Plugin/*/{Entity,Resource,ServiceProvider,Tests,Codeception,DoctrineMigrations}'
```
`exclude` が `Entity` / `Resource` / `ServiceProvider` / `Tests` / `Codeception` / `DoctrineMigrations` のみで、プラグインが同梱するライブラリのディレクトリ(`phpseclib` など)を除外していません。PSR-4 探索がそれらのファイルからパスに対応するクラスを探そうとし、クラスが見つからず失敗します。
## 影響範囲
- **4.4 の base ブランチで再現します**(特定の PR / 変更に依存しない既存問題)。
- 非 PSR-4 のライブラリを同梱するプラグインを配置した環境で、`cache:warmup` / `cache:clear`(warmup 込み)/ `doctrine:schema:update` 等のコンテナビルドを伴う操作が失敗しうる。
## 対応案(要検討)
- `exclude` を拡張し、一般的な非 PSR-4 ディレクトリ(同梱ライブラリ等)を除外する
- あるいは対象を「プラグインルート直下の PSR-4 準拠ディレクトリのみ」に限定する
- あるいは各プラグイン側で services 定義の exclude を持たせる規約とする
## 補足
本件は #6895(Entity の `if (!class_exists())` ガード全廃)のレビューコメントで、`scanTraits` の正規表現が原因ではないかとご指摘いただいたのが発端です。検証したところ、`src/Eccube/Service/EntityProxyService.php` と `src/Eccube/Kernel.php` を base 4.4 の版に戻しても(= #6895 の変更を一切含まなくても)同一の例外が再現しました。したがって本例外は Symfony DI(`services.yaml` の `Plugin\` リソース glob)由来の**独立した既存問題**であり、#6895 の変更とは切り離して扱うべきと考え、別 issue として起票します。
Contributor guide
Research direction
Start with app/config/eccube/services.yaml and inspect the Plugin\ resource and its exclude pattern. Reproduce the failure with a non-PSR-4 file such as app/Plugin/AmazonPayV2_42_Bundle/phpseclib/bootstrap.php by running bin/console cache:warmup or doctrine:schema:update --dump-sql. Done means container-building commands succeed while preserving service discovery for valid plugin classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100