PHPackages                             gebn/brush - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gebn/brush

ActiveLibrary[API Development](/categories/api)

gebn/brush
==========

Brush is a complete object-oriented PHP wrapper for the Pastebin API.

v1.2.0(7y ago)3912713[1 issues](https://github.com/gebn/Brush/issues)1MITPHPPHP &gt;=5.3.0

Since Sep 14Pushed 4y ago8 watchersCompare

[ Source](https://github.com/gebn/Brush)[ Packagist](https://packagist.org/packages/gebn/brush)[ Docs](https://github.com/gebn/Brush)[ RSS](/packages/gebn-brush/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (1)

Brush [![License](https://camo.githubusercontent.com/f48f8d6cf609f5b181b9c3218a85175fe8a5809c7ea400347f39697a5d55065d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174)](LICENSE) [![Stars](https://camo.githubusercontent.com/a5ecd9261aca7e65d2795618be41477a227b380735f0664639604b4a33762809/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6765626e2f62727573682e7376673f7374796c653d666c6174)](https://github.com/gebn/Brush/stargazers) [![Forks](https://camo.githubusercontent.com/fa5126e36285a46b1c3c1530d5babe8439a92fc22fa24b061ed5a3c866addfa2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6765626e2f62727573682e7376673f7374796c653d666c6174)](https://github.com/gebn/Brush/network/members) [![Issues](https://camo.githubusercontent.com/a30a674892ca551b58ffbde7b2695251c466bdfc67b8f6579b78f08ad5aa257c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6765626e2f62727573682e7376673f7374796c653d666c6174)](https://github.com/gebn/Brush/issues)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#brush----)

Brush is a complete object-oriented PHP wrapper for the Pastebin API.

Features
--------

[](#features)

- Create pastes directly from files, with automatic language detection.
- Easily apply default account settings to new pastes.
- High performance with aggressive caching.
- End-to-end UTF-8 support.

Dependencies
------------

[](#dependencies)

- PHP 5.3.0+
- cURL

Install
-------

[](#install)

Composer is not required, however Brush is on Packagist and may be added to a project with:

```
composer require gebn/brush "1.*"

```

Getting Started
---------------

[](#getting-started)

### Create an anonymous paste

[](#create-an-anonymous-paste)

Below is a minimal example showing how to submit a new paste:

```
require 'Brush/Brush.php';

use \Brush\Pastes\Draft;
use \Brush\Accounts\Developer;
use \Brush\Exceptions\BrushException;

$draft = new Draft(); // drafts represent unsent pastes
$draft->setContent('Some random content'); // set the paste content

// the Developer class encapsulates a developer API key; an instance
// needs to be provided whenever Brush might interact with Pastebin
$developer = new Developer('');

try {
	// send the draft to Pastebin; turn it into a full blown Paste object
	$paste = $draft->paste($developer);

	// print out the URL of the new paste
	echo $paste->getUrl(); // e.g. https://pastebin.com/JYvbS0fC
}
catch (BrushException $e) {
	// some sort of error occurred; check the message for the cause
	echo $e->getMessage();
}
```

There are several things to note:

- You only ever need to require `Brush.php`; Brush has an autoloader, which will take care of other includes for you.
- The `Draft` class represents a paste not yet submitted to Pastebin. It has setters allowing you to configure every possible option for your new paste, including expiry, format and visibility.
- The `Developer` class represents a developer account. An instance needs to be passed in all situations where Brush could interact with the Pastebin API.
- When `paste()` is called on a draft, Brush checks for basic errors before attempting to send the draft to Pastebin. If an error is detected (e.g. no content set), a `ValidationException` will be thrown.
- All exceptions thrown by Brush extend `BrushException`. This allows you to easily handle every single possible error in a single `catch` clause, or use multiple clauses for more fine-grained handling.
- Once a draft is `paste()`d, Brush automatically creates and return a `Paste` object without any further interaction with the Pastebin API. This object contains all information about the paste, including its key, URL and expiry date.
- A `Draft`'s `paste()` method can be safely called multiple times, changing the draft between invocations if required.
- For a complete method reference, see [METHODS.md](METHODS.md).

### Create a private paste

[](#create-a-private-paste)

Private pastes must have an account associated with them, but Brush makes this easy to set up:

```
require 'Brush/Brush.php';

use \Brush\Accounts\Developer;
use \Brush\Accounts\Account;
use \Brush\Accounts\Credentials;
use \Brush\Pastes\Draft;
use \Brush\Pastes\Options\Visibility;
use \Brush\Exceptions\BrushException;

// this time, create a draft directly from a file
$draft = Draft::fromFile('passwords.txt');

// an Account object represents a Pastebin user account
$account = new Account(new Credentials('', ''));

// link the draft to the account
$draft->setOwner($account);

// specify that we don't want this paste to be publicly accessible
$draft->setVisibility(Visibility::VISIBILITY_PRIVATE);

// the Developer class manages a developer key
$developer = new Developer('');

try {
	// submit the draft and retrieve the final paste in the same way as above
	$paste = $draft->paste($developer);

	// print out the key of the newly created paste
	echo $paste->getKey();
}
catch (BrushException $e) {
	echo $e->getMessage();
}
```

The `Account` class represents a Pastebin account. At the lowest level, it manages a user session key, which has to be provided when doing operations affecting a particular account. An instance can be created in two ways:

1. Via a set of credentials, as above. Brush will make an HTTP request to Pastebin to retrieve a new user key when one is first needed, and will cache it for the rest of execution.
2. Directly by passing a session key string as the only argument to `Account`'s constructor. This saves a request, and is the recommended way if you always want to work with the same account.

In the above example, instead of manually writing a draft, we asked Brush to automatically create one from a local file. Brush will set the draft title to the name of the file, the content as the file content, and attempt to recognise the format from the file's extension. The mappings it uses to do this are in `Configuration/extensions.ini`. This is designed to be edited by you, so feel free to add lines according to your requirements. If you add a large number of maps, please consider contributing them in a pull request so that others may benefit!

You can also create a draft paste inheriting an account's default settings using the `fromOwner(Account, Developer)` method. This will retrieve the defaults for the supplied account, apply them to a new draft, and set the account as the owner.

### Retrieve an account's pastes

[](#retrieve-an-accounts-pastes)

Retrieving pastes belonging to an account is easy:

```
require 'Brush/Brush.php';

use \Brush\Accounts\Account;
use \Brush\Accounts\Developer;
use \Brush\Exceptions\BrushException;

$account = new Account('');
$developer = new Developer('');

try {
	// retrieve the first 50 (see below) account pastes
	$pastes = $account->getPastes($developer);

	// print out the name of each paste followed by a line feed
	foreach ($pastes as $paste) {
		echo $paste->getTitle(), "\n";
	}
}
catch (BrushException $e) {
	echo $e->getMessage();
}
```

`Account`'s `getPastes()` method returns an array of `Paste` objects, representing pastes submitted by that account. It takes an optional second argument, the maximum number of pastes to retrieve, which defaults to 50.

#### Delete a paste

[](#delete-a-paste)

Pastes retrieved in the above way can be removed by calling `delete()` on them:

```
require 'Brush/Brush.php';

use \Brush\Accounts\Account;
use \Brush\Accounts\Developer;
use \Brush\Exceptions\BrushException;

$account = new Account('');
$developer = new Developer('');

try {
	// retrieve up to 10 account pastes
	$pastes = $account->getPastes($developer, 10);

	// delete each one
	foreach ($pastes as $paste) {
		$paste->delete($developer);
		echo 'Deleted ', $paste->getKey(), "\n";
	}
}
catch (BrushException $e) {
	echo $e->getMessage();
}
```

N.B. For reasons of authentication, only pastes retrieved from an account can be deleted. If you attempt to delete a paste obtained via other means (e.g. a trending paste), Brush will detect this and throw a `ValidationException`, as Pastebin would simply reject the request. Brush will always try to warn you of errors before bothering Pastebin.

### Retrieve trending pastes

[](#retrieve-trending-pastes)

```
require 'Brush/Brush.php';

use \Brush\Accounts\Developer;
use \Brush\Pastes\Trending;
use \Brush\Exceptions\BrushException;

$developer = new Developer('');

try {
	// retrieve an array of the top 18 currently trending pastes
	$pastes = Trending::getPastes($developer);

	// print out the titles and hit counts of each one
	foreach ($pastes as $paste) {
		printf("%-70s%d\n", $paste->getTitle(), $paste->getHits());
	}
}
catch (BrushException $e) {
	echo $e->getMessage();
}
```

Contributing
------------

[](#contributing)

Suggestions and pull requests are welcome. Please submit these through the normal GitHub channels.

If you discover a bug, please open a [new issue](https://github.com/gebn/Brush/issues/new).

Licence
-------

[](#licence)

Brush is released under the MIT Licence - see the LICENSE file for details. For more information about how this allows you to use the library, see the [Wikipedia article](https://en.wikipedia.org/wiki/MIT_License).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~203 days

Recently: every ~274 days

Total

9

Last Release

2636d ago

Major Versions

v0.13 → v1.0.02016-02-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/b78de457acf6c6a1a5921ebb42c827b2444e902db4885e7a016af6ee2eb1512f?d=identicon)[gebn](/maintainers/gebn)

---

Top Contributors

[![gebn](https://avatars.githubusercontent.com/u/2334407?v=4)](https://github.com/gebn "gebn (114 commits)")[![tetreum](https://avatars.githubusercontent.com/u/1708730?v=4)](https://github.com/tetreum "tetreum (1 commits)")

---

Tags

apipastebinphpwrapperapiwrappertextpastebin

### Embed Badge

![Health badge](/badges/gebn-brush/health.svg)

```
[![Health](https://phpackages.com/badges/gebn-brush/health.svg)](https://phpackages.com/packages/gebn-brush)
```

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

16553.3k1](/packages/php-tmdb-laravel)[php-tmdb/symfony

Symfony Bundle for TMDB (The Movie Database) API. Provides easy access to the php-tmdb/api library.

3649.7k](/packages/php-tmdb-symfony)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)[lasserafn/laravel-economic

Economic REST wrapper for Laravel

1118.5k](/packages/lasserafn-laravel-economic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
