PHP client library for PrivateBin.
Supports:
- Modern camelCase API (
PrivatebinPHP) - Original snake_case API (
PrivatebinSnakeCase) - Optional pipe-style helpers (
PrivatebinPHPPipe) - Attachments
- Password-protected pastes
- Burn-after-reading
- Discussions
- Compression
- Custom formatters
- SSL verification control
- PHP 7.1+ compatibility
composer require cyvax/privatebin_phpBy default, the library is configured to use:
https://paste.i2pd.xyz/
You can override it with setUrl() or via constructor options.
use Cyvax\Clients\Privatebin;
$result = (new Privatebin())
->setUrl("https://privatebin.net/")
->setText("Because ignorance is bliss!")
->setExpire("1hour")
->encodeAndPost();PrivatebinPHP::init() supports named parameters for a more concise setup on PHP 8+:
use Cyvax\Clients\Privatebin;
$result = Privatebin::init(
url: "https://privatebin.net/",
text: "Because ignorance is bliss!",
expire: "1hour",
)->encodeAndPost();use Cyvax\Clients\PrivatebinSnakeCase;
$result = (new PrivatebinSnakeCase())
->set_url("https://privatebin.net/")
->set_text("Because ignorance is bliss!")
->set_expire("1hour")
->encode_and_post();Note
PrivatebinSnakeCase is also available as the alias \Cyvax\PrivatebinPHP
for compatibility with older versions of the library.
Both clients accept an options array in their constructor:
use Cyvax\Clients\Privatebin;
$result = (new Privatebin([
"url" => "https://privatebin.net/",
"text" => "Because ignorance is bliss!",
]))->encodeAndPost();use Cyvax\Clients\Privatebin;
$result = (new Privatebin())
->setAttachment("/path/to/image.png")
->encodeAndPost();Note
setAttachment() throws PrivatebinException if the file cannot be read.
An optional second argument overrides the attachment filename:
->setAttachment("/path/to/image.png", "screenshot.png")SSL verification is enabled by default. Disable it only for local or self-signed instances:
use Cyvax\Clients\Privatebin;
$result = (new Privatebin())
->setUrl("https://local.privatebin/")
->setSslVerify(false)
->setText("Hello!")
->encodeAndPost();The ssl_verify key is also accepted in the constructor options array and in PrivatebinPHP::init().
PrivatebinPHPPipe provides functional-style helper closures.
On PHP versions supporting the pipe operator:
use Cyvax\Clients\PrivatebinPipe;
$result = PrivatebinPipe::init("https://privatebin.net/")
|> PrivatebinPipe::text("Hello!")
|> PrivatebinPipe::expire("1hour")
|> PrivatebinPipe::encodeAndPost();Without pipe support, it is recommended to use PrivatebinPHP or PrivatebinSnakeCase directly.
If needed, closures can still be invoked manually:
use Cyvax\Clients\PrivatebinPipe;
$client = PrivatebinPipe::init("https://privatebin.net/");
$client = PrivatebinPipe::text("Hello!")($client);
$client = PrivatebinPipe::expire("1hour")($client);
$result = PrivatebinPipe::encodeAndPost()($client);use Cyvax\Clients\Privatebin;
$client = new Privatebin();
// Fetch and decrypt in one call
$data = $client->fetchAndDecrypt($pasteId, $b58);
echo $data['paste'];
// $data['attachment'] and $data['attachment_name'] are set if the paste had an attachment| Interface | Namespace | Used by |
|---|---|---|
PrivatebinClientInterface |
Cyvax\Contracts |
PrivatebinPHP (camelCase) |
PrivatebinSnakeCaseClientInterface |
Cyvax\Contracts |
PrivatebinSnakeCase |
Type-hint against an interface when you want to swap implementations:
use Cyvax\Contracts\PrivatebinClientInterface;
function postPaste(PrivatebinClientInterface $client): array {
return $client->setText("Hello!")->encodeAndPost();
}- AES-256-GCM encryption
- PBKDF2 SHA-256 key derivation
- Zlib compression support
- Attachments support
- Password-protected pastes
- Burn-after-reading support
- Discussions support
- Multiple formatter support
- SSL verification control
- Fluent API
- Functional pipe helpers
- PHP 7.1+ compatible
See the Wiki for full documentation.
This project is licensed under the MIT license.
See LICENSE.