Skip to content

Commit 25d4a47

Browse files
aidan-caseybrendt
andauthored
feat(filesystem): add new Filesystem component (#441)
Co-authored-by: Brent Roose <[email protected]>
1 parent 25e5d81 commit 25d4a47

18 files changed

+1004
-0
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"guzzlehttp/psr7": "^2.6.1",
4444
"illuminate/view": "~11.7.0",
4545
"jenssegers/blade": "^2.0",
46+
"mikey179/vfsstream": "^2.0@dev",
4647
"nyholm/psr7": "^1.8",
4748
"phpat/phpat": "^0.10.14",
4849
"phpbench/phpbench": "84.x-dev",
@@ -64,6 +65,7 @@
6465
"tempest/database": "self.version",
6566
"tempest/debug": "self.version",
6667
"tempest/event-bus": "self.version",
68+
"tempest/filesystem": "self.version",
6769
"tempest/generation": "self.version",
6870
"tempest/http": "self.version",
6971
"tempest/http-client": "self.version",
@@ -88,6 +90,7 @@
8890
"Tempest\\Database\\": "src/Tempest/Database/src",
8991
"Tempest\\Debug\\": "src/Tempest/Debug/src",
9092
"Tempest\\EventBus\\": "src/Tempest/EventBus/src",
93+
"Tempest\\Filesystem\\": "src/Tempest/Filesystem/src",
9194
"Tempest\\Framework\\": "src/Tempest/Framework",
9295
"Tempest\\Generation\\": "src/Tempest/Generation/src",
9396
"Tempest\\HttpClient\\": "src/Tempest/HttpClient/src",
@@ -123,6 +126,7 @@
123126
"Tempest\\Core\\Tests\\": "src/Tempest/Core/tests",
124127
"Tempest\\Database\\Tests\\": "src/Tempest/Database/tests",
125128
"Tempest\\EventBus\\Tests\\": "src/Tempest/EventBus/tests",
129+
"Tempest\\Filesystem\\Tests\\": "src/Tempest/Filesystem/tests",
126130
"Tempest\\Generation\\Tests\\": "src/Tempest/Generation/tests",
127131
"Tempest\\HttpClient\\Tests\\": "src/Tempest/HttpClient/tests",
128132
"Tempest\\Http\\Tests\\": "src/Tempest/Http/tests",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Exclude build/test files from the release
2+
.github/ export-ignore
3+
tests/ export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
phpunit.xml export-ignore
7+
README.md export-ignore
8+
9+
# Configure diff output for .php and .phar files.
10+
*.php diff=php

src/Tempest/Filesystem/LICENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Brent Roose [email protected]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "tempest/filesystem",
3+
"description": "The PHP framework that gets out of your way.",
4+
"require": {
5+
"php": "^8.3"
6+
},
7+
"autoload": {
8+
"psr-4": {
9+
"Tempest\\Filesystem\\": "src"
10+
}
11+
},
12+
"autoload-dev": {
13+
"psr-4": {
14+
"Tempest\\Filesystem\\Tests\\": "tests"
15+
}
16+
},
17+
"license": "MIT",
18+
"minimum-stability": "dev",
19+
"require-dev": {
20+
"mikey179/vfsstream": "^2.0@dev"
21+
}
22+
}

src/Tempest/Filesystem/phpunit.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" displayDetailsOnPhpunitDeprecations="true" failOnPhpunitDeprecation="false" failOnRisky="true" failOnWarning="true">
3+
<testsuites>
4+
<testsuite name="Tempest Filesystem">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
9+
<include>
10+
<directory>src</directory>
11+
</include>
12+
</source>
13+
</phpunit>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Filesystem;
6+
7+
final class ErrorContext
8+
{
9+
private array $lastError = [];
10+
11+
public function __construct()
12+
{
13+
error_clear_last();
14+
}
15+
16+
public static function reset(): self
17+
{
18+
return new self();
19+
}
20+
21+
public function getMessage(?string $default = 'Unknown error.'): string
22+
{
23+
return $this->getLastError()['message'] ?? $default;
24+
}
25+
26+
public function commit(): self
27+
{
28+
$this->lastError = error_get_last() ?? [];
29+
30+
return $this;
31+
}
32+
33+
private function getLastError(): array
34+
{
35+
return $this->lastError ??= $this->commit()->lastError;
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Filesystem\Exceptions;
6+
7+
use RuntimeException;
8+
9+
final class FileDoesNotExist extends RuntimeException
10+
{
11+
public static function atPath(string $path): FileDoesNotExist
12+
{
13+
return new self("File does not exist at path `{$path}`.");
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Filesystem\Exceptions;
6+
7+
use RuntimeException;
8+
use Tempest\Filesystem\ErrorContext;
9+
10+
final class UnableToCopyFile extends RuntimeException
11+
{
12+
public static function fromSourceToDestination(string $source, string $destination, ErrorContext $error): self
13+
{
14+
return new self(
15+
sprintf("Unable to copy file from `%s` to `%s`. %s", $source, $destination, $error->getMessage())
16+
);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Filesystem\Exceptions;
6+
7+
use RuntimeException;
8+
use Tempest\Filesystem\ErrorContext;
9+
10+
final class UnableToCreateDirectory extends RuntimeException
11+
{
12+
public static function atPath(string $path, ErrorContext $error): self
13+
{
14+
$message = sprintf('Unable to create directory at path [%s]. %s', $path, $error->getMessage());
15+
16+
return new self($message);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Filesystem\Exceptions;
6+
7+
use RuntimeException;
8+
use Tempest\Filesystem\ErrorContext;
9+
10+
final class UnableToDeleteDirectory extends RuntimeException
11+
{
12+
public static function atPath(string $path, ErrorContext $error): self
13+
{
14+
return new self(
15+
sprintf('Unable to delete directory at path: %s. %s', $path, $error->getMessage()),
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)