2022-12-17 22:52:21 +01:00
|
|
|
<?php declare(strict_types=1);
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-08-05 16:55:56 +02:00
|
|
|
namespace Amp\File;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2022-02-08 19:49:16 +01:00
|
|
|
interface FilesystemDriver
|
2018-10-27 17:57:31 +02:00
|
|
|
{
|
2015-08-13 01:02:41 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Open a handle for the specified path.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2015-08-13 01:02:41 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function openFile(string $path, string $mode): File;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Get file status; also known as stat operation.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* If the requested path does not exist, it returns {@code null}.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file system path to stat.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function getStatus(string $path): ?array;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2022-02-08 19:49:16 +01:00
|
|
|
* Same as {@see FilesystemDriver::getStatus()} except if the path is a link then the link's data is returned.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2023-03-02 22:50:39 +01:00
|
|
|
* If the requested path does not exist, this method will return NULL.
|
2020-06-30 21:45:09 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file system path to stat.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* @return array|null An associative array upon successful completion.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function getLinkStatus(string $path): ?array;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Create a symlink $link pointing to the file/directory located at $target.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function createSymlink(string $target, string $link): void;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2016-08-24 06:55:06 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Create a hard link $link pointing to the file/directory located at $target.
|
2016-08-24 06:55:06 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function createHardlink(string $target, string $link): void;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2016-08-24 06:55:06 +02:00
|
|
|
/**
|
2020-06-30 21:45:09 +02:00
|
|
|
* Resolve the symlink at $path.
|
2016-08-24 06:55:06 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function resolveSymlink(string $target): string;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Move / rename a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function move(string $from, string $to): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Delete a file.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function deleteFile(string $path): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Create a directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2021-12-22 22:54:20 +01:00
|
|
|
* @throws FilesystemException
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function createDirectory(string $path, int $mode = 0777): void;
|
2020-06-30 21:45:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a directory recursively.
|
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* @throws FilesystemException If the operation fails.
|
2020-06-30 21:45:09 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function createDirectoryRecursively(string $path, int $mode = 0777): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Delete a directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function deleteDirectory(string $path): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Retrieve an array of files and directories inside the specified path.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
|
|
|
*
|
2020-10-08 16:23:44 +02:00
|
|
|
* @return list<string>
|
2022-02-08 22:20:28 +01:00
|
|
|
*
|
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function listFiles(string $path): array;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* chmod a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function changePermissions(string $path, int $mode): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* chown a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2022-02-08 22:20:28 +01:00
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function changeOwner(string $path, ?int $uid, ?int $gid): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-07-18 20:53:46 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Update the access and modification time of the specified path.
|
2015-07-18 20:53:46 +02:00
|
|
|
*
|
|
|
|
* If the file does not exist it will be created automatically.
|
|
|
|
*
|
2020-06-30 21:45:09 +02:00
|
|
|
* @param int|null $modificationTime The touch time. If $time is not supplied, the current system time is used.
|
|
|
|
* @param int|null $accessTime The access time. If $atime is not supplied, value passed to the $time parameter is
|
|
|
|
* used.
|
2022-02-08 22:20:28 +01:00
|
|
|
*
|
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-18 20:53:46 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function touch(string $path, ?int $modificationTime, ?int $accessTime): void;
|
2015-07-18 20:53:46 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Buffer the specified file's contents.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file path from which to buffer contents.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2023-03-02 22:50:39 +01:00
|
|
|
* @return string The file contents.
|
2022-02-08 22:20:28 +01:00
|
|
|
*
|
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function read(string $path): string;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the contents string to the specified path.
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file path to which to $contents should be written.
|
|
|
|
* @param string $contents The data to write to the specified $path.
|
2022-02-08 22:20:28 +01:00
|
|
|
*
|
|
|
|
* @throws FilesystemException If the operation fails.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-10-08 16:23:44 +02:00
|
|
|
public function write(string $path, string $contents): void;
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|