cyvax/privatebin_php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cyvax/privatebin_php

Composer 安装命令:

composer require cyvax/privatebin_php

包简介

PHP client library for PrivateBin with client-side encryption and decryption support.

README 文档

README

GitHub License version packagist Packagist PHP Version Support Codacy grade

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

Installation

composer require cyvax/privatebin_php

Default Instance

By default, the library is configured to use:

https://paste.i2pd.xyz/

You can override it with setUrl() or via constructor options.

Usage

Modern camelCase API

use Cyvax\Clients\Privatebin;

$result = (new Privatebin())
    ->setUrl("https://privatebin.net/")
    ->setText("Because ignorance is bliss!")
    ->setExpire("1hour")
    ->encodeAndPost();

Factory method

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

Original snake_case API

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.

Constructor Options

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

Attachments

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

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().

Pipe-style API

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

Fetching and Decrypting

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

Interfaces

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

Features

  • 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

Documentation

See the Wiki for full documentation.

License

This project is licensed under the MIT license.

See LICENSE.

cyvax/privatebin_php 适用场景与选型建议

cyvax/privatebin_php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.86k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「encryption」 「paste」 「privatebin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 cyvax/privatebin_php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cyvax/privatebin_php 我们能提供哪些服务?
定制开发 / 二次开发

基于 cyvax/privatebin_php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-07