├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── config └── notify.php └── src ├── Drivers ├── Base.php ├── FleepHook.php ├── Flowdock.php ├── FromConfig.php ├── Mail.php ├── Mailgun.php ├── Plivo.php ├── Pushover.php ├── Sentry.php ├── Slack.php └── Twilio.php ├── Facades ├── FleepHook.php ├── Flowdock.php ├── Mail.php ├── Mailgun.php ├── Notify.php ├── Plivo.php ├── Pushover.php ├── Sentry.php ├── Slack.php └── Twilio.php ├── Factories └── MonologHandlerFactory.php └── Providers └── NotifyServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-notify` will be documented in this file. 4 | 5 | ### Unreleased 6 | - Updated for Laravel 7 and 8 7 | - Add support for PHP 7.3, 7.4, 8.0 8 | - Removed support for Laravel 5.5, 5.6, 5.7, 5.8 9 | - Removed support for PHP 7.0, 7.1 10 | - Removed deprecated RavenHandler handler, use sentry/sentry 3.x and their Sentry\Monolog\Handler instead 11 | - Removed deprecated HipChat handler, migrate to Slack and use SlackWebhookHandler or SlackHandler instead 12 | 13 | ### 3.0.0 14 | - Updated for Laravel 6 15 | 16 | ### 2.1.0 17 | - Auto Package Discovery 18 | - Removed support for 5.4, 5.3, 5.2, 5.1 19 | 20 | ### 2.0.0 21 | - Fixed outdated dependencies for laravel 5.5 22 | - Removed support for PHP 5.5.9 23 | 24 | ### 1.8.5 25 | - Correctly sets text/html on SMTP emails 26 | 27 | ### 1.8.4 28 | - Added LineFormatter with newlines enabled to the Fleephook, Hipchat, Pushover, Raven, and Slack handlers 29 | 30 | ### 1.8.3 31 | - Quick fix! Correctly sets text/html on native emails (non-SMTP) 32 | 33 | ### 1.8.2 34 | - Emails now use the content type text/html 35 | 36 | ### 1.8.1 37 | - Added LineFormatter with newlines enabled to the mail and mailgun handlers 38 | 39 | ### 1.8.0 40 | - Added Mailgun support 41 | 42 | ### 1.7.0 43 | - Added psr/log interfaces 44 | 45 | ### 1.6.0 46 | - Added support for Raven (A driver for Sentry) 47 | 48 | ### 1.5.0 49 | - Can now set the SMS character limit from the config 50 | 51 | ### 1.4.3 52 | - Fixed config 53 | 54 | ### 1.4.2 55 | - Config will now default to an empty array if config is null 56 | 57 | ### 1.4.1 58 | - Removed array_merge_recursive which was not correctly merging config values that were provided in the constructor 59 | 60 | ### 1.4.0 61 | - Added Flowdock and FleepHook support 62 | 63 | ### 1.3.1 64 | - Fixed Plivo acting as Twilio 65 | 66 | ### 1.3.0 67 | - Added Plivo and Twilio support 68 | 69 | ### 1.2.0 70 | - Added email support 71 | 72 | ### 1.1.1 73 | - Can now set the title from the constructor 74 | 75 | ### 1.1.0 76 | - Added ability to change the title/subject 77 | 78 | ### 1.0.1 79 | - Fixed array to string conversion error 80 | 81 | ### 1.0.0 82 | - Initial release and connected with packagist 83 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 tylercd100 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel 5 Notify 2 | [![Latest Version](https://img.shields.io/github/release/tylercd100/laravel-notify.svg?style=flat-square)](https://github.com/tylercd100/laravel-notify/releases) 3 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 4 | [![Build Status](https://travis-ci.org/tylercd100/laravel-notify.svg?branch=master)](https://travis-ci.org/tylercd100/laravel-notify) 5 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tylercd100/laravel-notify/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-notify/?branch=master) 6 | [![Code Coverage](https://scrutinizer-ci.com/g/tylercd100/laravel-notify/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-notify/?branch=master) 7 | [![Dependency Status](https://www.versioneye.com/user/projects/56f3252c35630e0029db0187/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56f3252c35630e0029db0187) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/tylercd100/laravel-notify.svg?style=flat-square)](https://packagist.org/packages/tylercd100/laravel-notify) 9 | 10 | Laravel Notify is a Laravel 5 package that will let you send notification messages to various services. 11 | 12 | Currently supported notification channels via [Monolog](https://github.com/Seldaek/monolog) 13 | - Email 14 | - [Pushover](https://pushover.net/) 15 | - [Slack](https://slack.com/) 16 | - [Fleephook](https://fleep.io/) 17 | - [Flowdock](https://www.flowdock.com/) 18 | - [Plivo](https://www.plivo.com/) an SMS messaging service. 19 | - [Twilio](https://www.twilio.com/) an SMS messaging service. 20 | - [Sentry](https://getsentry.com) via [Sentry SDK for PHP](https://github.com/getsentry/sentry-php) 21 | - [Mailgun](https://mailgun.com) 22 | 23 | ## Version Compatibility 24 | 25 | Laravel | Laravel Notify 26 | :---------|:---------------- 27 | 5.1.x | 1.x 28 | 5.2.x | 1.x 29 | 5.3.x | 1.x 30 | 5.4.x | 1.x 31 | 5.5.x | 2.x 32 | 6.x | 3.x and 4.x 33 | 7.x | 4.x 34 | 8.x | 4.x 35 | 36 | ## Installation 37 | 38 | Version 2.x uses [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). If you are using 1.x you will need to follow these [instructions.](https://github.com/tylercd100/laravel-notify/tree/1.8.5) 39 | 40 | Install via [composer](https://getcomposer.org/) - In the terminal: 41 | ```bash 42 | composer require tylercd100/laravel-notify 43 | ``` 44 | 45 | Then you will need to run this in order to copy the config file. 46 | ```bash 47 | php artisan vendor:publish --provider="Tylercd100\Notify\Providers\NotifyServiceProvider" 48 | ``` 49 | 50 | ## Usage 51 | 52 | After you have changed your configuration file (`config/notify.php`) you can simply use it like so: 53 | ```php 54 | Notify::debug("This is a debug message!"); 55 | Notify::info("This is a info message!"); 56 | Notify::notice("This is a notice message!"); 57 | Notify::warning("This is a warning message!"); 58 | Notify::error("This is a error message!"); 59 | Notify::critical("This is a critical message!"); 60 | Notify::alert("This is a alert message!"); 61 | Notify::emergency("This is a emergency message!"); 62 | 63 | # Add context 64 | Notify::info("This is a info message with context!",['user'=>$user, 'data'=>$data]); 65 | ``` 66 | 67 | ## Other Features 68 | Laravel Notify also exposes extra Facades. To use them you will need to add them to your `config/app.php` file in your aliases array. 69 | ```php 70 | "Pushover" => Tylercd100\Notify\Facades\Pushover::class, 71 | "Flowdock" => Tylercd100\Notify\Facades\Flowdock::class, 72 | "FleepHook" => Tylercd100\Notify\Facades\FleepHook::class, 73 | "Slack" => Tylercd100\Notify\Facades\Slack::class, 74 | "Plivo" => Tylercd100\Notify\Facades\Plivo::class, 75 | "Twilio" => Tylercd100\Notify\Facades\Twilio::class, 76 | "Sentry" => Tylercd100\Notify\Facades\Sentry::class, 77 | "Mailgun" => Tylercd100\Notify\Facades\Mailgun::class, 78 | ``` 79 | And then use them like this 80 | ```php 81 | Slack::info("This is information!"); 82 | Pushover::critical("Everything is broken and the server room caught fire!"); 83 | ``` 84 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tylercd100/laravel-notify", 3 | "description": "", 4 | "keywords": [ 5 | "laravel", 6 | "notifications", 7 | "monolog", 8 | "tylercd100" 9 | ], 10 | "homepage": "https://github.com/tylercd100/laravel-notify", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Tyler Arbon", 15 | "email": "tylercd100@gmail.com" 16 | } 17 | ], 18 | "autoload":{ 19 | "psr-4":{ 20 | "Tylercd100\\Notify\\":"src/" 21 | } 22 | }, 23 | "autoload-dev": { 24 | "psr-4": { 25 | "Tylercd100\\Notify\\Tests\\": "tests/" 26 | } 27 | }, 28 | "minimum-stability": "dev", 29 | "prefer-stable": true, 30 | "require": { 31 | "illuminate/support": "^6.0|^7.0|^8.0", 32 | "monolog/monolog": "^2.0", 33 | "php": "^7.2|^8.0", 34 | "psr/log": "^1.0", 35 | "tylercd100/monolog-mailgun": "^3.0", 36 | "tylercd100/monolog-sms":"^2.0" 37 | }, 38 | "require-dev": { 39 | "sentry/sentry": "dev-php8-support", 40 | "symfony/options-resolver": "^5.1", 41 | "http-interop/http-factory-guzzle": "^1.0.0", 42 | "php-http/guzzle7-adapter": "^0.2.0", 43 | "phpunit/phpunit": "^8.4|^9.3.3", 44 | "mockery/mockery": "~1.3.3|^1.4.2", 45 | "orchestra/testbench": "^4.0|^5.0|^6.0" 46 | }, 47 | "suggest": { 48 | "sentry/sentry": "Required to use the Sentry driver (~3.0)." 49 | }, 50 | "extra": { 51 | "providers": [ 52 | "Tylercd100\\Notify\\Providers\\NotifyServiceProvider" 53 | ], 54 | "aliases": { 55 | "Notify": "Tylercd100\\Notify\\Facades\\Notify" 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /config/notify.php: -------------------------------------------------------------------------------- 1 | 'Tylercd100\Notify', 6 | 7 | /** 8 | * Drivers to use for your notifications 9 | */ 10 | 'drivers' => ['mail'], 11 | 12 | /** 13 | * Mail settings 14 | */ 15 | 'mail'=>[ 16 | 'to' =>'to@address.com', 17 | 'from'=>'from@address.com', 18 | 'smtp'=>true, 19 | ], 20 | 21 | /** 22 | * Mailgun settings 23 | */ 24 | 'mailgun'=>[ 25 | 'to' => env('MAILGUN_TO'), 26 | 'from' => env('MAILGUN_FROM'), 27 | 'token' => env('MAILGUN_APP_TOKEN'), 28 | 'domain'=> env('MAILGUN_DOMAIN'), 29 | ], 30 | 31 | /** 32 | * Pushover settings 33 | */ 34 | 'pushover'=>[ 35 | 'token' => env('PUSHOVER_APP_TOKEN'), 36 | 'users' => [env('PUSHOVER_USER_KEY')], 37 | ], 38 | 39 | /** 40 | * Slack settings 41 | */ 42 | 'slack'=>[ 43 | 'token' => env('SLACK_APP_TOKEN'), //https://api.slack.com/web#auth 44 | 'channel' => env('SLACK_CHANNEL', '#exceptions'), //Dont forget the '#' 45 | 'username'=> env('SLACK_USERNAME', 'LERN'), //The 'from' name 46 | ], 47 | 48 | /** 49 | * Flowdock settings 50 | */ 51 | 'flowdock'=>[ 52 | 'token' => env('FLOWDOCK_APP_TOKEN'), 53 | ], 54 | 55 | /** 56 | * Sentry settings 57 | */ 58 | 'sentry'=>[ 59 | 'dsn' => env('SENTRY_DSN'), 60 | 'level' => 'info', 61 | ], 62 | 63 | /** 64 | * Fleephook settings 65 | */ 66 | 'fleephook'=>[ 67 | 'token' => env('FLEEPHOOK_APP_TOKEN'), 68 | ], 69 | 70 | /** 71 | * Plivo settings 72 | */ 73 | 'plivo'=>[ 74 | 'auth_id' => env('PLIVO_AUTH_ID'), 75 | 'token' => env('PLIVO_AUTH_TOKEN'), 76 | 'to' => env('PLIVO_TO'), 77 | 'from' => env('PLIVO_FROM'), 78 | 'limit' => 160, 79 | ], 80 | 81 | /** 82 | * Twilio settings 83 | */ 84 | 'twilio'=>[ 85 | 'sid' => env('TWILIO_AUTH_SID'), 86 | 'secret' => env('TWILIO_AUTH_SECRET'), 87 | 'to' => env('TWILIO_TO'), 88 | 'from' => env('TWILIO_FROM'), 89 | 'limit' => 160, 90 | ] 91 | ]; 92 | -------------------------------------------------------------------------------- /src/Drivers/Base.php: -------------------------------------------------------------------------------- 1 | config = array_merge($default,$config); 36 | 37 | if(!$logger instanceof Logger){ 38 | $logger = new Logger($this->config['channel']); 39 | } 40 | $this->logger = $logger; 41 | $this->title = $title; 42 | 43 | $this->attachDrivers(); 44 | } 45 | 46 | /** 47 | * Returns a list of driver names to load 48 | * @return array An array of drivers to use 49 | */ 50 | abstract protected function getDrivers(); 51 | 52 | /** 53 | * Gets a handler instance for the provided name 54 | * @param string $name The name of the driver you want to use 55 | * @return HandlerInterface 56 | */ 57 | protected function getHandlerInstanceByName($name){ 58 | $config = (isset($this->config[$name]) ? $this->config[$name] : []); 59 | return Factory::create($name,$config,$this->title); 60 | } 61 | 62 | /** 63 | * Pushes a Monolog Handler in to the Monolog Logger instance 64 | * @param HandlerInterface $handler The Handler to attach 65 | * @return void 66 | */ 67 | protected function attachHandler(HandlerInterface $handler){ 68 | $this->logger->pushHandler($handler); 69 | } 70 | 71 | /** 72 | * This will attach all the monolog handlers specified in the drivers config array 73 | * @return void 74 | */ 75 | protected function attachDrivers() 76 | { 77 | $drivers = $this->getDrivers(); 78 | foreach ($drivers as $driver) { 79 | $handler = $this->getHandlerInstanceByName($driver); 80 | $this->attachHandler($handler); 81 | } 82 | } 83 | 84 | /** 85 | * System is unusable. 86 | * 87 | * @param string $message 88 | * @param array $context 89 | * @return null 90 | */ 91 | public function emergency($message, array $context = array()) 92 | { 93 | $this->logger->emergency($message,$context); 94 | } 95 | 96 | /** 97 | * Action must be taken immediately. 98 | * 99 | * Example: Entire website down, database unavailable, etc. This should 100 | * trigger the SMS alerts and wake you up. 101 | * 102 | * @param string $message 103 | * @param array $context 104 | * @return null 105 | */ 106 | public function alert($message, array $context = array()) 107 | { 108 | $this->logger->alert($message,$context); 109 | } 110 | 111 | /** 112 | * Critical conditions. 113 | * 114 | * Example: Application component unavailable, unexpected exception. 115 | * 116 | * @param string $message 117 | * @param array $context 118 | * @return null 119 | */ 120 | public function critical($message, array $context = array()) 121 | { 122 | $this->logger->critical($message,$context); 123 | } 124 | 125 | /** 126 | * Runtime errors that do not require immediate action but should typically 127 | * be logged and monitored. 128 | * 129 | * @param string $message 130 | * @param array $context 131 | * @return null 132 | */ 133 | public function error($message, array $context = array()) 134 | { 135 | $this->logger->error($message,$context); 136 | } 137 | 138 | /** 139 | * Exceptional occurrences that are not errors. 140 | * 141 | * Example: Use of deprecated APIs, poor use of an API, undesirable things 142 | * that are not necessarily wrong. 143 | * 144 | * @param string $message 145 | * @param array $context 146 | * @return null 147 | */ 148 | public function warning($message, array $context = array()) 149 | { 150 | $this->logger->warning($message,$context); 151 | } 152 | 153 | /** 154 | * Normal but significant events. 155 | * 156 | * @param string $message 157 | * @param array $context 158 | * @return null 159 | */ 160 | public function notice($message, array $context = array()) 161 | { 162 | $this->logger->notice($message,$context); 163 | } 164 | 165 | /** 166 | * Interesting events. 167 | * 168 | * Example: User logs in, SQL logs. 169 | * 170 | * @param string $message 171 | * @param array $context 172 | * @return null 173 | */ 174 | public function info($message, array $context = array()) 175 | { 176 | $this->logger->info($message,$context); 177 | } 178 | 179 | /** 180 | * Detailed debug information. 181 | * 182 | * @param string $message 183 | * @param array $context 184 | * @return null 185 | */ 186 | public function debug($message, array $context = array()) 187 | { 188 | $this->logger->debug($message,$context); 189 | } 190 | 191 | /** 192 | * Logs with an arbitrary level. 193 | * 194 | * @param mixed $level 195 | * @param string $message 196 | * @param array $context 197 | * @return null 198 | */ 199 | public function log($level, $message, array $context = array()) 200 | { 201 | $this->logger->log($level, $message, $context); 202 | } 203 | 204 | } -------------------------------------------------------------------------------- /src/Drivers/FleepHook.php: -------------------------------------------------------------------------------- 1 | config['drivers']; 15 | } 16 | } -------------------------------------------------------------------------------- /src/Drivers/Mail.php: -------------------------------------------------------------------------------- 1 | setFormatter(new LineFormatter(null, null, true)); 28 | } 29 | 30 | if ($handler instanceof \Monolog\Handler\NativeMailerHandler) { 31 | $handler->setContentType('text/html'); 32 | } 33 | 34 | return $handler; 35 | } 36 | 37 | /** 38 | * Returns a PushoverHandler 39 | * @param array $config An array of config values to use 40 | * @param string $title The title/subject to use 41 | * @return \Monolog\Handler\PushoverHandler 42 | */ 43 | protected static function pushover(array $config = [], $title = null){ 44 | $defaults = [ 45 | "title" => null, 46 | "level" => Logger::DEBUG, 47 | "bubble" => true, 48 | "useSSL" => true, 49 | "highPriorityLevel" => Logger::CRITICAL, 50 | "emergencyLevel" => Logger::EMERGENCY, 51 | "retry" => 30, 52 | "expire" => 25200 53 | ]; 54 | 55 | $c = array_merge($defaults,$config); 56 | 57 | $c['title'] = $title; 58 | 59 | return new \Monolog\Handler\PushoverHandler( 60 | $c['token'], 61 | $c['users'], 62 | $c['title'], 63 | $c['level'], 64 | $c['bubble'], 65 | $c['useSSL'], 66 | $c['highPriorityLevel'], 67 | $c['emergencyLevel'], 68 | $c['retry'], 69 | $c['expire']); 70 | } 71 | 72 | /** 73 | * Returns a PushoverHandler 74 | * @param array $config An array of config values to use 75 | * @param string $title The title/subject to use 76 | * @return \Tylercd100\Monolog\Handler\MailgunHandler 77 | */ 78 | protected static function mailgun(array $config = [], $title = null){ 79 | $defaults = [ 80 | "title" => null, 81 | "level" => Logger::CRITICAL, 82 | "bubble" => true, 83 | "host" => 'api.mailgun.net', 84 | "version" => 'v3' 85 | ]; 86 | 87 | $c = array_merge($defaults,$config); 88 | 89 | $c['title'] = $title; 90 | 91 | return new \Tylercd100\Monolog\Handler\MailgunHandler( 92 | $c["to"], 93 | $c["title"], 94 | $c["from"], 95 | $c["token"], 96 | $c["domain"], 97 | $c["level"], 98 | $c["bubble"], 99 | $c["host"], 100 | $c["version"]); 101 | } 102 | 103 | /** 104 | * Returns a FlowdockHandler 105 | * @param array $config An array of config values to use 106 | * @param string $title The title/subject to use 107 | * @return \Monolog\Handler\FlowdockHandler 108 | */ 109 | protected static function flowdock(array $config = [], $title = null){ 110 | $defaults = [ 111 | "level" => Logger::DEBUG, 112 | "bubble" => true, 113 | ]; 114 | 115 | $c = array_merge($defaults,$config); 116 | 117 | return new \Monolog\Handler\FlowdockHandler( 118 | $c['token'], 119 | $c['level'], 120 | $c['bubble']); 121 | } 122 | 123 | /** 124 | * Returns a FleepHookHandler 125 | * @param array $config An array of config values to use 126 | * @param string $title The title/subject to use 127 | * @return \Monolog\Handler\FleepHookHandler 128 | */ 129 | protected static function fleephook(array $config = [], $title = null){ 130 | $defaults = [ 131 | "level" => Logger::DEBUG, 132 | "bubble" => true, 133 | ]; 134 | 135 | $c = array_merge($defaults,$config); 136 | 137 | return new \Monolog\Handler\FleepHookHandler( 138 | $c['token'], 139 | $c['level'], 140 | $c['bubble']); 141 | } 142 | 143 | /** 144 | * Returns a PlivoHandler 145 | * @param array $config An array of config values to use 146 | * @param string $title The title/subject to use 147 | * @return \Tylercd100\Monolog\Handler\PlivoHandler 148 | */ 149 | protected static function plivo(array $config = [], $title = null){ 150 | $defaults = [ 151 | 'level' => Logger::DEBUG, 152 | 'bubble' => true, 153 | 'useSSL' => true, 154 | 'host' => 'api.plivo.com', 155 | 'version' => 'v1', 156 | 'limit' => 160, 157 | ]; 158 | 159 | $c = array_merge($defaults,$config); 160 | 161 | return new \Tylercd100\Monolog\Handler\PlivoHandler( 162 | $c['token'], 163 | $c['auth_id'], 164 | $c['from'], 165 | $c['to'], 166 | $c['level'], 167 | $c['bubble'], 168 | $c['useSSL'], 169 | $c['host'], 170 | $c['version'], 171 | $c['limit']); 172 | } 173 | 174 | /** 175 | * Returns a TwilioHandler 176 | * @param array $config An array of config values to use 177 | * @param string $title The title/subject to use 178 | * @return \Tylercd100\Monolog\Handler\TwilioHandler 179 | */ 180 | protected static function twilio(array $config = [], $title = null){ 181 | $defaults = [ 182 | 'level' => Logger::DEBUG, 183 | 'bubble' => true, 184 | 'useSSL' => true, 185 | 'host' => 'api.twilio.com', 186 | 'version' => '2010-04-01', 187 | 'limit' => 160, 188 | ]; 189 | 190 | $c = array_merge($defaults,$config); 191 | 192 | return new \Tylercd100\Monolog\Handler\TwilioHandler( 193 | $c['secret'], 194 | $c['sid'], 195 | $c['from'], 196 | $c['to'], 197 | $c['level'], 198 | $c['bubble'], 199 | $c['useSSL'], 200 | $c['host'], 201 | $c['version'], 202 | $c['limit']); 203 | } 204 | 205 | /** 206 | * Returns a SentryHandler 207 | * @param array $config An array of config values to use 208 | * @param string $title The title/subject to use 209 | * @return \Sentry\Monolog\Handler 210 | */ 211 | protected static function sentry(array $config = [], $title = null) 212 | { 213 | $defaults = [ 214 | 'dsn' => null, 215 | 'level' => Logger::ERROR, 216 | 'bubble' => true, 217 | ]; 218 | 219 | $c = array_merge($defaults, $config); 220 | $client = \Sentry\ClientBuilder::create(Arr::only($c, 'dsn'))->getClient(); 221 | 222 | return new \Sentry\Monolog\Handler( 223 | new \Sentry\State\Hub($client), 224 | $c['level'], 225 | $c['bubble'] 226 | ); 227 | } 228 | 229 | /** 230 | * Returns a SlackHandler 231 | * @param array $config An array of config values to use 232 | * @param string $title The title/subject to use 233 | * @return \Monolog\Handler\SlackHandler 234 | */ 235 | protected static function slack(array $config = [], $title = null){ 236 | $defaults = [ 237 | 'username' => 'Monolog', 238 | 'useAttachment' => true, 239 | 'iconEmoji' => null, 240 | 'level' => Logger::DEBUG, 241 | 'bubble' => true, 242 | 'useShortAttachment' => false, 243 | 'includeContextAndExtra' => false 244 | ]; 245 | 246 | $c = array_merge($defaults,$config); 247 | 248 | return new \Monolog\Handler\SlackHandler( 249 | $c['token'], 250 | $c['channel'], 251 | $c['username'], 252 | $c['useAttachment'], 253 | $c['iconEmoji'], 254 | $c['level'], 255 | $c['bubble'], 256 | $c['useShortAttachment'], 257 | $c['includeContextAndExtra']); 258 | } 259 | 260 | /** 261 | * Creates Mail Monolog Handler 262 | * @param array $config An array of config values to use 263 | * @param string $title The title/subject to use 264 | * @return \Monolog\Handler\MailHandler 265 | */ 266 | protected static function mail(array $config = [], $title = null) 267 | { 268 | if (isset($config['smtp']) && $config['smtp']) { 269 | return self::swiftMail($config,$title); 270 | } else { 271 | return self::nativeMail($config,$title); 272 | } 273 | } 274 | 275 | /** 276 | * Creates Mail Monolog Handler 277 | * @param array $config An array of config values to use 278 | * @param string $title The title/subject to use 279 | * @return \Monolog\Handler\SwiftMailerHandler 280 | */ 281 | protected static function swiftMail(array $config, $title = null) 282 | { 283 | $defaults = [ 284 | 'level' => Logger::DEBUG, 285 | 'bubble' => true 286 | ]; 287 | 288 | $c = array_merge($defaults,$config); 289 | 290 | $c['title'] = $title; 291 | 292 | $swift = new Swift_Message($c['title']); 293 | $swift->setFrom($c['from']) 294 | ->setTo($c['to']) 295 | ->setContentType('text/html'); 296 | 297 | return new \Monolog\Handler\SwiftMailerHandler( 298 | Mail::getSwiftMailer(), 299 | $swift, 300 | $c['level'], 301 | $c['bubble'] 302 | ); 303 | } 304 | 305 | /** 306 | * Creates Mail Monolog Handler 307 | * @param array $config An array of config values to use 308 | * @param string $title The title/subject to use 309 | * @return \Monolog\Handler\NativeMailerHandler 310 | */ 311 | protected static function nativeMail(array $config, $title = null) 312 | { 313 | $defaults = [ 314 | 'level' => Logger::DEBUG, 315 | 'bubble' => true, 316 | 'maxColumnWidth' => 70 317 | ]; 318 | 319 | $c = array_merge($defaults,$config); 320 | 321 | $c['title'] = $title; 322 | 323 | return new \Monolog\Handler\NativeMailerHandler( 324 | $c['to'], 325 | $c['title'], 326 | $c['from'], 327 | $c['level'], 328 | $c['bubble'], 329 | $c['maxColumnWidth'] 330 | ); 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /src/Providers/NotifyServiceProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom(__DIR__ . '/../../config/notify.php', 'notify'); 21 | 22 | $registerMap = [ 23 | 'notify' => FromConfig::class, 24 | 'notify-fleephook' => FleepHook::class, 25 | 'notify-flowdock' => Flowdock::class, 26 | 'notify-mail' => Mail::class, 27 | 'notify-mailgun' => Mailgun::class, 28 | 'notify-plivo' => Plivo::class, 29 | 'notify-pushover' => Pushover::class, 30 | 'notify-sentry' => Sentry::class, 31 | 'notify-slack' => Slack::class, 32 | 'notify-twilio' => Twilio::class, 33 | ]; 34 | 35 | $this->registerSingletonsFromMap($registerMap); 36 | } 37 | 38 | public function boot() 39 | { 40 | $this->publishes([ 41 | __DIR__ . '/../../config/notify.php' => base_path('config/notify.php'), 42 | ]); 43 | } 44 | 45 | private function registerSingletonsFromMap($map){ 46 | foreach ($map as $key => $class) { 47 | $this->app->singleton($key, function() use ($class){ 48 | return new $class; 49 | }); 50 | } 51 | } 52 | } 53 | --------------------------------------------------------------------------------