Remove FileSystemInterface::basename() and use PHP native basename()

Created on 17 June 2025, 7 days ago

Problem/Motivation

Cores FileSystemInterface::basename() can cause container circular references with contrib.
#3259065: Circular reference detected for service "s3fsfileservice" with mime_type guesser β†’
πŸ“Œ Copy core 11.1.x ExtensionMimeTypeGuesser to s3fs Active

FileSystem::basename()is essentially a duplication of PHP native basename()

PHP Native basename() is path unware, it functions on a path based on the directory separator.

It appears this was intended to work around https://bugs.php.net/bug.php?id=37738 however that issue no longer appears to be present in PHP as of the 8.x branch https://3v4l.org/XcflK

It makes little to no sense for basename() logic to be overridden by contrib. Any such override inside Drupal will not extend to 3rd party libraries. Even Symfony makes 27 calls to the native basename() function (I can not assert any of these methods are used by Core).

Steps to reproduce

Proposed resolution

Remove FileSystemInterface::basename()
Optionaly: Retain FileSystem::basename() in a trait that can be included when necessary (although I see no need to do this).

Remaining tasks

User interface changes

None

Introduced terminology

None

API changes

FileSystemInterface::basename() deprecation/removal

Data model changes

None

Release notes snippet

FileSystemInterface::basename() is now deprecated, use basename() instead.

πŸ“Œ Task
Status

Active

Version

11.2 πŸ”₯

Component

file system

Created by

πŸ‡ΊπŸ‡ΈUnited States cmlara

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @cmlara
  • πŸ‡ΊπŸ‡ΈUnited States cmlara
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Would be good to have a subsystem maintainer sign-off before any effort is put into code on this.

    Pinging @kimb0 (Kim Pepper) on Slack.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Looks like you are correct. I'd be happy to deprecate/remove.

    Confirmed that:

    • the bug linked in the comment is no longer relevant.
    • Directory separators are handled natively
    • The behavior of php basename() seems to handle directories ending in slash just fine.
       * PHP's basename() does not properly support streams or filenames beginning
       * with a non-US-ASCII character.
    
    @see http://bugs.php.net/bug.php?id=37738
    

    Here's an 3v4l snippet to test the standard basename() behavior:

    https://3v4l.org/5oTmX

  • Pipeline finished with Failed
    5 days ago
    Total: 144s
    #525565
  • Pipeline finished with Failed
    5 days ago
    Total: 493s
    #525607
  • Pipeline finished with Failed
    5 days ago
    Total: 231s
    #525616
  • Pipeline finished with Success
    5 days ago
    Total: 550s
    #525626
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    I reviewed the changes and confirmed that all use of FileSystemInterface::basename() have been converted to basename().

    My only question is on which version this will be removed in.

    @deprecated in drupal:11.3.0 and is removed from drupal:13.0.0.

    Is it too late to have it removed in drupal 12.0.0 ?

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    @kim.pepper Thanks for the quick review. Was typing up the following while your review came in:

    This was actually not as embedded in core as I expected it to be.

    Set deprecation for 11.3 removal in 13.0 based on (the not yet accepted) discussion in πŸ“Œ Defer disruptive 11.3 deprecations for removal until 13.0 Active out of concern it might be considered 'disruptive' (removing a method).

    As an argument it is not disruptive: basename()is PHP native and works in PHP8.1 which is the minimum supported version for any D10.x release. A module could easily support ^10 || ^11 || ^12 with just the native function.

    Above my position to make the final call on D12 vs D13 (willing to edit to D12 if it is approved).

    This does impact a deprecation added in πŸ› Separate MIME type mapping from ExtensionMimeTypeGuesser Needs work the file_system was added to the ExtensionMimeTypeGuesser as optional in D11.2 and would have been required in D12 will now be removed in D11.3.

Production build 0.71.5 2024