Skip to content

[Filesystem] Improve exists() behaviour to be able to differentiate files/dirs #34037

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

Closed
wants to merge 7 commits into from
Closed

[Filesystem] Improve exists() behaviour to be able to differentiate files/dirs #34037

wants to merge 7 commits into from

Conversation

jejem
Copy link

@jejem jejem commented Oct 18, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #33873
License MIT
Doc PR symfony/symfony-docs#12516

The current implementation of Filesystem::exists allowed to check whether a file is present on the filesystem, without any kind of distinction on the file type, so it is blind about the fact that it can be a file, directory, symlink, socket, ...

The new (optional) second argument allows to specify whether we want to check against a specific file type. I used the standard Unix/POSIX file types definition (see https://en.wikipedia.org/wiki/Unix_file_types), and implemented regular/directory. Class constants were added to list/use the available file types.

The change is BC and didn't alter the default/previous behaviour. I already pushed a usage example in the associated documentation.

@xabbuh
Copy link
Member

xabbuh commented Oct 26, 2019

What about not having this implemented as options to be passed to the exists() method but having dedicated methods for this that are named similarly to the existing is_file() and is_dir() functions in PHP? So something like isFile()/isDir() or fileExists()/dirExists()?

@nicolas-grekas
Copy link
Member

I'm closing because is_dir() and is_file() are just fine. The component doesn't need to re-implement the native function that are working well enough.
Thanks for opening.

@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
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 class improvement
7 participants