LoginSignup
2
2

More than 1 year has passed since last update.

EC-CUBEで大量のmethod非推奨ログ「doctrine/inflector」

Last updated at Posted at 2021-08-03

以下のようなログが大量に出ていた。

User Deprecated: The "Doctrine\Common\Inflector\Inflector::classify" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.

ログの内容は「メソッドが非推奨になったから新しいの使えよ!」みたいな感じ。

なんでこんなに出てるんだと調べてみると「doctrine/inflector」のバージョンが1.4.*になってた。
1.4から非推奨になってた。

多分、composer updateとかしたんだろう。。。

EC-CUBEのcomposer.lockでは1.3.1
https://github.com/EC-CUBE/ec-cube/blob/8fb10d3a0151476e4d8035c039010c5e41906116/composer.lock#L1268

オイラの環境では1.4.4になってた。

解決方法は二つ

解決方法:1 doctrine/inflectorをダウングレード

1.3.*にすればいいので、バージョンを指定してダウングレード。
https://www.doctrine-project.org/projects/inflector/1.3.html

下記コマンドで一発。

composer require doctrine/inflector:1.3.1

無事にダウングレードできたら、ログは出なくなった。

解決方法:2 EC-CUBE本体を修正

コメントから「ソースコードの互換性を壊す変更になる」との事なのでEC-CUBE4.0系4.1系の場合はダウングレードでの解決がよさそうです

Inflector::classifyの使用箇所を探す。
https://github.com/EC-CUBE/ec-cube/blob/4.0/src/Eccube/Entity/AbstractEntity.php

34行目と48行目にあった。

で、doctrine/inflector:1.4.*のドキュメント
https://www.doctrine-project.org/projects/doctrine-inflector/en/1.4/index.html

src/Eccube/Entity/AbstractEntity.phpを下記のように修正した。

- use Doctrine\Common\Inflector\Inflector;
+ use Doctrine\Inflector\Inflector; 
+ use Doctrine\Inflector\InflectorFactory;

プロパティとオプジェクトを返すメソッド追加

+ private $Inflector;
+ 
+ private function getInflector() : Inflector
+ {
+     if ($this->Inflector === null) {
+         $this->Inflector = InflectorFactory::create()->build();
+     }
+ 
+     return $this->Inflector;
+ }

使用箇所を修正

- $method = Inflector::classify($offset);
+ $method = $this->getInflector()->classify($offset);

こんな感じで修正してみました。
これでログは増えないはず。。。

伝えたい事。

ログの内容を見ようぜ。
一行全部、翻訳機にぶっこんで読んでも大丈夫。

パッケージ探してみようぜ。
バージョン確認してみようぜ。
パッケージのGitHubみて、それっぽいメソッド探してみようぜ。
ドキュメント探して見ようぜ。

おわり!!

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2