1
0
mirror of https://github.com/danog/file.git synced 2024-12-11 16:59:39 +01:00
file/src/FilesystemDriver.php

171 lines
4.5 KiB
PHP
Raw Normal View History

<?php
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
{
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
*
* @param string $path
* @param string $mode
2020-06-24 22:00:24 +02:00
*
2020-10-08 16:23:44 +02:00
* @return File
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
*
* If the requested path does not exist the resulting Promise will resolve to NULL.
*
* @param string $path The file system path to stat.
2020-06-24 22:00:24 +02:00
*
2020-10-08 16:23:44 +02:00
* @return array|null
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
*
2020-06-30 21:45:09 +02:00
* If the requested path does not exist the resulting Promise will resolve to NULL.
*
* @param string $path The file system path to stat.
2020-06-24 22:00:24 +02:00
*
2020-10-08 16:23:44 +02:00
* @return array|null A promise resolving to an associative array upon successful resolution.
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
*
* @param string $target
* @param string $link
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
/**
2017-06-17 23:41:57 +02:00
* Create a hard link $link pointing to the file/directory located at $target.
*
* @param string $target
* @param string $link
2021-12-22 22:54:20 +01:00
*
* @throws FilesystemException
*/
2020-10-08 16:23:44 +02:00
public function createHardlink(string $target, string $link): void;
2017-01-11 14:22:06 +01:00
/**
2020-06-30 21:45:09 +02:00
* Resolve the symlink at $path.
*
* @param string $target
2021-12-22 22:54:20 +01:00
*
* @throws FilesystemException
*/
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
*
* @param string $from
* @param string $to
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
*
* @param string $path
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
*
* @param string $path
2021-12-22 22:54:20 +01:00
* @param int $mode
*
* @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.
*
* @param string $path
2021-12-22 22:54:20 +01:00
* @param int $mode
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
*
* @param string $path
*/
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 "..").
*
* @param string $path
2020-06-24 22:00:24 +02:00
*
2020-10-08 16:23:44 +02:00
* @return list<string>
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
*
* @param string $path
2021-12-22 22:54:20 +01:00
* @param int $mode
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
*
2021-12-22 22:54:20 +01:00
* @param string $path
* @param int|null $uid
* @param int|null $gid
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.
*
2021-12-22 22:54:20 +01:00
* @param string $path
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.
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
*
* @param string $path The file path from which to buffer contents.
2020-06-24 22:00:24 +02:00
*
2020-10-08 16:23:44 +02:00
* @return string A promise resolving to a string upon successful resolution.
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.
*
* @param string $path The file path to which to $contents should be written.
* @param string $contents The data to write to the specified $path.
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
}