Skip to content

Commit 818f1bb

Browse files
committed
updated tests.
1 parent ae14f38 commit 818f1bb

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/Core/System/IFileSystem.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,12 @@ public function rmdir( string $path ): bool;
9191
* @return array|false Array of filenames or false on failure
9292
*/
9393
public function scandir( string $path ): array|false;
94+
95+
/**
96+
* Find pathnames matching a pattern
97+
*
98+
* @param string $pattern Pattern to match (e.g., "/path/*.txt", "/path/**​/*.php")
99+
* @return array|false Array of matching paths or false on failure
100+
*/
101+
public function glob( string $pattern ): array|false;
94102
}

src/Core/System/MemoryFileSystem.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,53 @@ public function scandir( string $path ): array|false
286286
sort( $items );
287287
return $items;
288288
}
289+
290+
/**
291+
* @inheritDoc
292+
*/
293+
public function glob( string $pattern ): array|false
294+
{
295+
// Convert glob pattern to regex
296+
$regex = $this->globToRegex( $pattern );
297+
298+
$matches = [];
299+
300+
// Match files
301+
foreach( $this->files as $path => $content )
302+
{
303+
if( preg_match( $regex, $path ) )
304+
{
305+
$matches[] = $path;
306+
}
307+
}
308+
309+
// Match directories
310+
foreach( $this->directories as $path => $exists )
311+
{
312+
if( preg_match( $regex, $path ) )
313+
{
314+
$matches[] = $path;
315+
}
316+
}
317+
318+
sort( $matches );
319+
return $matches;
320+
}
321+
322+
/**
323+
* Convert glob pattern to regex pattern
324+
*
325+
* @param string $pattern Glob pattern (e.g., "/path/*.txt")
326+
* @return string Regex pattern
327+
*/
328+
private function globToRegex( string $pattern ): string
329+
{
330+
$escaped = preg_quote( $pattern, '/' );
331+
332+
// Replace escaped wildcard characters with regex equivalents
333+
$regex = str_replace( '\*', '[^/]*', $escaped );
334+
$regex = str_replace( '\?', '[^/]', $regex );
335+
336+
return '/^' . $regex . '$/';
337+
}
289338
}

src/Core/System/RealFileSystem.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,12 @@ public function scandir( string $path ): array|false
9393
{
9494
return scandir( $path );
9595
}
96+
97+
/**
98+
* @inheritDoc
99+
*/
100+
public function glob( string $pattern ): array|false
101+
{
102+
return glob( $pattern );
103+
}
96104
}

versionlog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
## 0.8.3
22

33
## 0.8.2 2025-12-10
4-
* Improved IFileSystem abstractions with additional methods.
4+
* Extended IFileSystem with directory operations: `mkdir()`, `rmdir()`, `scandir()`, and `unlink()` for comprehensive file system abstraction
5+
* Enables full testability of file-dependent code across the framework
6+
* Used by MVC FileCacheStorage for complete in-memory testing
57

68
## 0.8.1 2025-12-10
7-
* Added file system abstractions.
9+
* Added file system abstractions: `IFileSystem`, `RealFileSystem`, `MemoryFileSystem`
10+
* Core methods: `fileExists()`, `readFile()`, `writeFile()`, `isDir()`, `realpath()`, `getcwd()`
11+
* Provides testable abstraction over PHP native file functions
12+
* Enables components to be unit tested without touching real file system
813

914
## 0.8.0 2025-11-11
1015
* Added pascalCase, toUpper and toLower functions to NString.

0 commit comments

Comments
 (0)