Skip to content

PrivatebinPipe

cyvax edited this page May 23, 2026 · 1 revision

PrivatebinPipe - pipe client

A pipe-style client built directly on top of PrivatebinCore.

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.


Usage with |>

$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();

Encode only

$encoded = PrivatebinPipe::init('https://privatebin.net/')
    |> PrivatebinPipe::text('Hello!')
    |> PrivatebinPipe::encode();

// $encoded['b58']  - Base58 decryption key
// $encoded['data'] - encrypted payload

Fetch and decrypt

$decrypted = PrivatebinPipe::init('https://privatebin.net/')
    |> PrivatebinPipe::fetchAndDecrypt('abc123', 'Base58EncodedKey');

echo $decrypted['paste'];

With a password

$decrypted = PrivatebinPipe::init('https://privatebin.net/')
    |> PrivatebinPipe::fetchAndDecrypt('abc123', 'Base58EncodedKey', 'my-password');

Without the pipe operator

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);

Available methods

init() - factory

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,
): PrivatebinPipe

Custom HTTP client and encryptor can be passed via the last two parameters.

See Advanced for implementing these interfaces.

Setter closures

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)

Attachments

After decryption, attachment contains a data URI (data:mime/type;base64,…) and attachment_name contains the filename.

Terminal closures

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}

Exceptions

All methods that communicate with the server or perform encryption may throw Cyvax\Exceptions\PrivatebinException. See API Reference - Exceptions for the full matrix.

Full example

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'

Clone this wiki locally