Exemple #1
0
 /**
  * @param $index
  * @return mixed|void
  */
 protected function lazyLoadHeader($index)
 {
     $current = $this->headers[$index];
     $current = Header::fromString($current['line']);
     $this->headers[$index] = $current;
     return $current;
 }
Exemple #2
0
 /**
  * Creates a new Syslog block from an input string.
  *
  * @param string $input
  *
  * @return \static
  */
 public static function fromString($input)
 {
     $result = new static();
     $exploded = explode(" ", $input);
     preg_match_all('/\\[(.*?)\\]/', $input, $elements);
     preg_match_all('/\\] (.*?)$/', $input, $message);
     $header = array_slice($exploded, 0, 7);
     if (!empty($header)) {
         $result->header = Header::fromString($header);
     }
     if (!empty($elements[1])) {
         $result->structuredData = Element::fromString($elements);
     } else {
         if ($exploded[7] == '-') {
             $body = $header = array_slice($exploded, 8);
             $message[1][0] = '';
             foreach ($body as $elem) {
                 $message[1][0] .= $elem . " ";
             }
             $message[1][0] = trim($message[1][0], " ");
         }
     }
     if (!empty($message[1])) {
         $result->message = Message::fromString($message[1][0]);
     }
     return $result;
 }