Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Filesystem] Add $fs->join([$pathSegment])  #26523

Copy link
Copy link
Closed
@tomasfejfar

Description

@tomasfejfar
Issue body actions
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version latest

When working with filesystem it's always very cumbersome to create path from different segments. For example, create full path from base directory, subdirectory and filename. Especially if you need to compare paths later.

What I propose is to add $filesystem->join() method. It's purpose would be to merge different path segment with path separator in a predictable way.

$filesystem->join(['some', 'path', 'segment']); // 'some/path/segment'

$filesystem->join(['/some/path/', '/subdir/', 'filename.tmp']); // '/some/path/subdir/filename.tmp'
// notice how it behaves better than implode('/', $array) in regards to doubleslashes

// following OS depended behavior is up to discussion
$filesystem->join(['c:\', '/subdir/', 'filename.tmp']); // 'c:/subdir/filename.tmp'
// that this way one can be sure that slash is separator and it works fine due to PHP transforming it on the fly when accessing the file

// also this could be useful
$filesystem->toOsSpecific('some/path\to\some/folder'); 
// 'some\path\to\some\folder' on windows
// 'some/path/to/some/folder' on linux
$filesystem->toPathWithSlashes('some\path/to\some\folder');
// always 'some/path/to/some/folder'

What do you think? I'd be happy to send a PR after it's disussed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureFilesystemRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.