ExportXMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • PHP Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      The global SortDirection enum (provided by PHP 8.6 natively, or by symfony/polyfill-php86 for PHP 8.1 and later, with the cases Ascending and Descending) is used as a sort direction value by libraries such as the Doctrine MongoDB ODM. PHP cannot convert a SortDirection enum to an int, so each library and each user must manually map SortDirection::Ascending to 1 and SortDirection::Descending to -1 wherever a sort order is expected.

      Request: BSON normalization should recognize a SortDirection enum and encode it as 1 for Ascending and -1 for Descending, so libraries and applications can pass the enum directly when building sort specifications.

      Example

      Before: the sort order must be provided as a literal 1 or -1.

      $cursor = $collection->find([], [
          'sort' => ['createdAt' => 1, 'priority' => -1],
      ]);
      

      After: the SortDirection enum is used directly and converted by the driver during BSON normalization.

      $cursor = $collection->find([], [
          'sort' => ['createdAt' => SortDirection::Ascending, 'priority' => SortDirection::Descending],
      ]);
      

            Assignee:
            Unassigned
            Reporter:
            Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: