-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
501 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,5 @@ | ||
/bootstrap/compiled.php | ||
.env.*.php | ||
.env.php | ||
.env | ||
|
||
# ========================= | ||
# Operating System Files | ||
# ========================= | ||
|
||
# OSX | ||
# ========================= | ||
|
||
vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# Windows | ||
# ========================= | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
.idea |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev | ||
|
||
script: phpunit |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "lithiumdev/laravel-exception-mailer", | ||
"description": "Receive an email whenever laravel throws an exception", | ||
"keywords": [ | ||
"laravel", | ||
"exception", | ||
"exception mailer" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Troy Siedsma", | ||
"company": "Lithium Hosting, llc", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.9", | ||
"illuminate/support": "~5.0" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"LithiumDev\\ExceptionMailer\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
![](https://lithiumhosting.com/images/logo_new_black.png) | ||
|
||
## Laravel Exception Mailer | ||
**from Lithium Hosting** | ||
We're always open to pull requests, feel free to make this your own or help us make it better. | ||
|
||
### Copyright | ||
(c) Lithium Hosting, llc | ||
|
||
### License | ||
This library is licensed under the MIT license; you can find a full copy of the license itself in the file /LICENSE | ||
|
||
### Requirements | ||
* PHP 5.5.9 or newer | ||
* Laravel 5.2.x | ||
|
||
### Description | ||
This package enables you to receive emails when Laravel throws an Exception. | ||
This enables you to react to issues in your application as they happen instead of waiting for user feedback. | ||
|
||
## Installation | ||
|
||
Begin by installing this package through Composer. | ||
Edit your project's `composer.json` file to require `lithiumdev/laravel-exception-mailer`. | ||
|
||
"require": { | ||
"laravel/framework": "5.*", | ||
"lithiumdev/laravel-exception-mailer": "~1.0" | ||
} | ||
|
||
Next, update Composer from the Terminal: | ||
|
||
composer update | ||
|
||
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. | ||
|
||
* Add `LithiumDev\ExceptionMailer\ExceptionMailerServiceProvider::class,` to your providers array in `app/config/app.php` | ||
* Run `php artisan vendor:publish --provider="LithiumDev\ExceptionMailer\ExceptionMailerServiceProvider"` to publish required resources. | ||
|
||
Now change Config file: `config/laravel-exception-mailer/config.php` | ||
```php | ||
return [ | ||
'subject' => 'Laravel Exception', | ||
'notify_emails' => [ | ||
[ | ||
'address' => '[email protected]', | ||
'name' => 'Your Name Here', | ||
], | ||
], | ||
'email_template' => "laravel-exception-mailer::email.exception", | ||
'notify_environment' => ['local'], | ||
'prevent_exception' => ['Symfony\Component\HttpKernel\Exception\NotFoundHttpException'], | ||
]; | ||
``` | ||
Be sure to set your email address and your name. You can add multiple arrays of users to receive notifications. | ||
|
||
Manually Call | ||
|
||
ExceptionMailer::notifyException($exception) | ||
|
||
Manually set environment | ||
|
||
ExceptionMailer::setEnvironment("local") | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace LithiumDev\ExceptionMailer; | ||
|
||
use App; | ||
use Exception; | ||
use App\Exceptions\Handler; | ||
|
||
class ExceptionHandler extends Handler | ||
{ | ||
|
||
/** | ||
* | ||
* @param Exception $e | ||
* @return type | ||
*/ | ||
public function report(Exception $e) | ||
{ | ||
parent::report($e); | ||
|
||
$this->prevent_exception = config('laravel-exception-mailer.config.prevent_exception'); | ||
$shouldReport = true; | ||
|
||
foreach ($this->prevent_exception as $type) { | ||
if ($e instanceof $type) $shouldReport = false; | ||
} | ||
if ($shouldReport) { | ||
$bugonemail = App::make('ExceptionMailer'); | ||
$bugonemail->notifyException($e); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace LithiumDev\ExceptionMailer; | ||
|
||
|
||
use Illuminate\Support\Facades\Request; | ||
|
||
/** | ||
* Description of ExceptionMailer | ||
* | ||
* @author Troy Siedsma <[email protected]> | ||
*/ | ||
class ExceptionMailer { | ||
|
||
public $env = ''; | ||
public $config = array(); | ||
|
||
public function __construct($config = array()) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
public function setEnvironment($env) | ||
{ | ||
$this->env = $env; | ||
} | ||
|
||
public function notifyException($exception) | ||
{ | ||
if (! empty($this->env)) | ||
{ | ||
$request = array(); | ||
$request['fullUrl'] = Request::fullUrl(); | ||
$request['input_get'] = $_GET; | ||
$request['input_post'] = $_POST; | ||
$request['input_old'] = Request::old(); | ||
$request['session'] = \Session::all(); | ||
$request['cookie'] = Request::cookie(); | ||
$request['file'] = Request::file(); | ||
$request['header'] = Request::header(); | ||
$request['server'] = Request::server(); | ||
$request['json'] = Request::json(); | ||
$request['request_format'] = Request::format(); | ||
$request['error'] = $exception->getTraceAsString(); | ||
$request['subject_line'] = $exception->getMessage(); | ||
$request['class_name'] = get_class($exception); | ||
if (! in_array($request['class_name'], $this->config['prevent_exception'])) | ||
{ | ||
\Mail::send("{$this->config['email_template']}", $request, function ($message) use ($request) | ||
{ | ||
foreach ($this->config['notify_emails'] as $recipient) | ||
{ | ||
$message->to($recipient['address'], $recipient['name']); | ||
} | ||
$message->subject("{$this->config['subject']} - URL: " . $request['fullUrl']); | ||
}); | ||
} | ||
} | ||
|
||
return $exception; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/LithiumDev/ExceptionMailer/ExceptionMailerServiceProvider.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace LithiumDev\ExceptionMailer; | ||
|
||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ExceptionMailerServiceProvider extends ServiceProvider { | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__ . '/../../config/config.php' => config_path('laravel-exception-mailer/config.php'), | ||
__DIR__ . '/../../views' => base_path('resources/views/vendor/laravel-exception-mailer'), | ||
]); | ||
$this->loadViewsFrom(__DIR__ . '/../../views', 'laravel-exception-mailer'); | ||
|
||
$this->app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'LithiumDev\ExceptionMailer\ExceptionHandler'); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom( | ||
__DIR__ . '/../../config/config.php', 'laravel-exception-mailer.config' | ||
); | ||
|
||
$this->app['ExceptionMailer'] = $this->app->share(function ($app) | ||
{ | ||
$config = $app['config']['laravel-exception-mailer']['config']; | ||
$eMailer = new ExceptionMailer($config); | ||
|
||
if (in_array($app->environment(), $config['notify_environment'])) | ||
{ | ||
$eMailer->setEnvironment($app->environment()); | ||
} | ||
|
||
return $eMailer; | ||
}); | ||
$this->app->singleton('ExceptionMailer', | ||
function ($app) | ||
{ | ||
$config = $app['config']['laravel-exception-mailer']['config']; | ||
|
||
$eMailer = new ExceptionMailer($config); | ||
|
||
if (in_array($app->environment(), $config['notify_environment'])) | ||
{ | ||
$eMailer->setEnvironment($app->environment()); | ||
} | ||
|
||
return $eMailer; | ||
}); | ||
// Shortcut so developers don't need to add an Alias in app/config/app.php | ||
$this->app->booting(function () | ||
{ | ||
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); | ||
$loader->alias('ExceptionMailer', 'LithiumDev\ExceptionMailer\Facades\ExceptionMailerFacade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array("ExceptionMailer"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/LithiumDev/ExceptionMailer/Facades/ExceptionMailerFacade.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace LithiumDev\ExceptionMailer\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class ExceptionMailerFacade extends Facade { | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { | ||
return 'ExceptionMailer'; | ||
} | ||
|
||
} |
Empty file.
Oops, something went wrong.