Created
October 29, 2016 01:18
-
-
Save raank/9f02c09214eca4b4b9ba339b7d80f88e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FlyingLuscas\BugNotifier; | |
class Message | |
{ | |
/** | |
* The title of the message. | |
* | |
* @var string | |
*/ | |
protected $title; | |
/** | |
* The body of the message. | |
* | |
* @var string | |
*/ | |
protected $body; | |
/** | |
* Create a new class instance. | |
* | |
* @param \Exception $e | |
*/ | |
public function __construct(\Exception $e) | |
{ | |
$this->setTitle($e)->setBody($e); | |
} | |
/** | |
* Set the title of the message. | |
* | |
* @param \Exception $e | |
* | |
* @return self | |
*/ | |
private function setTitle(\Exception $e) | |
{ | |
$classname = class_basename(get_class($e)); | |
$filename = basename($e->getFile()); | |
$line = $e->getLine(); | |
$this->title = sprintf('%s in %s line %d', $classname, $filename, $line); | |
return $this; | |
} | |
/** | |
* Set the body of the message. | |
* | |
* @param \Exception $e | |
* | |
* @return self | |
*/ | |
private function setBody(\Exception $e) | |
{ | |
$classname = get_class($e); | |
$filename = $e->getFile(); | |
$line = $e->getLine(); | |
$message = $e->getMessage(); | |
$trace = $e->getTraceAsString(); | |
$at = 'teste'; | |
$this->body = sprintf("[%s] %s in %s line %d\n\n%s\n\n%s", $at, $classname, $filename, $line, $message, $trace); | |
return $this; | |
} | |
/** | |
* Get the body of the message. | |
* | |
* @return string | |
*/ | |
public function getBody() | |
{ | |
return $this->body; | |
} | |
/** | |
* Get the title of the message. | |
* | |
* @return string | |
*/ | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment