Skip to content

[Filesystem] Add the Path class #41954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged

Conversation

theofidry
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #26523
License MIT
Doc PR TODO

Re-opening #30969 as requested by @fabpot.

This PR proposes a low-level, performant and pure API to manipulate file paths.

Two methods Path::isAbsolute() and Path::isRelative() are similar to Filesystem::isAbsolutePath() and Filesystem::makePathRelative(). They are however different as the methods from Path do not check the existence of the path which is very helpful in some scenarios (for example when manipulating virtual paths such as "regular" paths of a PHAR).

The original code comes from webmozart/path-util from which the path part was extracted. The library is very stable, well tested and documented. It has been heavily used in Puli, which although is no longer active has been a good performance test and is used in several other popular projects such as:

  • vimeo/psalm
  • drush/drush
  • infection/infection
  • humbug/box
  • humbug/php-scoper
  • phpbench/phpbench

It however suffers from lack of maintener from @webmozart which no longer has time to maintain it.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Still pretty sure there are some places in core that could leverage this. That might be for another PR though.

@theofidry
Copy link
Contributor Author

theofidry commented Jul 5, 2021

Still pretty sure there are some places in core that could leverage this. That might be for another PR though.

I am not familiar enough with the code-base to spot those. But as a rule of thumb, I would keep the current usages of Filesystem::isAbsolutePath() as it is a stronger check than Path::isAbsolute()

@OskarStark
Copy link
Contributor

Can you please target 🎯 6.0, as we are not allowed to introduce experimental classes in an LTS version.

@Nyholm
Copy link
Member

Nyholm commented Jul 23, 2021

Can you please target 🎯 6.0, as we are not allowed to introduce experimental classes in an LTS version.

@OskarStark is correct. We cannot have experimental code in LTS. However, we can make this new class non-experimental. It is a well used class outside of Symfony as the PR description tells.

@theofidry, Do what you prefer.

@chalasr
Copy link
Member

chalasr commented Jul 23, 2021

Since this has already proven useful and it’s not controversial, I vote for 5.4 with no experimental flag.

@chalasr
Copy link
Member

chalasr commented Jul 25, 2021

Please rebase :) We cannot merge PRs that contain merge commits

@theofidry theofidry force-pushed the feature/path-component branch from cce7eb6 to 9854256 Compare July 25, 2021 12:21
@theofidry
Copy link
Contributor Author

theofidry commented Jul 25, 2021

Please rebase :) We cannot merge PRs that contain merge commits

Is there a technical reason for that choice or is it just the process in place? Seems weird to have to rebase which requires a force-push from the user and completely change the commits history (which messes up the GitHub discussions)

@chalasr
Copy link
Member

chalasr commented Jul 25, 2021

Yes, IIRC it's a limitation from the internal tool we use for merging, it doesn't play well with merge commits

@webmozart
Copy link
Contributor

Just adding my two cents: This PR (including its predecessor #30969) has been open for over two years (!). It's not very motivating for a contributor to have their work pending for so long, and then being asked to make small changes, rebases etc. every few months.

@theofidry rebased this 19 days ago. I think it would be a great appreciation of his work and endurance to merge this, rather than waiting again, asking for another rebase, adding more nitpick comments etc.

@chalasr chalasr force-pushed the feature/path-component branch from 3905ec6 to 512b476 Compare August 13, 2021 13:18
@chalasr
Copy link
Member

chalasr commented Aug 13, 2021

Thank you @theofidry.

This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Filesystem] Add $fs->join([$pathSegment])
8 participants