2016-08-24 07:01:41 +02: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
|
|
|
|
2016-11-15 06:17:19 +01:00
|
|
|
use Interop\Async\Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
2015-07-30 16:10:53 +02:00
|
|
|
interface Driver {
|
2015-08-13 01:02:41 +02:00
|
|
|
/**
|
|
|
|
* Open a handle for the specified path
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param string $mode
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<\Amp\File\Handle>
|
2015-08-13 01:02:41 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function open(string $path, string $mode): Promise;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
|
|
|
* Execute a file stat operation
|
|
|
|
*
|
|
|
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
|
|
|
*
|
|
|
|
* @param string $path The file system path to stat
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<array|null>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function stat(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-08-08 16:09:07 +02:00
|
|
|
/**
|
|
|
|
* Does the specified path exist?
|
|
|
|
*
|
|
|
|
* This function should never resolve as a failure -- only a successfull bool value
|
|
|
|
* indicating the existence of the specified path.
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<bool>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function exists(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the size in bytes of the file at the specified path.
|
|
|
|
*
|
|
|
|
* If the path does not exist or is not a regular file this
|
|
|
|
* function's returned Promise WILL resolve as a failure.
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<int>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function size(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the specified path exist and is it a directory?
|
|
|
|
*
|
|
|
|
* If the path does not exist the returned Promise will resolve
|
|
|
|
* to FALSE and will not reject with an error.
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<bool>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function isdir(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the specified path exist and is it a file?
|
|
|
|
*
|
|
|
|
* If the path does not exist the returned Promise will resolve
|
|
|
|
* to FALSE and will not reject with an error.
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<bool>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function isfile(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the path's last modification time as a unix timestamp
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<int>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function mtime(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the path's last access time as a unix timestamp
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<int>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function atime(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the path's creation time as a unix timestamp
|
|
|
|
*
|
|
|
|
* @param string $path An absolute file system path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise<int>
|
2015-08-08 16:09:07 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function ctime(string $path): Promise;
|
2015-08-08 16:09:07 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
|
|
|
* Same as stat() except if the path is a link then the link's data is returned
|
|
|
|
*
|
|
|
|
* @param string $path The file system path to stat
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise A promise resolving to an associative array upon successful resolution
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function lstat(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a symlink $link pointing to the file/directory located at $target
|
|
|
|
*
|
|
|
|
* @param string $target
|
|
|
|
* @param string $link
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function symlink(string $target, string $link): Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a hard link $link pointing to the file/directory located at $target
|
|
|
|
*
|
|
|
|
* @param string $target
|
|
|
|
* @param string $link
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function link(string $target, string $link): Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the symlink at $path.
|
|
|
|
*
|
|
|
|
* @param string $target
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function readlink(string $target): Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
|
|
|
* Rename a file or directory
|
|
|
|
*
|
|
|
|
* @param string $from
|
|
|
|
* @param string $to
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function rename(string $from, string $to): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a file
|
|
|
|
*
|
|
|
|
* @param string $path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function unlink(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a director
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $mode
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function mkdir(string $path, int $mode = 0644): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a directory
|
|
|
|
*
|
|
|
|
* @param string $path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function rmdir(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an array of files and directories inside the specified path
|
|
|
|
*
|
|
|
|
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
|
|
|
*
|
|
|
|
* @param string $path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function scandir(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* chmod a file or directory
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $mode
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function chmod(string $path, int $mode): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* chown a file or directory
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $uid
|
|
|
|
* @param int $gid
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function chown(string $path, int $uid, int $gid): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-07-18 20:53:46 +02:00
|
|
|
/**
|
|
|
|
* Update the access and modification time of the specified path
|
|
|
|
*
|
|
|
|
* If the file does not exist it will be created automatically.
|
|
|
|
*
|
|
|
|
* @param string $path
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise
|
2015-07-18 20:53:46 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function touch(string $path): Promise;
|
2015-07-18 20:53:46 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
|
|
|
* Buffer the specified file's contents
|
|
|
|
*
|
|
|
|
* @param string $path The file path from which to buffer contents
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise A promise resolving to a string upon successful resolution
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function get(string $path): Promise;
|
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
|
2016-11-15 06:17:19 +01:00
|
|
|
* @return \Interop\Async\Promise A promise resolving to the integer length written upon success
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2016-11-15 06:17:19 +01:00
|
|
|
public function put(string $path, string $contents): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|