-
Notifications
You must be signed in to change notification settings - Fork 3
Advanced
cyvax edited this page May 23, 2026
·
2 revisions
All clients accept custom HTTP and encryption implementations via constructor injection.
Typical use cases include:
- replacing cURL with Guzzle or Symfony HTTP Client
- adding custom logging or retry logic
- integrating alternate encryption implementations
- testing with mocked transports
Both interfaces are considered stable extension points and are safe to implement in userland code.
Implement Cyvax\Contracts\HttpClientInterface to replace the default cURL transport.
namespace Cyvax\Contracts;
interface HttpClientInterface
{
public function request(
string $url,
string $method,
array $headers,
bool $sslVerify,
string $body = ""
): string;
}request() must return the raw response body as a string and throw Cyvax\Exceptions\PrivatebinException on failure.
use Cyvax\Contracts\HttpClientInterface;
use Cyvax\Exceptions\PrivatebinException;
class MyHttpClient implements HttpClientInterface
{
public function request(string $url, string $method, array $headers, bool $sslVerify, string $body = ""): string
{
// return raw response body as string
// throw PrivatebinException on failure
}
}Inject it:
use Cyvax\Clients\Privatebin;
// Custom HTTP client
$client = new Privatebin([], new MyHttpClient());Implement Cyvax\Contracts\PasteEncryptorInterface to replace the default AES-256-GCM encryption.
namespace Cyvax\Contracts;
interface PasteEncryptorInterface
{
public function encrypt(
array $pasteData,
string $compression,
string $formatter,
bool $discussion,
bool $burn,
string $expire,
?string $userPassword = null,
bool $debug = false
): array; // array{data: array, b58: string}
public function decrypt(
array $fetchResult,
string $b58,
?string $userPassword = null
): array; // array{paste: string, attachment: string|null, attachment_name: string|null}
}Inject it:
use Cyvax\Clients\Privatebin;
// Custom encryptor
$client = new Privatebin([], null, new MyEncryptor());Implement Cyvax\Contracts\Base58Interface to replace the bundled Base58 encoder/decoder.
namespace Cyvax\Contracts;
interface Base58Interface
{
public function encode(string $data): string;
public function decode(string $data): string; // throws PrivatebinException on invalid input
}use Cyvax\Contracts\Base58Interface;
use Cyvax\Exceptions\PrivatebinException;
use Tuupola\Base58 as TuupolaBase58;
class TuupolaBase58Adapter implements Base58Interface
{
private $base58;
public function __construct()
{
$this->base58 = new TuupolaBase58(['characters' => TuupolaBase58::BITCOIN]);
}
public function encode(string $data): string
{
return $this->base58->encode($data);
}
public function decode(string $data): string
{
try {
return $this->base58->decode($data);
} catch (\Exception $e) {
throw new PrivatebinException('Base58 decode failed: ' . $e->getMessage(), 0, $e);
}
}
}Inject it via AesEncryptor:
use Cyvax\Clients\Privatebin;
use Cyvax\Internal\AesEncryptor;
$client = new Privatebin([], null, new AesEncryptor(new TuupolaBase58Adapter()));