| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Polyfill; |
| 4: | |
| 5: | /** |
| 6: | * Base class for stream wrappers that support filesystem operations |
| 7: | * |
| 8: | * @api |
| 9: | */ |
| 10: | abstract class FilesystemStreamWrapper extends StreamWrapper |
| 11: | { |
| 12: | /** |
| 13: | * Close directory handle |
| 14: | * |
| 15: | * This method is called in response to {@see closedir()}. |
| 16: | * |
| 17: | * Any resources which were locked, or allocated, during opening and use of |
| 18: | * the directory stream should be released. |
| 19: | * |
| 20: | * @return bool `true` on success or `false` on failure. |
| 21: | */ |
| 22: | abstract public function dir_closedir(): bool; |
| 23: | |
| 24: | /** |
| 25: | * Open directory handle |
| 26: | * |
| 27: | * This method is called in response to {@see opendir()}. |
| 28: | * |
| 29: | * @param string $path Specifies the URL that was passed to |
| 30: | * {@see opendir()}. |
| 31: | * @return bool `true` on success or `false` on failure. |
| 32: | */ |
| 33: | abstract public function dir_opendir(string $path, int $options): bool; |
| 34: | |
| 35: | /** |
| 36: | * Read entry from directory handle |
| 37: | * |
| 38: | * This method is called in response to {@see readdir()}. |
| 39: | * |
| 40: | * @return string|false The next filename, or `false` if there is no next |
| 41: | * file. |
| 42: | */ |
| 43: | abstract public function dir_readdir(); |
| 44: | |
| 45: | /** |
| 46: | * Rewind directory handle |
| 47: | * |
| 48: | * This method is called in response to {@see rewinddir()}. |
| 49: | * |
| 50: | * Should reset the output generated by |
| 51: | * {@see HasDirectoryHandles::dir_readdir()}, i.e. the next call to |
| 52: | * {@see HasDirectoryHandles::dir_readdir()} should return the first entry |
| 53: | * in the location returned by {@see HasDirectoryHandles::dir_opendir()}. |
| 54: | * |
| 55: | * @return bool `true` on success or `false` on failure. |
| 56: | */ |
| 57: | abstract public function dir_rewinddir(): bool; |
| 58: | |
| 59: | /** |
| 60: | * Create a directory |
| 61: | * |
| 62: | * This method is called in response to {@see mkdir()}. |
| 63: | * |
| 64: | * @param string $path Directory which should be created. |
| 65: | * @param int $mode The value passed to {@see mkdir()}. |
| 66: | * @param int $options A bitwise mask of values, such as |
| 67: | * {@see \STREAM_MKDIR_RECURSIVE}. |
| 68: | * @return bool `true` on success or `false` on failure. |
| 69: | */ |
| 70: | abstract public function mkdir(string $path, int $mode, int $options): bool; |
| 71: | |
| 72: | /** |
| 73: | * Renames a file or directory |
| 74: | * |
| 75: | * This method is called in response to {@see rename()}. |
| 76: | * |
| 77: | * @param string $path_from The URL to the current file. |
| 78: | * @param string $path_to The URL which the **`path_from`** should be |
| 79: | * renamed to. |
| 80: | * @return bool `true` on success or `false` on failure. |
| 81: | */ |
| 82: | abstract public function rename(string $path_from, string $path_to): bool; |
| 83: | |
| 84: | /** |
| 85: | * Removes a directory |
| 86: | * |
| 87: | * This method is called in response to {@see rmdir()}. |
| 88: | * |
| 89: | * @param string $path The directory URL which should be removed. |
| 90: | * @param int $options A bitwise mask of values, such as |
| 91: | * {@see \STREAM_MKDIR_RECURSIVE}. |
| 92: | * @return bool `true` on success or `false` on failure. |
| 93: | */ |
| 94: | abstract public function rmdir(string $path, int $options): bool; |
| 95: | |
| 96: | /** |
| 97: | * Advisory file locking |
| 98: | * |
| 99: | * This method is called in response to {@see flock()}, |
| 100: | * {@see file_put_contents()} (when **`flags`** contains {@see \LOCK_EX}), |
| 101: | * {@see stream_set_blocking()} and when closing the stream |
| 102: | * ({@see \LOCK_UN}). |
| 103: | * |
| 104: | * @param int $operation One of the following: |
| 105: | * |
| 106: | * - {@see \LOCK_SH} to acquire a shared lock (reader). |
| 107: | * - {@see \LOCK_EX} to acquire an exclusive lock (writer). |
| 108: | * - {@see \LOCK_UN} to release a lock (shared or exclusive). |
| 109: | * - {@see \LOCK_NB} if you don't want {@see flock()} to block while locking |
| 110: | * (not supported on Windows). |
| 111: | * @return bool `true` on success or `false` on failure. |
| 112: | */ |
| 113: | abstract public function stream_lock(int $operation): bool; |
| 114: | |
| 115: | /** |
| 116: | * Delete a file |
| 117: | * |
| 118: | * This method is called in response to {@see unlink()}. |
| 119: | * |
| 120: | * @param string $path The file URL which should be deleted. |
| 121: | * @return bool `true` on success or `false` on failure. |
| 122: | */ |
| 123: | abstract public function unlink(string $path): bool; |
| 124: | } |
| 125: |