Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`OrderExtension` and `OrderFilter` pass string sort directions, deprecated since `doctrine/orm` 3.7

オープン 初心者向け
#8,648 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@VincentLanglet がすでに取り組んでいます。

2026年10月7日 から。

  • #8654 @VincentLanglet による — オープン

評価

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

調査の方向性

src/Doctrine/Orm/Extension/OrderExtension.php の 72 行目と 85 行目、および src/Doctrine/Orm/Filter/OrderFilter.php の 281 行目と 284 行目から始める。これらでは 'ASC'/'DESC' リテラルが orderBy()/addOrderBy() に渡されている。doctrine/orm >= 3.7 の場合にのみ \SortDirection::Ascending/Descending へマップし(判定は Composer\InstalledVersions または QueryBuilder::addOrderBy() に対するリフレクションによる)、それ以外は文字列を返す小さなヘルパーを導入し、OrderFilter の nulls の扱いを含む 4 すべての呼び出し箇所に適用する。完了の条件は、doctrine/orm 3.7 でのコレクションリクエストで文字列ソートの deprecation が出ないこと、および ORM 2.17/^3.3 で壊れないこと — 既存の Doctrine ORM extension/filter のテストスイートで検証する。

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

説明

API Platform affected: 4.3.21, and the current heads of 4.4, 5.0 and main

The doctrine/orm 3.7 deprecates string based sort directions in QueryBuilder::orderBy() and addOrderBy(). It wants the PHP 8.6 \SortDirection enum instead, which ORM itself requires through symfony/polyfill-php86. See "Deprecated using strings or null as sort directions" in https://github.com/doctrine/orm/blob/3.7.x/UPGRADE.md

OrderExtension and OrderFilter still pass 'ASC' and 'DESC' literals:

Line 85 matters most. collection.order defaults to ASC, so every Doctrine collection without its own order gets addOrderBy('o.id', 'ASC'). Any app on doctrine/orm 3.7 sees this on its first collection request:

Passing string as $order to Doctrine\ORM\QueryBuilder::addOrderBy() is deprecated, use an instance of SortDirection instead.
(QueryBuilder.php:1518 called by QueryBuilder.php:1254, https://github.com/doctrine/orm/issues/11313, package doctrine/orm)

The message names QueryBuilder.php as the caller, and doctrine/deprecations reports it only once per process, so it took me a while to trace it back to API Platform. We fixed all our own orderBy() calls and it kept coming.

How to reproduce

PHP 8.4, Symfony 8.1, doctrine/orm 3.7.3, deprecations visible (for example PHPUnit with failOnDeprecation). Request any Doctrine-backed GetCollection.

Possible solution

As the API Platform still allows doctrine/orm ^2.17 || ^3.3, passing the enum unconditionally would break older ORM versions. A small helper could map 'ASC'/'DESC' to \SortDirection::Ascending/Descending when the installed ORM is 3.7 or newer, and return the string otherwise. The version check could use i.e. Composer\InstalledVersions, or reflection on the second parameter of QueryBuilder::addOrderBy(). OrderFilter needs the same mapping, including the nulls handling on line 281.

I could prepare such PR if proposed solution fits. Which branch should it target then, 4.4?

主要言語
PHP
スター
2.6k
フォーク
987
平均マージ
1日 8時間
マージ済み PR(30日)
90

環境構築

はじめの一歩

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

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

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

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