Skip to content

Commit 7fd26f3

Browse files
Remove filesystem interface
1 parent 7b33342 commit 7fd26f3

File tree

3 files changed

+35
-53
lines changed

3 files changed

+35
-53
lines changed

src/Filesystem.php

+34-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,42 @@
22

33
namespace Spatie\Snapshots;
44

5-
interface Filesystem
5+
class Filesystem
66
{
7-
public function path(string $filename): string;
7+
/** @var string */
8+
private $basePath;
89

9-
public function has(string $filename): bool;
10+
public function __construct(string $basePath)
11+
{
12+
$this->basePath = $basePath;
13+
}
1014

11-
public function read(string $filename): bool;
15+
public static function inDirectory(string $path): self
16+
{
17+
return new self($path);
18+
}
1219

13-
public function put(string $filename, string $contents);
20+
public function path(string $filename): string
21+
{
22+
return $this->basePath.DIRECTORY_SEPARATOR.$filename;
23+
}
24+
25+
public function has(string $filename): bool
26+
{
27+
return file_exists($this->path($filename));
28+
}
29+
30+
public function read(string $filename): bool
31+
{
32+
return file_get_contents($this->path($filename));
33+
}
34+
35+
public function put(string $filename, string $contents)
36+
{
37+
if (! file_exists($this->basePath)) {
38+
mkdir($this->basePath);
39+
}
40+
41+
file_put_contents($this->path($filename), $contents);
42+
}
1443
}

src/Filesystems/LocalFilesystem.php

-45
This file was deleted.

src/Snapshot.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Spatie\Snapshots;
44

5-
use Spatie\Snapshots\Filesystems\LocalFilesystem;
6-
75
class Snapshot
86
{
97
/** @var string */
@@ -31,7 +29,7 @@ public static function forTestCase(
3129
string $directory,
3230
Driver $driver
3331
): self {
34-
$filesystem = LocalFilesystem::inDirectory($directory);
32+
$filesystem = Filesystem::inDirectory($directory);
3533

3634
$id = "{$namespace}__{$test}";
3735

0 commit comments

Comments
 (0)