From 9edf583dbd7ef446a661102605ee069bb200f4e9 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 16 Feb 2018 13:10:34 +0100 Subject: [PATCH] Adds support to Laravel 5.6 --- composer.json | 11 +-- readme.md | 86 ++++++------------- src/Contracts/Notification.php | 6 +- src/LaravelDesktopNotifierServiceProvider.php | 40 +++++++-- src/Notifications.php | 39 --------- src/Notifier.php | 6 +- 6 files changed, 69 insertions(+), 119 deletions(-) delete mode 100644 src/Notifications.php diff --git a/composer.json b/composer.json index 7c66e3a..5a21d0e 100644 --- a/composer.json +++ b/composer.json @@ -4,13 +4,14 @@ "keywords": ["laravel", "framework", "console", "artisan", "php", "wrapper", "JoliNotif", "notification", "notifier", "Nuno Maduro", "NunoMaduro"], "license": "MIT", "require": { - "php": ">=5.5.9", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*", - "jolicode/jolinotif": "^1.1" + "php": "^7.1.3", + "illuminate/support": "5.6.*", + "illuminate/console": "5.6.*", + "jolicode/jolinotif": "2.0.*" }, "require-dev": { - "graham-campbell/testbench": "^3.1", - "phpunit/phpunit": "^4.8|^5.0" + "graham-campbell/testbench": "dev-master", + "phpunit/phpunit": "^7.0" }, "authors": [ { diff --git a/readme.md b/readme.md index d542b5c..c1c437a 100644 --- a/readme.md +++ b/readme.md @@ -1,48 +1,35 @@ -

- -Laravel Desktop Notifier -================ - -Laravel Desktop Notifier was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a [JoliNotif](https://github.com/jolicode/JoliNotif) wrapper for [Laravel](http://laravel.com). Feel free to check out the [change log](CHANGELOG.md), [releases](nunomaduro/laravel-desktop-notifier/releases), [license](LICENSE), and [contribution guidelines](CONTRIBUTING.md). +

+ +

- StyleCI Status - Build Status - Quality Score - Latest Version - License + StyleCI Status + Build Status + Quality Score + Latest Version + License

-## Installation +## About Laravel Desktop Notifier -[PHP](https://php.net) 5.5+ +Laravel Desktop Notifier was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a replacement for the List Command in Laravel Console Commands. -To get the latest version of Laravel Desktop Notifier, simply require the project using [Composer](https://getcomposer.org): +## Installation -```bash -$ composer require nunomaduro/laravel-desktop-notifier -``` +> **Requires [PHP 7.1+](https://php.net/releases/)** -Instead, you may of course manually update your require block and run `composer update` if you so choose: +Require Laravel Desktop Notifier using [Composer](https://getcomposer.org): -```json -{ - "require": { - "nunomaduro/laravel-desktop-notifier": "^1.0" - } -} +```bash +composer require nunomaduro/laravel-desktop-notifier ``` -## Usage with Trait +## Usage ```php -use Illuminate\Console\Command; -use NunoMaduro\LaravelDesktopNotifier\Notifications; -class Zonda extends Command +class ZondaCommand extends Command { - use Notifications; - public function handle() { $this->notify('Hello Web Artisan', 'Love beautiful code? We do too!'); @@ -50,42 +37,17 @@ class Zonda extends Command } ``` -## Usage with Laravel IOC container - -```php -use Illuminate\Console\Command; -use NunoMaduro\LaravelDesktopNotifier\Contracts\Notifier; -use NunoMaduro\LaravelDesktopNotifier\Contracts\Notification; - -class Zonda extends Command -{ - public function handle() - { - $notifier = app(Notifier::class); - - $notification = app(Notification::class) - ->setTitle('Hello Web Artisan') - ->setBody('Love beautiful code? We do too!') - ->setIcon(__DIR__ . '/path/to/your/icon.png'); - - $notifier->send($notification); - } -} -``` - -## Git branching model - -The git branching model used for development is the one described and assisted by `twgit` tool: [https://github.com/Twenga/twgit](https://github.com/Twenga/twgit). - -## Stay In Touch - -For latest releases and announcements, follow on Twitter: [@enunomaduro](https://twitter.com/enunomaduro) - ## Contributing Thank you for considering to contribute to Laravel Desktop Notifier. All the contribution guidelines are mentioned [here](CONTRIBUTING.md). -You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements: [@enunomaduro](https://twitter.com/enunomaduro) +You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro) + +## Support the development +**Do you like this project? Support it by donating** + +- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) +- Patreon: [Donate](https://www.patreon.com/nunomaduro) ## License diff --git a/src/Contracts/Notification.php b/src/Contracts/Notification.php index 38921d4..aea4419 100644 --- a/src/Contracts/Notification.php +++ b/src/Contracts/Notification.php @@ -28,7 +28,7 @@ public function getTitle(); * * @return \NunoMaduro\LaravelDesktopNotifier\Contracts\Notification */ - public function setTitle($title); + public function setTitle(string $title): \Joli\JoliNotif\Notification; /** * @return string @@ -40,7 +40,7 @@ public function getBody(); * * @return \NunoMaduro\LaravelDesktopNotifier\Contracts\Notification */ - public function setBody($body); + public function setBody(string $body): \Joli\JoliNotif\Notification; /** * @return string @@ -52,5 +52,5 @@ public function getIcon(); * * @return \NunoMaduro\LaravelDesktopNotifier\Contracts\Notification */ - public function setIcon($icon); + public function setIcon(string $icon): \Joli\JoliNotif\Notification; } diff --git a/src/LaravelDesktopNotifierServiceProvider.php b/src/LaravelDesktopNotifierServiceProvider.php index 9ef4205..6318cc7 100644 --- a/src/LaravelDesktopNotifierServiceProvider.php +++ b/src/LaravelDesktopNotifierServiceProvider.php @@ -11,22 +11,48 @@ namespace NunoMaduro\LaravelDesktopNotifier; -use Illuminate\Support\ServiceProvider; use Joli\JoliNotif\NotifierFactory; -use NunoMaduro\LaravelDesktopNotifier\Contracts\Notification as NotificationContract; +use Illuminate\Console\Command; +use Illuminate\Support\ServiceProvider; use NunoMaduro\LaravelDesktopNotifier\Contracts\Notifier as NotifierContract; +use NunoMaduro\LaravelDesktopNotifier\Contracts\Notification as NotificationContract; /** * The is the Laravel Desktop Notifier service provider class. - * - * @author Nuno Maduro */ class LaravelDesktopNotifierServiceProvider extends ServiceProvider { /** - * Register the laravel desktop notifier implementation. - * - * @return void + * {@inheritdoc} + */ + public function boot() + { + /* + * Sends a desktop notification. + * + * @param string $title + * @param string $body + * @param string|null $icon + * + * @return void + */ + Command::macro( + 'notify', + function (string $text, string $body, $icon = null) { + $notifier = $this->app[Contracts\Notifier::class]; + + $notification = $this->app[Contracts\Notification::class] + ->setTitle($text) + ->setBody($body) + ->setIcon($icon); + + $notifier->send($notification); + } + ); + } + + /** + * {@inheritdoc} */ public function register() { diff --git a/src/Notifications.php b/src/Notifications.php deleted file mode 100644 index edc136c..0000000 --- a/src/Notifications.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace NunoMaduro\LaravelDesktopNotifier; - -/** - * An helper trait to include on Laravel console commands. - * - * @author Nuno Maduro - */ -trait Notifications -{ - /** - * @param string $text - * @param string $body - * @param string|null $icon - * - * @return void - */ - public function notify($text, $body, $icon = null) - { - $notifier = app(Contracts\Notifier::class); - - $notification = app(Contracts\Notification::class) - ->setTitle($text) - ->setBody($body) - ->setIcon($icon); - - $notifier->send($notification); - } -} diff --git a/src/Notifier.php b/src/Notifier.php index a0c8496..6cbe3f8 100644 --- a/src/Notifier.php +++ b/src/Notifier.php @@ -39,7 +39,7 @@ public function __construct(BaseNotifier $notifier) /** * {@inheritdoc} */ - public function isSupported() + public function isSupported(): bool { return $this->notifier->isSupported(); } @@ -47,7 +47,7 @@ public function isSupported() /** * {@inheritdoc} */ - public function getPriority() + public function getPriority(): int { return $this->notifier->getPriority(); } @@ -55,7 +55,7 @@ public function getPriority() /** * {@inheritdoc} */ - public function send(\Joli\JoliNotif\Notification $notification) + public function send(\Joli\JoliNotif\Notification $notification): bool { return $this->notifier->send($notification); }