Skip to content

Commit 9ef642b

Browse files
committed
Document the Path::join() method
- Add clear documentation for path joining behavior - Show examples for common use cases - Clarify that leading slashes in subsequent arguments are removed - Include examples for empty parts, trailing slashes, and multiple arguments
1 parent 16f868c commit 9ef642b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

components/filesystem.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,44 @@ Malformed paths are returned unchanged::
359359
echo Path::canonicalize('C:Programs/PHP/php.ini');
360360
// => C:Programs/PHP/php.ini
361361

362+
Joining Paths
363+
~~~~~~~~~~~~~
364+
365+
The :method:`Symfony\\Component\\Filesystem\\Path::join` method concatenates
366+
the given paths and normalizes separators. It's a cleaner alternative to
367+
string concatenation for building file paths::
368+
369+
echo Path::join('/var/www', 'vhost', 'config.ini');
370+
// => /var/www/vhost/config.ini
371+
372+
echo Path::join('C:\\Program Files', 'PHP', 'php.ini');
373+
// => C:/Program Files/PHP/php.ini
374+
375+
The method handles multiple scenarios correctly:
376+
377+
- Empty parts are ignored::
378+
379+
echo Path::join('/var/www', '', 'config.ini');
380+
// => /var/www/config.ini
381+
382+
- Leading slashes in subsequent arguments are removed::
383+
384+
echo Path::join('/var/www', '/etc', 'config.ini');
385+
// => /var/www/etc/config.ini
386+
387+
- Trailing slashes are preserved only for root paths::
388+
389+
echo Path::join('/var/www', 'vhost/');
390+
// => /var/www/vhost
391+
392+
echo Path::join('/', '');
393+
// => /
394+
395+
- Works with any number of arguments::
396+
397+
echo Path::join('/var', 'www', 'vhost', 'symfony', 'config', 'config.ini');
398+
// => /var/www/vhost/symfony/config/config.ini
399+
362400
Converting Absolute/Relative Paths
363401
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364402

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy