Skip to content

Commit e19fd73

Browse files
committed
Initial Commit
1 parent 6dcc351 commit e19fd73

File tree

14 files changed

+501
-54
lines changed

14 files changed

+501
-54
lines changed

.gitignore

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
1-
/bootstrap/compiled.php
2-
.env.*.php
3-
.env.php
4-
.env
5-
6-
# =========================
7-
# Operating System Files
8-
# =========================
9-
10-
# OSX
11-
# =========================
12-
1+
vendor
2+
composer.phar
3+
composer.lock
134
.DS_Store
14-
.AppleDouble
15-
.LSOverride
16-
17-
# Thumbnails
18-
._*
19-
20-
# Files that might appear in the root of a volume
21-
.DocumentRevisions-V100
22-
.fseventsd
23-
.Spotlight-V100
24-
.TemporaryItems
25-
.Trashes
26-
.VolumeIcon.icns
27-
28-
# Directories potentially created on remote AFP share
29-
.AppleDB
30-
.AppleDesktop
31-
Network Trash Folder
32-
Temporary Items
33-
.apdisk
34-
35-
# Windows
36-
# =========================
37-
38-
# Windows image file caches
39-
Thumbs.db
40-
ehthumbs.db
41-
42-
# Folder config file
43-
Desktop.ini
44-
45-
# Recycle Bin used on file shares
46-
$RECYCLE.BIN/
47-
48-
# Windows Installer files
49-
*.cab
50-
*.msi
51-
*.msm
52-
*.msp
53-
54-
# Windows shortcuts
55-
*.lnk
5+
.idea

.gitkeep

Whitespace-only changes.

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: php
2+
3+
php:
4+
- 5.5
5+
6+
before_script:
7+
- curl -s http://getcomposer.org/installer | php
8+
- php composer.phar install --dev
9+
10+
script: phpunit

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "lithiumdev/laravel-exception-mailer",
3+
"description": "Receive an email whenever laravel throws an exception",
4+
"keywords": [
5+
"laravel",
6+
"exception",
7+
"exception mailer"
8+
],
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Troy Siedsma",
13+
"company": "Lithium Hosting, llc",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.5.9",
19+
"illuminate/support": "~5.0"
20+
},
21+
"autoload": {
22+
"psr-0": {
23+
"LithiumDev\\ExceptionMailer\\": "src/"
24+
}
25+
},
26+
"minimum-stability": "dev"
27+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

readme.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
![](https://lithiumhosting.com/images/logo_new_black.png)
2+
3+
## Laravel Exception Mailer
4+
**from Lithium Hosting**
5+
We're always open to pull requests, feel free to make this your own or help us make it better.
6+
7+
### Copyright
8+
(c) Lithium Hosting, llc
9+
10+
### License
11+
This library is licensed under the MIT license; you can find a full copy of the license itself in the file /LICENSE
12+
13+
### Requirements
14+
* PHP 5.5.9 or newer
15+
* Laravel 5.2.x
16+
17+
### Description
18+
This package enables you to receive emails when Laravel throws an Exception.
19+
This enables you to react to issues in your application as they happen instead of waiting for user feedback.
20+
21+
## Installation
22+
23+
Begin by installing this package through Composer.
24+
Edit your project's `composer.json` file to require `lithiumdev/laravel-exception-mailer`.
25+
26+
"require": {
27+
"laravel/framework": "5.*",
28+
"lithiumdev/laravel-exception-mailer": "~1.0"
29+
}
30+
31+
Next, update Composer from the Terminal:
32+
33+
composer update
34+
35+
Once this operation completes, the next step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.
36+
37+
* Add `LithiumDev\ExceptionMailer\ExceptionMailerServiceProvider::class,` to your providers array in `app/config/app.php`
38+
* Run `php artisan vendor:publish --provider="LithiumDev\ExceptionMailer\ExceptionMailerServiceProvider"` to publish required resources.
39+
40+
Now change Config file: `config/laravel-exception-mailer/config.php`
41+
```php
42+
return [
43+
'subject' => 'Laravel Exception',
44+
'notify_emails' => [
45+
[
46+
'address' => '[email protected]',
47+
'name' => 'Your Name Here',
48+
],
49+
],
50+
'email_template' => "laravel-exception-mailer::email.exception",
51+
'notify_environment' => ['local'],
52+
'prevent_exception' => ['Symfony\Component\HttpKernel\Exception\NotFoundHttpException'],
53+
];
54+
```
55+
Be sure to set your email address and your name. You can add multiple arrays of users to receive notifications.
56+
57+
Manually Call
58+
59+
ExceptionMailer::notifyException($exception)
60+
61+
Manually set environment
62+
63+
ExceptionMailer::setEnvironment("local")
64+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace LithiumDev\ExceptionMailer;
4+
5+
use App;
6+
use Exception;
7+
use App\Exceptions\Handler;
8+
9+
class ExceptionHandler extends Handler
10+
{
11+
12+
/**
13+
*
14+
* @param Exception $e
15+
* @return type
16+
*/
17+
public function report(Exception $e)
18+
{
19+
parent::report($e);
20+
21+
$this->prevent_exception = config('laravel-exception-mailer.config.prevent_exception');
22+
$shouldReport = true;
23+
24+
foreach ($this->prevent_exception as $type) {
25+
if ($e instanceof $type) $shouldReport = false;
26+
}
27+
if ($shouldReport) {
28+
$bugonemail = App::make('ExceptionMailer');
29+
$bugonemail->notifyException($e);
30+
}
31+
}
32+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace LithiumDev\ExceptionMailer;
4+
5+
6+
use Illuminate\Support\Facades\Request;
7+
8+
/**
9+
* Description of ExceptionMailer
10+
*
11+
* @author Troy Siedsma <[email protected]>
12+
*/
13+
class ExceptionMailer {
14+
15+
public $env = '';
16+
public $config = array();
17+
18+
public function __construct($config = array())
19+
{
20+
$this->config = $config;
21+
}
22+
23+
public function setEnvironment($env)
24+
{
25+
$this->env = $env;
26+
}
27+
28+
public function notifyException($exception)
29+
{
30+
if (! empty($this->env))
31+
{
32+
$request = array();
33+
$request['fullUrl'] = Request::fullUrl();
34+
$request['input_get'] = $_GET;
35+
$request['input_post'] = $_POST;
36+
$request['input_old'] = Request::old();
37+
$request['session'] = \Session::all();
38+
$request['cookie'] = Request::cookie();
39+
$request['file'] = Request::file();
40+
$request['header'] = Request::header();
41+
$request['server'] = Request::server();
42+
$request['json'] = Request::json();
43+
$request['request_format'] = Request::format();
44+
$request['error'] = $exception->getTraceAsString();
45+
$request['subject_line'] = $exception->getMessage();
46+
$request['class_name'] = get_class($exception);
47+
if (! in_array($request['class_name'], $this->config['prevent_exception']))
48+
{
49+
\Mail::send("{$this->config['email_template']}", $request, function ($message) use ($request)
50+
{
51+
foreach ($this->config['notify_emails'] as $recipient)
52+
{
53+
$message->to($recipient['address'], $recipient['name']);
54+
}
55+
$message->subject("{$this->config['subject']} - URL: " . $request['fullUrl']);
56+
});
57+
}
58+
}
59+
60+
return $exception;
61+
}
62+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace LithiumDev\ExceptionMailer;
4+
5+
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class ExceptionMailerServiceProvider extends ServiceProvider {
9+
/**
10+
* Indicates if loading of the provider is deferred.
11+
*
12+
* @var bool
13+
*/
14+
protected $defer = false;
15+
16+
/**
17+
* Bootstrap the application events.
18+
*
19+
* @return void
20+
*/
21+
public function boot()
22+
{
23+
$this->publishes([
24+
__DIR__ . '/../../config/config.php' => config_path('laravel-exception-mailer/config.php'),
25+
__DIR__ . '/../../views' => base_path('resources/views/vendor/laravel-exception-mailer'),
26+
]);
27+
$this->loadViewsFrom(__DIR__ . '/../../views', 'laravel-exception-mailer');
28+
29+
$this->app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'LithiumDev\ExceptionMailer\ExceptionHandler');
30+
}
31+
32+
/**
33+
* Register the service provider.
34+
*
35+
* @return void
36+
*/
37+
public function register()
38+
{
39+
$this->mergeConfigFrom(
40+
__DIR__ . '/../../config/config.php', 'laravel-exception-mailer.config'
41+
);
42+
43+
$this->app['ExceptionMailer'] = $this->app->share(function ($app)
44+
{
45+
$config = $app['config']['laravel-exception-mailer']['config'];
46+
$eMailer = new ExceptionMailer($config);
47+
48+
if (in_array($app->environment(), $config['notify_environment']))
49+
{
50+
$eMailer->setEnvironment($app->environment());
51+
}
52+
53+
return $eMailer;
54+
});
55+
$this->app->singleton('ExceptionMailer',
56+
function ($app)
57+
{
58+
$config = $app['config']['laravel-exception-mailer']['config'];
59+
60+
$eMailer = new ExceptionMailer($config);
61+
62+
if (in_array($app->environment(), $config['notify_environment']))
63+
{
64+
$eMailer->setEnvironment($app->environment());
65+
}
66+
67+
return $eMailer;
68+
});
69+
// Shortcut so developers don't need to add an Alias in app/config/app.php
70+
$this->app->booting(function ()
71+
{
72+
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
73+
$loader->alias('ExceptionMailer', 'LithiumDev\ExceptionMailer\Facades\ExceptionMailerFacade');
74+
});
75+
}
76+
77+
/**
78+
* Get the services provided by the provider.
79+
*
80+
* @return array
81+
*/
82+
public function provides()
83+
{
84+
return array("ExceptionMailer");
85+
}
86+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace LithiumDev\ExceptionMailer\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class ExceptionMailerFacade extends Facade {
8+
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor() {
15+
return 'ExceptionMailer';
16+
}
17+
18+
}

0 commit comments

Comments
 (0)