-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathopen_read_write.php
24 lines (21 loc) · 945 Bytes
/
open_read_write.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
declare(strict_types=1);
namespace Psl\File;
/**
* Open a file handle for read and write.
*
* @param non-empty-string $path
*
* @throws Exception\NotFileException If $file points to a non-file node on the filesystem.
* @throws Exception\AlreadyCreatedException If $file is already created, and $write_mode is {@see WriteMode::MUST_CREATE}.
* @throws Exception\NotFoundException If $file does not exist, and $write_mode is {@see WriteMode::TRUNCATE} or {@see WriteMode::APPEND}.
* @throws Exception\NotWritableException If $file exists, and is non-writable.
* @throws Exception\NotReadableException If $file exists, and is non-readable.
* @throws Exception\RuntimeException If unable to create the $file if it does not exist.
*/
function open_read_write(
string $path,
WriteMode $write_mode = WriteMode::OpenOrCreate,
): ReadHandleInterface&WriteHandleInterface {
return new ReadWriteHandle($path, $write_mode);
}