From 2e3fcbfa34f092f3a98d0974fb743a32f8718269 Mon Sep 17 00:00:00 2001 From: Harish Toshniwal Date: Fri, 7 Sep 2018 04:38:39 +0530 Subject: [PATCH] first commit --- .gitignore | 6 ++ CHANGELOG.md | 4 + LICENSE.txt | 21 +++++ README.md | 97 ++++++++++++++++++++++++ composer.json | 33 ++++++++ config/mailviewer.php | 58 ++++++++++++++ src/MailViewer.php | 58 ++++++++++++++ src/MailViewerServiceProvider.php | 24 ++++++ src/controllers/MailViewerController.php | 30 ++++++++ src/routes/web.php | 11 +++ src/views/index.blade.php | 47 ++++++++++++ 11 files changed, 389 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/mailviewer.php create mode 100644 src/MailViewer.php create mode 100644 src/MailViewerServiceProvider.php create mode 100644 src/controllers/MailViewerController.php create mode 100644 src/routes/web.php create mode 100644 src/views/index.blade.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19adabd --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/vendor +composer.lock +.DS_Store +Thumbs.db +phpunit.xml +/.idea \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d9093e6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +All notable changes to the Laravel Mail Viewer be documented in this file + +## v0.1.0 (07-09-2018) +- Initial release \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9bb7eb8 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Jogg Inc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac0906d --- /dev/null +++ b/README.md @@ -0,0 +1,97 @@ +# View all your mailables at a single place + +The Design and content team members often need access to the emails your app will be sending out to the users. This is a fairly simple package that makes it possible and tries to minimize developer dependency. By using this package, you can have a dedicated route to view all your mailables at a single place. + +## Installation + +You can install this package via composer using this command: + +```bash +composer require joggapp/laravel-mail-viewer +``` + +The package will automatically register itself. + +You will have to configure the package settings using the package's config file. You can publish the config file with: + +```bash +php artisan vendor:publish --provider="JoggApp\MailViewer\MailViewerServiceProvider" --tag="config" +``` + +This will create the package's config file called `mailviewer.php` in the `config` directory. These are the contents of the published config file: + +```php +return [ + /* + |-------------------------------------------------------------------------- + | Register the mailables that should be accessible + |-------------------------------------------------------------------------- + | + | You have to add the mailables including their dependencies + | in the following array. When asked for a mailable, + | the package will search it here. + | + | Eg: [ new OrderShipped(factory(Order::class)->create()) ] + | + */ + + 'mailables' => [], + + /* + |-------------------------------------------------------------------------- + | URL where you want to view the mails + |-------------------------------------------------------------------------- + | + | This is the URL where you can view all the mailables + | registered in your application. + | + */ + + 'url' => 'mails', + + /* + |-------------------------------------------------------------------------- + | The environments in which the url should be accesible + |-------------------------------------------------------------------------- + | + | If you don't want to use this package in production env + | at all, you can restrict that using this option + | rather than by using a middleware. + | + */ + + 'allowed_environments' => ['local', 'staging'], + + /* + |-------------------------------------------------------------------------- + | Middlewares that should be applied to the URL + |-------------------------------------------------------------------------- + | + | The value should be an array of fully qualified + | class names of the middlware classes. + | + | Eg: [Authenticate::class, CheckForMaintenanceMode::class] + | Don't forget to import the classes at the top! + | + */ + + 'middlewares' => [], +]; +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Security + +If you discover any security related issues, please email [harish@jogg.co](mailto:harish@jogg.co) instead of using the issue tracker. + +## Credits + +- [Harish Toshniwal](https://github.com/introwit) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.txt) for more information. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..89af04b --- /dev/null +++ b/composer.json @@ -0,0 +1,33 @@ +{ + "name": "joggapp/laravel-mail-viewer", + "description": "View all your mailables at a single place", + "license": "MIT", + "authors": [ + { + "name": "Harish Toshniwal", + "email": "harish@jogg.co" + } + ], + "autoload": { + "psr-4": { + "JoggApp\\MailViewer\\": "src" + } + }, + "require": { + "php": "^7.1", + "illuminate/routing": "5.6.*|5.7.*", + "illuminate/support": "5.6.*|5.7.*" + }, + "extra": { + "laravel": { + "providers": [ + "JoggApp\\MailViewer\\MailViewerServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/config/mailviewer.php b/config/mailviewer.php new file mode 100644 index 0000000..238f7df --- /dev/null +++ b/config/mailviewer.php @@ -0,0 +1,58 @@ +create()) ] + | + */ + + 'mailables' => [], + + /* + |-------------------------------------------------------------------------- + | URL where you want to view the mails + |-------------------------------------------------------------------------- + | + | This is the URL where you can view all the mailables + | registered in your application. + | + */ + + 'url' => 'mails', + + /* + |-------------------------------------------------------------------------- + | The environments in which the url should be accesible + |-------------------------------------------------------------------------- + | + | If you don't want to use this package in production env + | at all, you can restrict that using this option + | rather than by using a middleware. + | + */ + + 'allowed_environments' => ['local', 'staging'], + + /* + |-------------------------------------------------------------------------- + | Middlewares that should be applied to the URL + |-------------------------------------------------------------------------- + | + | The value should be an array of fully qualified + | class names of the middlware classes. + | + | Eg: [Authenticate::class, CheckForMaintenanceMode::class] + | Don't forget to import the classes at the top! + | + */ + + 'middlewares' => [], +]; diff --git a/src/MailViewer.php b/src/MailViewer.php new file mode 100644 index 0000000..1ddc577 --- /dev/null +++ b/src/MailViewer.php @@ -0,0 +1,58 @@ +getShortName() === $mail) { + return $mailable; + } + } + + throw new Exception("No mailable called {$mail} is registered in config/mailviewer.php file"); + } + + public static function url() + { + $url = config('mailviewer.url', 'mails'); + + if ((!empty($url)) && is_string($url)) { + return $url; + } + + throw new Exception('Please set a valid URL to view the mails'); + } + + public static function middlewares() + { + $middlewares = config('mailviewer.middlewares', []); + + if (is_array($middlewares)) { + return $middlewares; + } + + throw new Exception('The middlewares config value only excepts an array'); + } +} diff --git a/src/MailViewerServiceProvider.php b/src/MailViewerServiceProvider.php new file mode 100644 index 0000000..fb95ada --- /dev/null +++ b/src/MailViewerServiceProvider.php @@ -0,0 +1,24 @@ +publishes([ + __DIR__ . '/../config/mailviewer.php' => config_path('mailviewer.php'), + ]); + + $this->loadRoutesFrom(__DIR__ . '/routes/web.php'); + + $this->loadViewsFrom(__DIR__ . '/views', 'mailviewer'); + } + + public function register() + { + // + } +} diff --git a/src/controllers/MailViewerController.php b/src/controllers/MailViewerController.php new file mode 100644 index 0000000..88a191b --- /dev/null +++ b/src/controllers/MailViewerController.php @@ -0,0 +1,30 @@ +middleware(MailViewer::middlewares()); + +Route::get(MailViewer::url() . '/{mail}', 'JoggApp\MailViewer\Controllers\MailViewerController@show') + ->middleware(MailViewer::middlewares()) + ->name('mv-mailviewer'); diff --git a/src/views/index.blade.php b/src/views/index.blade.php new file mode 100644 index 0000000..798f763 --- /dev/null +++ b/src/views/index.blade.php @@ -0,0 +1,47 @@ + + + + + + + + Laravel Mail Viewer + + + + + @if(empty($mails)) +

There are no mails

+ @else +
    + @foreach($mails as $mail) +
  1. {{ $mail }}
  2. + @endforeach +
+ @endif + + \ No newline at end of file