| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\SwooleException; |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* |
| 10 |
* @param string $filename The filename being written. |
| 11 |
* @param string $content The content writing to the file. |
| 12 |
* @param int $offset The offset. |
| 13 |
* @param callable $callback |
| 14 |
* @throws SwooleException |
| 15 |
* |
| 16 |
*/ |
| 17 |
function swoole_async_write(string $filename, string $content, int $offset = null, callable $callback = null): void |
| 18 |
{ |
| 19 |
error_clear_last(); |
| 20 |
if ($callback !== null) { |
| 21 |
$result = \swoole_async_write($filename, $content, $offset, $callback); |
| 22 |
} elseif ($offset !== null) { |
| 23 |
$result = \swoole_async_write($filename, $content, $offset); |
| 24 |
} else { |
| 25 |
$result = \swoole_async_write($filename, $content); |
| 26 |
} |
| 27 |
if ($result === false) { |
| 28 |
throw SwooleException::createFromPhpError(); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* |
| 35 |
* |
| 36 |
* @param string $filename The filename being written. |
| 37 |
* @param string $content The content writing to the file. |
| 38 |
* @param callable $callback |
| 39 |
* @param int $flags |
| 40 |
* @throws SwooleException |
| 41 |
* |
| 42 |
*/ |
| 43 |
function swoole_async_writefile(string $filename, string $content, callable $callback = null, int $flags = 0): void |
| 44 |
{ |
| 45 |
error_clear_last(); |
| 46 |
if ($flags !== 0) { |
| 47 |
$result = \swoole_async_writefile($filename, $content, $callback, $flags); |
| 48 |
} elseif ($callback !== null) { |
| 49 |
$result = \swoole_async_writefile($filename, $content, $callback); |
| 50 |
} else { |
| 51 |
$result = \swoole_async_writefile($filename, $content); |
| 52 |
} |
| 53 |
if ($result === false) { |
| 54 |
throw SwooleException::createFromPhpError(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
/** |
| 60 |
* |
| 61 |
* |
| 62 |
* @param callable $callback |
| 63 |
* @throws SwooleException |
| 64 |
* |
| 65 |
*/ |
| 66 |
function swoole_event_defer(callable $callback): void |
| 67 |
{ |
| 68 |
error_clear_last(); |
| 69 |
$result = \swoole_event_defer($callback); |
| 70 |
if ($result === false) { |
| 71 |
throw SwooleException::createFromPhpError(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
/** |
| 77 |
* |
| 78 |
* |
| 79 |
* @param int $fd |
| 80 |
* @throws SwooleException |
| 81 |
* |
| 82 |
*/ |
| 83 |
function swoole_event_del(int $fd): void |
| 84 |
{ |
| 85 |
error_clear_last(); |
| 86 |
$result = \swoole_event_del($fd); |
| 87 |
if ($result === false) { |
| 88 |
throw SwooleException::createFromPhpError(); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
/** |
| 94 |
* |
| 95 |
* |
| 96 |
* @param int $fd |
| 97 |
* @param string $data |
| 98 |
* @throws SwooleException |
| 99 |
* |
| 100 |
*/ |
| 101 |
function swoole_event_write(int $fd, string $data): void |
| 102 |
{ |
| 103 |
error_clear_last(); |
| 104 |
$result = \swoole_event_write($fd, $data); |
| 105 |
if ($result === false) { |
| 106 |
throw SwooleException::createFromPhpError(); |
| 107 |
} |
| 108 |
} |
| 109 |
|