-
Notifications
You must be signed in to change notification settings - Fork 3
PrivatebinPipe
It holds the core internally and each setter method returns a Closure(PrivatebinPipe): PrivatebinPipe, allowing natural composition with PHP 8.5's |> pipe operator.
Terminal operations (encode, encodeAndPost, fetch, …) return result arrays.
use Cyvax\Clients\PrivatebinPipe;Caution
Requires PHP 8.5+ to use the native |> pipe operator syntax.
If you still want to use this client on older PHP versions, see Without the pipe operator.
$result = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::text('Hello, world!')
|> PrivatebinPipe::expire('1day')
|> PrivatebinPipe::formatter('markdown')
|> PrivatebinPipe::compression('zlib')
|> PrivatebinPipe::discussion(false)
|> PrivatebinPipe::burn(false)
|> PrivatebinPipe::encodeAndPost();$encoded = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::text('Hello!')
|> PrivatebinPipe::encode();
// $encoded['b58'] - Base58 decryption key
// $encoded['data'] - encrypted payload$decrypted = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::fetchAndDecrypt('abc123', 'Base58EncodedKey');
echo $decrypted['paste'];$decrypted = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::fetchAndDecrypt('abc123', 'Base58EncodedKey', 'my-password');Important
While fully supported, this style is generally less readable than using Privatebin or PrivatebinSnakeCase directly.
On PHP < 8.5, you can invoke the closures manually:
$client = PrivatebinPipe::init('https://privatebin.net/');
$client = PrivatebinPipe::text('Hello!')($client);
$client = PrivatebinPipe::expire('1day')($client);
$result = PrivatebinPipe::encodeAndPost()($client);Creates and returns a PrivatebinPipe instance. This is the only method that is not a closure - it is the pipe entry point and must be the first call in every chain.
PrivatebinPipe::init(
url: 'https://paste.i2pd.xyz/',
text: '',
password: null,
expire: '1day',
formatter: 'plaintext',
compression: 'zlib',
discussion: false,
burn: false,
debug: false,
sslVerify: true,
options: [],
httpClient: null,
encryptor: null,
): PrivatebinPipeCustom HTTP client and encryptor can be passed via the last two parameters.
See Advanced for implementing these interfaces.
Each returns Closure(PrivatebinPipe): PrivatebinPipe.
| Method | Parameter |
|---|---|
url(string $url) |
PrivateBin instance URL |
text(string $text) |
Paste body |
password(string $password) |
Extra password |
expire(string $expire, bool $bypass = false) |
Expiry - see valid values |
formatter(string $formatter, bool $bypass = false) |
Formatter - see valid values |
compression(string $compression) |
'zlib' or 'none'
|
discussion(bool $discussion) |
Enable comments (disables burn) |
burn(bool $burn) |
Burn after reading (disables discussion) |
attachment(string $fileLocation, ?string $filename) |
File path |
debug(bool $debug) |
Print debug output |
sslVerify(bool $sslVerify) |
Verify SSL certificates (default: true) |
After decryption, attachment contains a data URI (data:mime/type;base64,…) and attachment_name contains the filename.
These terminate the pipe chain and return arrays instead of a PrivatebinPipe instance.
| Method | Returns |
|---|---|
encode() |
array{data: array, b58: string} |
encodeAndPost() |
array{requests_result: object, b58: string} |
fetch(string $id) |
Raw server response array |
fetchAndDecrypt(string $id, string $b58, ?string $password) |
array{paste: string, attachment: string|null, attachment_name: string|null} |
decrypt(array $fetchResult, string $b58, ?string $password) |
array{paste: string, attachment: string|null, attachment_name: string|null} |
All methods that communicate with the server or perform encryption may throw Cyvax\Exceptions\PrivatebinException. See API Reference - Exceptions for the full matrix.
use Cyvax\Clients\PrivatebinPipe;
$result = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::text('# Hello from pipe')
|> PrivatebinPipe::formatter('markdown')
|> PrivatebinPipe::expire('1hour')
|> PrivatebinPipe::compression('none')
|> PrivatebinPipe::encodeAndPost();
$id = $result['requests_result']->id;
$key = $result['b58'];
$decrypted = PrivatebinPipe::init('https://privatebin.net/')
|> PrivatebinPipe::fetchAndDecrypt($id, $key);
echo $decrypted['paste']; // '# Hello from pipe'