Skip to content

Commit 38669ce

Browse files
committed
Add filesystem interface
1 parent 0861efc commit 38669ce

4 files changed

Lines changed: 204 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"require": {
1111
"php": "^8.2",
12+
"ext-fileinfo": "*",
1213
"psr/cache": "^3.0",
1314
"psr/clock": "^1.0",
1415
"psr/container": "^2.0.x-dev",

packages/Filesystem/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"source": "https://github.com/sxbrsky/aether"
99
},
1010
"require": {
11-
"php": "^8.2"
11+
"php": "^8.2",
12+
"ext-fileinfo": "*"
1213
},
1314
"minimum-stability": "dev",
1415
"autoload": {
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the aether/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Aether\Filesystem;
13+
14+
interface FilesystemInterface {
15+
/**
16+
* Checks if a file exists at the given path.
17+
*
18+
* @param string $path
19+
* @return bool
20+
* @throws \Aether\Filesystem\IOException
21+
*/
22+
public function exists(string $path): bool;
23+
24+
/**
25+
* Gets the contents of a file.
26+
*
27+
* @param string $path
28+
* @return string
29+
*/
30+
public function read(string $path): string;
31+
32+
/**
33+
* Writes the contents to a file.
34+
*
35+
* @param string $path
36+
* @param string $contents
37+
* @param bool $lock
38+
* @return void
39+
* @throws \Aether\Filesystem\IOException
40+
*/
41+
public function write(string $path, string $contents, bool $lock = false): void;
42+
43+
/**
44+
* Copies a file to a new location.
45+
*
46+
* @param string $source
47+
* @param string $destination
48+
49+
* @return void
50+
*
51+
* @throws \Aether\Filesystem\IOException
52+
*/
53+
public function copy(string $source, string $destination): void;
54+
55+
/**
56+
* Moves a file to a new location.
57+
*
58+
* @param string $source
59+
* @param string $destination
60+
*
61+
* @return void
62+
*
63+
* @throws \Aether\Filesystem\IOException
64+
*/
65+
public function move(string $source, string $destination): void;
66+
67+
/**
68+
* Appends contents to a file.
69+
*
70+
* @param string $path
71+
* @param string $contents
72+
* @return bool
73+
*/
74+
public function append(string $path, string $contents): bool;
75+
76+
/**
77+
* Sets access and modification time of file.
78+
*
79+
* @param string $filename
80+
* @param int|null $mtime
81+
* @param int|null $atime
82+
*/
83+
public function touch(string $filename, ?int $mtime = null, ?int $atime = null): void;
84+
85+
/**
86+
* Deletes a file.
87+
*
88+
* @param string|array $filename
89+
* @return void
90+
*
91+
* @throws \Aether\Filesystem\IOException
92+
*/
93+
public function unlink(string|array $filename): void;
94+
95+
/**
96+
* Creates a directory.
97+
*
98+
* @param string $directory
99+
* @param int $mode
100+
* @param bool $recursive
101+
*
102+
* @return void
103+
*
104+
* @throws \Aether\Filesystem\IOException
105+
*/
106+
public function mkdir(string $directory, int $mode = 0777, bool $recursive = true): void;
107+
108+
/**
109+
* Deletes a directory.
110+
*
111+
* @param string $directory
112+
* @return void
113+
*
114+
* @throws \Aether\Filesystem\IOException
115+
*/
116+
public function rmdir(string $directory): void;
117+
118+
/**
119+
* Gets the name.
120+
*
121+
* @param string $path
122+
* @return string
123+
*/
124+
public function name(string $path): string;
125+
126+
/**
127+
* Gets the basename.
128+
*
129+
* @param string $path
130+
* @return string
131+
*/
132+
public function basename(string $path): string;
133+
134+
/**
135+
* Gets the dirname.
136+
*
137+
* @param string $path
138+
* @return string
139+
*/
140+
public function dirname(string $path): string;
141+
142+
/**
143+
* Gets the file extension.
144+
*
145+
* @param string $path
146+
* @return string
147+
*/
148+
public function extension(string $path): string;
149+
150+
/**
151+
* Gets the file size.
152+
*
153+
* @param string $path
154+
* @return int
155+
*
156+
* @throws \Aether\Filesystem\IOException
157+
*/
158+
public function filesize(string $path): int;
159+
160+
/**
161+
* Check if a path is a directory.
162+
*
163+
* @param string $path
164+
* @return bool
165+
*/
166+
public function isDirectory(string $path): bool;
167+
168+
/**
169+
* Check if a path is a file.
170+
*
171+
* @param string $path
172+
* @return bool
173+
*/
174+
public function isFile(string $path): bool;
175+
176+
/**
177+
* Get the mime type of file.
178+
*
179+
* @param string $path
180+
* @return string
181+
*
182+
* @throws \Aether\Filesystem\IOException
183+
*/
184+
public function mimeType(string $path): string;
185+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the aether/aether.
5+
*
6+
* Copyright (C) 2024 Dominik Szamburski
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
namespace Aether\Filesystem;
13+
14+
class IOException extends \RuntimeException {
15+
16+
}

0 commit comments

Comments
 (0)