Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 8/9 #58

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
composer.phar
composer.lock
composer.lock
/.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ An easy way to send emails with stack trace whenever an exception occurs on the

#### For Laravel <= 5.2, please use the [v1 branch](https://github.com/squareboat/sneaker/tree/v1)!
#### For Laravel 5.2 < version <= 6.x, please use the [v5 branch](https://github.com/squareboat/sneaker/tree/v5)!
#### For Laravel 6.x < version <= 8.x, please use the [v7 branch](https://github.com/squareboat/sneaker/tree/v7)!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit confusing because of the .x at the start.
I recommend changing it into "For Laravel 7.0 <= version <= 8.x" 😊
And while you're at it, I recommend also changing that second line into "For Laravel 5.3 <= version ..." then...

Less brain cells wasted for developers trying to figure out which branch they need 😊


```
$ composer require squareboat/sneaker
Expand Down
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*",
"illuminate/view": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*",
"illuminate/config": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*",
"illuminate/mail": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*",
"illuminate/log": "5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*",
"symfony/debug": "~3.1|~3.2|~4.0"
"php": ">=7.3",
"illuminate/support": "8.*",
"illuminate/view": "8.*",
"illuminate/config": "8.*",
"illuminate/mail": "8.*",
"illuminate/log": "8.*",
"illuminate/queue": "8.*",
"illuminate/console": "8.*",
"symfony/error-handler": "~5.1"
},
"require-dev": {
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Sneak.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle()

$this->info('Sneaker is working fine ✅');
} catch (Exception $e) {
(new ConsoleApplication)->renderException($e, $this->output);
(new ConsoleApplication)->renderThrowable($e, $this->output);
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/ExceptionHandler.php → src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace SquareBoat\Sneaker;

use Illuminate\View\Factory;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\ErrorHandler\Exception\FlattenException;

class ExceptionHandler

class ErrorHandler
{
/**
* The view factory implementation.
Expand Down Expand Up @@ -47,16 +48,17 @@ public function convertExceptionToHtml($exception)
{
$flat = $this->getFlattenedException($exception);

$handler = new SymfonyExceptionHandler();
$renderer = new HtmlErrorRenderer(true);

return $this->decorate($renderer->getBody($flat), $renderer->getStylesheet($flat), $flat);

return $this->decorate($handler->getContent($flat), $handler->getStylesheet($flat), $flat);
}

/**
* Converts the Exception in a PHP Exception to be able to serialize it.
*
* @param \Exception $exception
* @return \Symfony\Component\Debug\Exception\FlattenException
*
* @param $exception
* @return FlattenException
*/
private function getFlattenedException($exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExceptionMailer.php → src/ErrorMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ExceptionMailer extends Mailable implements ShouldQueue
class ErrorMailer extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;

Expand Down
19 changes: 10 additions & 9 deletions src/Sneaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\Log\LoggerInterface;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Config\Repository;
use Throwable;

class Sneaker
{
Expand All @@ -18,7 +19,7 @@ class Sneaker
/**
* The exception handler implementation.
*
* @var \SquareBoat\Sneaker\ExceptionHandler
* @var \SquareBoat\Sneaker\ErrorHandler
*/
private $handler;

Expand All @@ -40,13 +41,13 @@ class Sneaker
* Create a new sneaker instance.
*
* @param \Illuminate\Config\Repository $config
* @param \SquareBoat\Sneaker\ExceptionHandler $handler
* @param \SquareBoat\Sneaker\ErrorHandler $handler
* @param \Illuminate\Contracts\Mail\Mailer $mailer
* @param \Psr\Log\LoggerInterface $logger
* @return void
*/
public function __construct(Repository $config,
ExceptionHandler $handler,
ErrorHandler $handler,
Mailer $mailer,
LoggerInterface $logger)
{
Expand All @@ -62,7 +63,7 @@ public function __construct(Repository $config,
/**
* Checks an exception which should be tracked and captures it if applicable.
*
* @param \Throwable|\Exception $exception
* @param Throwable|\Exception $exception
* @return void
*/
public function captureException($exception, $sneaking = false)
Expand All @@ -79,7 +80,7 @@ public function captureException($exception, $sneaking = false)
if ($this->shouldCapture($exception)) {
$this->capture($exception);
}
} catch (Exception $e) {
} catch (Throwable $e) {
$this->logger->error(sprintf(
'Exception thrown in Sneaker when capturing an exception (%s: %s)',
get_class($e), $e->getMessage()
Expand All @@ -96,7 +97,7 @@ public function captureException($exception, $sneaking = false)
/**
* Capture an exception.
*
* @param \Exception|\Throwable $exception
* @param \Exception|Throwable $exception
* @return void
*/
private function capture($exception)
Expand All @@ -107,7 +108,7 @@ private function capture($exception)

$body = $this->handler->convertExceptionToHtml($exception);

$this->mailer->to($recipients)->send(new ExceptionMailer($subject, $body));
$this->mailer->to($recipients)->send(new ErrorMailer($subject, $body));
}

/**
Expand All @@ -117,13 +118,13 @@ private function capture($exception)
*/
private function isSilent()
{
return $this->config->get('sneaker.silent');
return $this->config->get('sneaker.silent', false);
}

/**
* Determine if the exception is in the "capture" list.
*
* @param \Throwable|\Exception $exception
* @param Throwable|\Exception $exception
* @return boolean
*/
private function shouldCapture($exception)
Expand Down