Skip to content

Commit b68afd0

Browse files
committed
docs: Improve README and Path class documentation for clarity and usage examples
1 parent a896d0c commit b68afd0

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
<br />
1414

15-
A simple, type-safe PHP library for working with file system paths.
16-
It handles path normalization, manipulation, and cross-platform compatibility (Windows and Unix) so you don't have to worry about slashes and edge cases.
15+
A type-safe library for working with file system paths.
16+
Handles normalization, cross-platform compatibility, and all the edge cases with slashes and separators.
17+
18+
Path is an immutable value object – all methods return new instances, so it's safe to use as a DTO,
19+
pass between layers, or store in your domain models without worrying about side effects.
1720

1821
## Installation
1922

src/Path.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,35 @@
44

55
namespace Internal;
66

7+
/**
8+
* Immutable value object for working with file system paths.
9+
*
10+
* Handles path normalization and manipulation across different operating systems.
11+
* Paths are automatically normalized: `.` and `..` segments are resolved, duplicate
12+
* separators are removed, and both `/` and `\` are accepted. Windows drive letters
13+
* like `C:/Users` are properly recognized.
14+
*
15+
* This object is designed to be used as a DTO or value object throughout your application.
16+
* All methods return new instances, making it safe to pass between layers, store in properties,
17+
* or use as command/query parameters without worrying about unexpected mutations.
18+
*
19+
* ```
20+
* $path = Path::create('/var/www/app');
21+
* $full = $path->join('src', 'Controller.php');
22+
* echo $full; // '/var/www/app/src/Controller.php'
23+
*
24+
* $file = Path::create('report.pdf');
25+
* $file->name(); // 'report.pdf'
26+
* $file->stem(); // 'report'
27+
* $file->extension(); // 'pdf'
28+
* ```
29+
*/
730
final class Path implements \Stringable
831
{
32+
/**
33+
* Directory separator used internally.
34+
* All paths are normalized to use forward slash regardless of OS.
35+
*/
936
private const DS = '/';
1037

1138
/**
@@ -203,8 +230,8 @@ public function absolute(): self
203230
*
204231
* @param non-empty-string|self $pattern The pattern to match against. Can be a string path or Path object.
205232
* Will be converted to absolute path before matching.
206-
* @param bool|null $caseSensitive Whether the match should be case-sensitive. If null, uses OS default:
207-
* case-insensitive on Windows, case-sensitive on Unix/Linux.
233+
* @param bool|null $caseSensitive Whether the match should be case-sensitive.
234+
* If null, uses OS default: case-insensitive on Windows, case-sensitive on Unix/Linux.
208235
*
209236
* @return bool True if the path matches the pattern, false otherwise.
210237
*/

0 commit comments

Comments
 (0)