/**
  * 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
 /**
  * Apply the values stored in a chunk of XML to this object.
  * @param \DOMElement $paste The `<paste>` element from Pastebin to parse.
  */
 protected function parse(DOMElement $paste)
 {
     $this->setTitle($paste->getElementsByTagName('paste_title')->item(0)->nodeValue);
     $this->setFormat(Format::fromXml($paste));
     $this->setVisibility($paste->getElementsByTagName('paste_private')->item(0)->nodeValue);
 }
示例#3
0
文件: Defaults.php 项目: gebn/brush
 /**
  * Import information from a <user> node.
  * @param \DOMElement $user The user element to parse.
  */
 protected function parse(DOMElement $user)
 {
     $this->setFormat(Format::fromCode($user->getElementsByTagName('user_format_short')->item(0)->nodeValue));
     $this->setVisibility($user->getElementsByTagName('user_private')->item(0)->nodeValue);
     $this->setExpiry($user->getElementsByTagName('user_expiration')->item(0)->nodeValue);
 }
示例#4
0
文件: Draft.php 项目: barricas/Brush
 /**
  * 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;
 }