Пример #1
0
 /**
  * Writes the record down to the log of the implementing handler.
  *
  * @param array $record
  *
  * @return void
  */
 protected function write(array $record)
 {
     if (!$this->initialized) {
         if (!$this->initialize()) {
             return;
         }
     }
     $developer = new Developer($this->pastebin['api_key']);
     $account = new Account(new Credentials($this->pastebin['username'], $this->pastebin['password']));
     $draft = new Draft();
     $draft->setContent(json_encode($record, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
     $draft->setOwner($account);
     $draft->setVisibility(Visibility::VISIBILITY_UNLISTED);
     $draft->setFormat(Format::fromExtension('js'));
     $draft->setExpiry('24H');
     $draft->setTitle($record['datetime']->format('U'));
     $paste = $draft->paste($developer);
     $message = substr($record['formatted'], 0, 256);
     $this->channel->sendMessage("Error: \n\n```\n{$message}\n```\n\nPastebin: <{$paste->getUrl()}>");
 }
Пример #2
0
 /**
  * Copy properties from a draft paste.
  * @param \Brush\Pastes\Draft $draft The draft to copy from.
  */
 private function import(Draft $draft)
 {
     $this->setTitle($draft->getTitle());
     $this->setContent($draft->getContent());
     $this->setSize(strlen($draft->getContent()));
     $this->setFormat($draft->getFormat());
     $this->setVisibility($draft->getVisibility());
     if ($draft->hasOwner()) {
         $this->setOwner($draft->getOwner());
     }
 }
Пример #3
0
<?php

require dirname(__FILE__) . '/../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('<username>', '<password>'));
// 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('<developer key>');
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(), PHP_EOL;
} catch (BrushException $e) {
    echo $e->getMessage(), PHP_EOL;
}
Пример #4
0
<?php

require '../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('<developer key>');
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. http://pastebin.com/JYvbS0fC
} catch (BrushException $e) {
    // some sort of error occurred; check the message for the cause
    echo $e->getMessage();
}
Пример #5
0
 /**
  * Apply the default settings contained in this object to a draft paste.
  * @param \Brush\Pastes\Draft $draft The draft to modify.
  */
 public function applyTo(Draft $draft)
 {
     $draft->setFormat($this->getFormat());
     $draft->setVisibility($this->getVisibility());
     $draft->setExpiry($this->getExpiry());
 }
Пример #6
0
 /**
  * Create a draft paste from a file.
  * @param string $path The path of the file to create a draft from.
  * @throws \Brush\Exceptions\IOException If the file cannot be read.
  * @return \Brush\Pastes\Draft The created draft paste.
  */
 public static function fromFile($path)
 {
     if (!is_readable($path)) {
         throw new IOException(sprintf('Cannot read from \'%s\'. Check file permissions.', $path));
     }
     $draft = new Draft();
     $draft->setTitle(basename($path));
     $draft->setContent(file_get_contents($path));
     try {
         $draft->setFormat(Format::fromExtension(pathinfo($path, PATHINFO_EXTENSION)));
     } catch (FormatException $e) {
         // couldn't auto-detect format; ah well
     }
     return $draft;
 }