From 279c58f75dd1bc3030774699beb346ed640fc69e Mon Sep 17 00:00:00 2001 From: Marten de Jong <83412223+martenvdlp@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:47:32 +0200 Subject: [PATCH 01/18] Publish to plugin directory instead of theme --- serviceproviders/HorizonServiceProvider.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/serviceproviders/HorizonServiceProvider.php b/serviceproviders/HorizonServiceProvider.php index 2556490..a880ab6 100644 --- a/serviceproviders/HorizonServiceProvider.php +++ b/serviceproviders/HorizonServiceProvider.php @@ -4,7 +4,6 @@ namespace Vdlp\Horizon\ServiceProviders; -use Cms\Classes\Theme; use Laravel\Horizon; use Laravel\Horizon\HorizonServiceProvider as HorizonServiceProviderBase; use Vdlp\Horizon\Listeners\SendNotification; @@ -14,7 +13,7 @@ final class HorizonServiceProvider extends HorizonServiceProviderBase public function defineAssetPublishing(): void { $this->publishes([ - HORIZON_PATH . '/public' => $this->getAssetPath(), + HORIZON_PATH . '/public' => plugins_path('vdlp/horizon/assets'), ], 'horizon-assets'); } @@ -31,20 +30,4 @@ protected function registerResources(): void { $this->loadViewsFrom(plugins_path('vdlp/horizon/views'), 'horizon'); } - - private function getAssetPath(): string - { - /** @var Theme $theme */ - $theme = Theme::getActiveTheme(); - - if ($theme === null) { - return ''; - } - - return $theme->getPath(implode(DIRECTORY_SEPARATOR, [ - $theme->getDirName(), - 'assets', - 'horizon', - ])); - } } From b66efc9a1f9a5cc451338b6a9bc1bf9b7249707a Mon Sep 17 00:00:00 2001 From: Marten de Jong <83412223+martenvdlp@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:50:42 +0200 Subject: [PATCH 02/18] Load assets from plugin dir --- classes/PathHelper.php | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/classes/PathHelper.php b/classes/PathHelper.php index 7cda5a8..1861577 100644 --- a/classes/PathHelper.php +++ b/classes/PathHelper.php @@ -4,39 +4,13 @@ namespace Vdlp\Horizon\Classes; -use Cms\Classes\Theme; -use Cms\Facades\Cms; +use Illuminate\Support\Facades\URL; final class PathHelper { - /** - * @var Theme|null - */ - private $theme; - - public function __construct() - { - $this->theme = Theme::getActiveTheme(); - } - - private function hasActiveTheme(): bool - { - return $this->theme !== null; - } - public function getAssetsPath(?string $path = null): string { - if (!$this->hasActiveTheme()) { - return (string) $path; - } - - $assetsPath = $this->theme->getPath( - $this->theme->getDirName() - . DIRECTORY_SEPARATOR - . 'assets' - . DIRECTORY_SEPARATOR - . 'horizon' - ); + $assetsPath = plugins_path('vdlp/horizon/assets'); if ($path !== null) { $assetsPath .= DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR); @@ -47,11 +21,7 @@ public function getAssetsPath(?string $path = null): string public function getAssetsUrlPath(?string $path = null): string { - if (!$this->hasActiveTheme()) { - return (string) $path; - } - - $assetsUrlPath = Cms::url('/themes/' . $this->theme->getDirName() . '/assets/horizon'); + $assetsUrlPath = URL::asset('plugins/vdlp/horizon/assets'); if ($path !== null) { $assetsUrlPath .= '/' . ltrim($path, '/'); From 208b8b61303c090acf73e35fd3089948a0c0df75 Mon Sep 17 00:00:00 2001 From: Marten de Jong <83412223+martenvdlp@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:37:03 +0200 Subject: [PATCH 03/18] Instantiate PathHelper through IOC container --- views/layout.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/layout.blade.php b/views/layout.blade.php index 5dac5eb..b412e11 100644 --- a/views/layout.blade.php +++ b/views/layout.blade.php @@ -1,4 +1,4 @@ - + From df2d625be6d698dc49bd755f2c0607120ba690e9 Mon Sep 17 00:00:00 2001 From: Marten de Jong <83412223+martenvdlp@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:38:10 +0200 Subject: [PATCH 04/18] Inject UrlGenerator instead of using facade --- classes/PathHelper.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/PathHelper.php b/classes/PathHelper.php index 1861577..46bf814 100644 --- a/classes/PathHelper.php +++ b/classes/PathHelper.php @@ -4,10 +4,17 @@ namespace Vdlp\Horizon\Classes; -use Illuminate\Support\Facades\URL; +use Illuminate\Contracts\Routing\UrlGenerator; final class PathHelper { + private UrlGenerator $urlGenerator; + + public function __construct(UrlGenerator $urlGenerator) + { + $this->urlGenerator = $urlGenerator; + } + public function getAssetsPath(?string $path = null): string { $assetsPath = plugins_path('vdlp/horizon/assets'); @@ -21,7 +28,7 @@ public function getAssetsPath(?string $path = null): string public function getAssetsUrlPath(?string $path = null): string { - $assetsUrlPath = URL::asset('plugins/vdlp/horizon/assets'); + $assetsUrlPath = $this->urlGenerator->asset('plugins/vdlp/horizon/assets'); if ($path !== null) { $assetsUrlPath .= '/' . ltrim($path, '/'); From 67bbc259f26c3f3808d6719e648c64985a9c888a Mon Sep 17 00:00:00 2001 From: Marten de Jong <83412223+martenvdlp@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:38:57 +0200 Subject: [PATCH 05/18] Resolve PathHelper through IOC container --- routes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes.php b/routes.php index bb5d000..839afe4 100644 --- a/routes.php +++ b/routes.php @@ -10,7 +10,8 @@ $router->group(['middleware' => ['web']], static function () use ($router) { $router->get('/vendor/horizon/img/horizon.svg', static function () { - $helper = new PathHelper; + /** @var PathHelper $helper */ + $helper = resolve(PathHelper::class); return response()->download($helper->getAssetsPath('img/horizon.svg'), 'horizon.svg', [ 'Content-Type' => 'image/svg+xml', From 30083ebf0aded9d9ff98250320d8b76467d972d8 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:06:28 +0200 Subject: [PATCH 06/18] Update plugin description --- Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin.php b/Plugin.php index 17491fa..a6f0f29 100644 --- a/Plugin.php +++ b/Plugin.php @@ -32,7 +32,7 @@ public function pluginDetails(): array { return [ 'name' => 'Horizon', - 'description' => 'Laravel Horizon integration for OctoberCMS', + 'description' => 'Laravel Horizon integration for October CMS', 'author' => 'Van der Let & Partners', 'icon' => 'icon-area-chart', 'homepage' => 'https://octobercms.com/plugin/vdlp-horizon', From 576199e21eb095d8b480c05b8dfbce6e24fab9eb Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:36:05 +0200 Subject: [PATCH 07/18] Override the horizon:install command --- .gitignore | 3 ++ Plugin.php | 7 +++-- README.md | 14 ++------- console/InstallCommand.php | 29 +++++++++++++++++++ ...pleJobs.php => PushExampleJobsCommand.php} | 2 +- 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 console/InstallCommand.php rename console/{PushExampleJobs.php => PushExampleJobsCommand.php} (91%) diff --git a/.gitignore b/.gitignore index 4f38912..7720681 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea +assets/img +assets/app* +assets/mix-manifest.json vendor composer.lock diff --git a/Plugin.php b/Plugin.php index a6f0f29..273a0e8 100644 --- a/Plugin.php +++ b/Plugin.php @@ -11,7 +11,8 @@ use Illuminate\Notifications\NotificationServiceProvider; use Laravel\Horizon\Horizon; use System\Classes\PluginBase; -use Vdlp\Horizon\Console\PushExampleJobs; +use Vdlp\Horizon\Console\InstallCommand; +use Vdlp\Horizon\Console\PushExampleJobsCommand; use Vdlp\Horizon\ServiceProviders\HorizonServiceProvider; final class Plugin extends PluginBase @@ -60,8 +61,10 @@ public function boot(): void $this->bootNotificationSettings(); if (config('app.debug') === true) { - $this->registerConsoleCommand(PushExampleJobs::class, PushExampleJobs::class); + $this->registerConsoleCommand(PushExampleJobsCommand::class, PushExampleJobsCommand::class); } + + $this->registerConsoleCommand(InstallCommand::class, InstallCommand::class); } public function register(): void diff --git a/README.md b/README.md index d4ad487..18930b3 100644 --- a/README.md +++ b/README.md @@ -53,21 +53,13 @@ You should add the `dont-discover` option to your projects `composer.json` file > IMPORTANT: Make sure the `composer.json` is deployed to your hosting site. This will be parsed by te framework to determine which service providers should be ignored. -## Assets - -* Run the command to publish assets for the Horizon dashboard: +## Assets & Configuration ``` -php artisan vendor:publish --tag horizon-assets --force +php artisan horizon:install ``` -## Configuration - -* Run the command to publish configuration file `config/horizon.php`: - -``` -php artisan vendor:publish --tag horizon-config --force -``` +> **IMPORTANT: Add the above line to your deployment logic. This way the assets will always be up to date.** * Configure Laravel Horizon settings file at `config/horizon.php`, please make sure `use` contains `horizon` (see the configuration snippet below). diff --git a/console/InstallCommand.php b/console/InstallCommand.php new file mode 100644 index 0000000..d861d02 --- /dev/null +++ b/console/InstallCommand.php @@ -0,0 +1,29 @@ +signature = 'horizon:install'; + $this->description = 'Install all of the Horizon resources'; + + parent::__construct(); + } + + public function handle(): void + { + $this->comment('Publishing Horizon Assets...'); + $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']); + + $this->comment('Publishing Horizon Configuration...'); + $this->callSilent('vendor:publish', ['--tag' => 'horizon-config']); + + $this->info('Horizon scaffolding installed successfully.'); + } +} diff --git a/console/PushExampleJobs.php b/console/PushExampleJobsCommand.php similarity index 91% rename from console/PushExampleJobs.php rename to console/PushExampleJobsCommand.php index 0871ad6..48c99f6 100644 --- a/console/PushExampleJobs.php +++ b/console/PushExampleJobsCommand.php @@ -8,7 +8,7 @@ use October\Rain\Support\Str; use Vdlp\Horizon\Jobs\Example; -final class PushExampleJobs extends Command +final class PushExampleJobsCommand extends Command { public function __construct() { From ed521cc103197c6b38a0bc5395f16e334269e451 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:53:43 +0200 Subject: [PATCH 08/18] Add force option when installing assets --- console/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/InstallCommand.php b/console/InstallCommand.php index d861d02..74a76d3 100644 --- a/console/InstallCommand.php +++ b/console/InstallCommand.php @@ -19,7 +19,7 @@ public function __construct() public function handle(): void { $this->comment('Publishing Horizon Assets...'); - $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']); + $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets', '--force' => true]); $this->comment('Publishing Horizon Configuration...'); $this->callSilent('vendor:publish', ['--tag' => 'horizon-config']); From 1286fa232a4a2de994fcfb793cbee79e416caee7 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:54:10 +0200 Subject: [PATCH 09/18] Add fallback route if assets are not present --- routes.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/routes.php b/routes.php index 839afe4..2c1a248 100644 --- a/routes.php +++ b/routes.php @@ -3,18 +3,32 @@ declare(strict_types=1); use Illuminate\Routing\Router; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Vdlp\Horizon\Classes\PathHelper; /** @var Router $router */ $router = resolve(Router::class); -$router->group(['middleware' => ['web']], static function () use ($router) { - $router->get('/vendor/horizon/img/horizon.svg', static function () { - /** @var PathHelper $helper */ - $helper = resolve(PathHelper::class); +/** @var PathHelper $pathHelper */ +$pathHelper = resolve(PathHelper::class); - return response()->download($helper->getAssetsPath('img/horizon.svg'), 'horizon.svg', [ +$router->group(['middleware' => ['web']], static function () use ($router, $pathHelper): void { + $router->get('/vendor/horizon/img/horizon.svg', static function () use ($pathHelper): BinaryFileResponse { + return response()->download($pathHelper->getAssetsPath('img/horizon.svg'), 'horizon.svg', [ 'Content-Type' => 'image/svg+xml', ]); }); }); + +if (!file_exists($pathHelper->getAssetsPath('mix-manifest.json'))) { + $router->group([ + 'domain' => config('horizon.domain'), + 'prefix' => config('horizon.path'), + 'middleware' => config('horizon.middleware', 'web'), + ], function () use ($router): void { + $router->get('/{dashboard?}', function (): string { + return 'The published Horizon assets are not up-to-date with the installed version. ' + . 'To update, run:
php artisan horizon:install'; + }); + }); +} From e0dac08972fb9f547276bd7a1575fd703db5ec9c Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:54:48 +0200 Subject: [PATCH 10/18] Add CHANGELOG --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..994a519 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.1.0] - 2021-10-18 +### Changed +- The location of the Horizon assets has been changed. The Horizon assets are published into the plugin directory itself. Please note that you need to re-publish the assets when you're deploying your October CMS website or application using the `php artisan vendor:publish --tag horizon-assets --force` command otherwise the Horizon Dashboard will not be available. +- The `horizon:install` command can now be used to (re-)publish the Horizon Assets required for the Horizon Dashboard. +- Renamed `PushExampleJobs` to `PushExampleJobsCommand`. + +### Removed +- Removed the dependency of the October CMS module (for headless applications). + +## [1.0.0] - 2021-06-22 + +- First release of `vdlp/oc-horizon-plugin`. From a461ab1869c47983d7942039d1a29447aa0a31b3 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 12:54:59 +0200 Subject: [PATCH 11/18] Bump version to 1.1.0 --- updates/version.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/updates/version.yaml b/updates/version.yaml index d1a96ae..58abd3c 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1 +1,2 @@ 1.0.0: "First version of Vdlp.Horizon" +1.1.0: "Removed the dependency of the October CMS module. See CHANGELOG for more details." From 259e6d0345f457fd39e0517d9bda9bc97569ae6a Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 13:01:36 +0200 Subject: [PATCH 12/18] Update deployment instructions --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18930b3..ba03ef5 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,15 @@ You should add the `dont-discover` option to your projects `composer.json` file php artisan horizon:install ``` -> **IMPORTANT: Add the above line to your deployment logic. This way the assets will always be up to date.** +## Update Horizon Assets + +To update the Horizon Assets you can use the following command: + +``` +php artisan horizon:assets +``` + +> IMPORTANT: Add the above command to your deployment logic. This way the assets will always be up to date on your staging or production environment. * Configure Laravel Horizon settings file at `config/horizon.php`, please make sure `use` contains `horizon` (see the configuration snippet below). From 7ddc9af4c8a5fab59139b7d08a36d1347c073e65 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Mon, 18 Oct 2021 17:25:13 +0200 Subject: [PATCH 13/18] Remove --force flag use horizon:assets --- console/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/InstallCommand.php b/console/InstallCommand.php index 74a76d3..d861d02 100644 --- a/console/InstallCommand.php +++ b/console/InstallCommand.php @@ -19,7 +19,7 @@ public function __construct() public function handle(): void { $this->comment('Publishing Horizon Assets...'); - $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets', '--force' => true]); + $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']); $this->comment('Publishing Horizon Configuration...'); $this->callSilent('vendor:publish', ['--tag' => 'horizon-config']); From 7a6081226963f3e0982ba480269e90a6457c62e2 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Tue, 19 Oct 2021 11:06:56 +0200 Subject: [PATCH 14/18] Add improved Horizon assets check --- classes/PathHelper.php | 19 ++++++++++++++++++- routes.php | 16 +++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/classes/PathHelper.php b/classes/PathHelper.php index 46bf814..9f8e696 100644 --- a/classes/PathHelper.php +++ b/classes/PathHelper.php @@ -4,15 +4,20 @@ namespace Vdlp\Horizon\Classes; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Contracts\Routing\UrlGenerator; +use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\File; final class PathHelper { private UrlGenerator $urlGenerator; + private Filesystem $filesystem; - public function __construct(UrlGenerator $urlGenerator) + public function __construct(UrlGenerator $urlGenerator, Filesystem $filesystem) { $this->urlGenerator = $urlGenerator; + $this->filesystem = $filesystem; } public function getAssetsPath(?string $path = null): string @@ -36,4 +41,16 @@ public function getAssetsUrlPath(?string $path = null): string return $assetsUrlPath; } + + public function assetsAreCurrent(): bool + { + $publishedPath = $this->getAssetsPath('mix-manifest.json'); + $vendorPath = base_path('vendor/laravel/horizon/public/mix-manifest.json'); + + try { + return $this->filesystem->get($publishedPath) === $this->filesystem->get($vendorPath); + } catch (FileNotFoundException $exception) { + return false; + } + } } diff --git a/routes.php b/routes.php index 2c1a248..ac2eacc 100644 --- a/routes.php +++ b/routes.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Routing\Router; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Vdlp\Horizon\Classes\PathHelper; @@ -20,15 +22,19 @@ }); }); -if (!file_exists($pathHelper->getAssetsPath('mix-manifest.json'))) { +if (!$pathHelper->assetsAreCurrent()) { $router->group([ 'domain' => config('horizon.domain'), 'prefix' => config('horizon.path'), 'middleware' => config('horizon.middleware', 'web'), - ], function () use ($router): void { - $router->get('/{dashboard?}', function (): string { - return 'The published Horizon assets are not up-to-date with the installed version. ' - . 'To update, run:
php artisan horizon:install'; + ], static function () use ($router): void { + $router->get('/{dashboard?}', static function (Request $request) { + if (Laravel\Horizon\Horizon::check($request)) { + return 'The published Horizon assets are not up-to-date with the installed version. ' + . 'To update, run:
php artisan horizon:assets'; + } + + return new Response('Not Found', 404); }); }); } From ec8e6dd7e52ea33e472ba2552fbe6fbc239726a0 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Tue, 19 Oct 2021 12:08:24 +0200 Subject: [PATCH 15/18] Update CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 994a519..18dda71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.1.0] - 2021-10-18 ### Changed -- The location of the Horizon assets has been changed. The Horizon assets are published into the plugin directory itself. Please note that you need to re-publish the assets when you're deploying your October CMS website or application using the `php artisan vendor:publish --tag horizon-assets --force` command otherwise the Horizon Dashboard will not be available. -- The `horizon:install` command can now be used to (re-)publish the Horizon Assets required for the Horizon Dashboard. +- The location of the Horizon assets has been changed. The Horizon assets are published into the plugin directory itself (`plugins/vdlp/horizon/assets`). Please note that you need to re-publish the assets when you are deploying your October CMS website or application using the `php artisan horizon:assets` command otherwise the Horizon Dashboard will not be available. +- The `horizon:assets` command can now be used to (re-)publish the Horizon Assets required for the Horizon Dashboard. - Renamed `PushExampleJobs` to `PushExampleJobsCommand`. ### Removed From e4630c7e0bcd877f0077dc35270d7207e08cd302 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Tue, 19 Oct 2021 12:18:21 +0200 Subject: [PATCH 16/18] Set miminum required PHP version to 7.4 --- CHANGELOG.md | 4 +++ Plugin.php | 53 ++++++++++++++-------------------- classes/PathHelper.php | 5 ++-- composer.json | 2 +- jobs/Example.php | 7 +++-- listeners/SendNotification.php | 24 +++++++-------- models/Settings.php | 4 +-- updates/version.yaml | 2 +- 8 files changed, 46 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18dda71..c500505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.1.0] - 2021-10-18 +### Added +- PHP 7.4 and PHP 8.0 support. + ### Changed - The location of the Horizon assets has been changed. The Horizon assets are published into the plugin directory itself (`plugins/vdlp/horizon/assets`). Please note that you need to re-publish the assets when you are deploying your October CMS website or application using the `php artisan horizon:assets` command otherwise the Horizon Dashboard will not be available. - The `horizon:assets` command can now be used to (re-)publish the Horizon Assets required for the Horizon Dashboard. @@ -12,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Removed the dependency of the October CMS module (for headless applications). +- Support for PHP 7.1 ## [1.0.0] - 2021-06-22 diff --git a/Plugin.php b/Plugin.php index 273a0e8..7fade00 100644 --- a/Plugin.php +++ b/Plugin.php @@ -17,10 +17,7 @@ final class Plugin extends PluginBase { - /** - * @var Backend - */ - private $backend; + private Backend $backend; public function __construct($app) { @@ -44,8 +41,8 @@ public function boot(): void { config()->set('app.env', $this->app->environment()); - Horizon::auth(static function () { - /** @var User $user */ + Horizon::auth(static function (): bool { + /** @var ?User $user */ $user = AuthManager::instance()->getUser(); if ($user === null) { @@ -82,32 +79,26 @@ public function registerSchedule($schedule): void public function registerPermissions(): array { - return array_merge( - (array) parent::registerPermissions(), - [ - 'vdlp.horizon.access_dashboard' => [ - 'tab' => 'Horizon', - 'label' => 'Access to the Horizon dashboard', - 'roles' => ['developer'], - ], - ] - ); + return [ + 'vdlp.horizon.access_dashboard' => [ + 'tab' => 'Horizon', + 'label' => 'Access to the Horizon dashboard', + 'roles' => ['developer'], + ], + ]; } public function registerNavigation(): array { - return array_merge( - (array) parent::registerNavigation(), - [ - 'dashboard' => [ - 'label' => 'Horizon', - 'url' => $this->backend->url('vdlp/horizon/dashboard'), - 'iconSvg' => '/plugins/vdlp/horizon/assets/icons/horizon.svg', - 'permissions' => ['vdlp.horizon.access_dashboard'], - 'order' => 500, - ], - ] - ); + return [ + 'dashboard' => [ + 'label' => 'Horizon', + 'url' => $this->backend->url('vdlp/horizon/dashboard'), + 'iconSvg' => '/plugins/vdlp/horizon/assets/icons/horizon.svg', + 'permissions' => ['vdlp.horizon.access_dashboard'], + 'order' => 500, + ], + ]; } public function registerMailTemplates(): array @@ -119,20 +110,20 @@ public function registerMailTemplates(): array private function bootNotificationSettings(): void { - if (config('vdlp.horizon::mail_notifications_enabled', false)) { + if ((bool) config('vdlp.horizon::mail_notifications_enabled', false)) { Horizon::routeMailNotificationsTo( config('vdlp.horizon::mail_notifications_to') ); } - if (config('vdlp.horizon::slack_notifications_enabled', false)) { + if ((bool) config('vdlp.horizon::slack_notifications_enabled', false)) { Horizon::routeSlackNotificationsTo( config('vdlp.horizon::slack_notifications_webhook_url'), config('vdlp.horizon::slack_notifications_channel') ); } - if (config('vdlp.horizon::sms_notifications_enabled', false)) { + if ((bool) config('vdlp.horizon::sms_notifications_enabled', false)) { Horizon::routeSmsNotificationsTo( config('vdlp.horizon::sms_notifications_to') ); diff --git a/classes/PathHelper.php b/classes/PathHelper.php index 9f8e696..75eab04 100644 --- a/classes/PathHelper.php +++ b/classes/PathHelper.php @@ -4,10 +4,9 @@ namespace Vdlp\Horizon\Classes; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Contracts\Routing\UrlGenerator; use Illuminate\Filesystem\Filesystem; -use Illuminate\Support\Facades\File; +use Throwable; final class PathHelper { @@ -49,7 +48,7 @@ public function assetsAreCurrent(): bool try { return $this->filesystem->get($publishedPath) === $this->filesystem->get($vendorPath); - } catch (FileNotFoundException $exception) { + } catch (Throwable $exception) { return false; } } diff --git a/composer.json b/composer.json index 66a3e3c..0e6ed0c 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "license": "GPL-2.0-only", "require": { - "php": ">=7.1", + "php": "^7.4 || ^8.0", "ext-pcntl": "*", "ext-posix": "*", "ext-redis": "*", diff --git a/jobs/Example.php b/jobs/Example.php index 5d137a4..95f13a0 100644 --- a/jobs/Example.php +++ b/jobs/Example.php @@ -12,8 +12,10 @@ final class Example implements ShouldQueue { - use Dispatchable, Queueable; - private $fooBar; + use Dispatchable; + use Queueable; + + private string $fooBar; public function __construct(string $fooBar) { @@ -21,7 +23,6 @@ public function __construct(string $fooBar) } /** - * @param LoggerInterface $log * @throws Exception */ public function handle(LoggerInterface $log): void diff --git a/listeners/SendNotification.php b/listeners/SendNotification.php index 9c4f6a9..465e026 100644 --- a/listeners/SendNotification.php +++ b/listeners/SendNotification.php @@ -11,15 +11,8 @@ final class SendNotification { - /** - * @var Horizon\Lock - */ - private $lock; - - /** - * @var Mailer - */ - private $mailer; + private Horizon\Lock $lock; + private Mailer $mailer; public function __construct(Horizon\Lock $lock, Mailer $mailer) { @@ -46,11 +39,14 @@ public function handle(Horizon\Events\LongWaitDetected $event): void 'seconds' => $notification->seconds, ]; - $this->mailer->send('vdlp.horizon::mail.long-wait-detected', $data, static function (Message $message) { - $message - ->to(Horizon\Horizon::$email) - ->subject(config('app.name') . ': Long Queue Wait Detected'); - }); + $this->mailer->send( + 'vdlp.horizon::mail.long-wait-detected', + $data, + static function (Message $message): void { + $message + ->to(Horizon\Horizon::$email) + ->subject(config('app.name') . ': Long Queue Wait Detected'); + }); } } } diff --git a/models/Settings.php b/models/Settings.php index c1b8cb1..af7f499 100644 --- a/models/Settings.php +++ b/models/Settings.php @@ -13,8 +13,8 @@ final class Settings extends Model { public $implement = ['System.Behaviors.SettingsModel']; - public $settingsCode = 'vdlp_horizon_settings'; - public $settingsFields = 'fields.yaml'; + public string $settingsCode = 'vdlp_horizon_settings'; + public string $settingsFields = 'fields.yaml'; public function isMailNotificationEnabled(): bool { diff --git a/updates/version.yaml b/updates/version.yaml index 58abd3c..465f767 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1,2 +1,2 @@ 1.0.0: "First version of Vdlp.Horizon" -1.1.0: "Removed the dependency of the October CMS module. See CHANGELOG for more details." +1.1.0: "Removed the dependency of the October CMS module. Moved Horizon Assets. See CHANGELOG for more details." From c4f25798a8678c35019bf9be33f4e4d5c1b7895d Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Tue, 19 Oct 2021 19:28:17 +0200 Subject: [PATCH 17/18] Override all Horizon routes when assets invalid --- routes.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/routes.php b/routes.php index ac2eacc..b636b3a 100644 --- a/routes.php +++ b/routes.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Illuminate\Routing\Router; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Vdlp\Horizon\Classes\PathHelper; @@ -16,7 +16,10 @@ $router->group(['middleware' => ['web']], static function () use ($router, $pathHelper): void { $router->get('/vendor/horizon/img/horizon.svg', static function () use ($pathHelper): BinaryFileResponse { - return response()->download($pathHelper->getAssetsPath('img/horizon.svg'), 'horizon.svg', [ + /** @var ResponseFactory $factory */ + $factory = resolve(ResponseFactory::class); + + return $factory->download($pathHelper->getAssetsPath('img/horizon.svg'), 'horizon.svg', [ 'Content-Type' => 'image/svg+xml', ]); }); @@ -28,13 +31,13 @@ 'prefix' => config('horizon.path'), 'middleware' => config('horizon.middleware', 'web'), ], static function () use ($router): void { - $router->get('/{dashboard?}', static function (Request $request) { + $router->get('/{anything?}', static function (Request $request): string { if (Laravel\Horizon\Horizon::check($request)) { return 'The published Horizon assets are not up-to-date with the installed version. ' . 'To update, run:
php artisan horizon:assets'; } - return new Response('Not Found', 404); - }); + abort(403); + })->where('anything', '(.*)'); }); } From 8e93029f985a3214e137c4f93ed75da145b0e5d6 Mon Sep 17 00:00:00 2001 From: Alwin Drenth Date: Fri, 5 Nov 2021 10:52:37 +0100 Subject: [PATCH 18/18] Bump version and update documentation --- CHANGELOG.md | 2 +- README.md | 4 ++-- composer.json | 1 - updates/version.yaml | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c500505..4fbce92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.1.0] - 2021-10-18 +## [2.0.0] - 2021-11-05 ### Added - PHP 7.4 and PHP 8.0 support. diff --git a/README.md b/README.md index ba03ef5..53ba141 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Horizon is 100% open source, so you're free to dig through the source to see exa ## Requirements -* October CMS 1.0 -* Due to its usage of async process signals, Horizon requires **PHP 7.1+**. +* October CMS 1.0 or higher +* PHP 7.4 or PHP 8.0+ * PHP extensions: `ext-pcntl`, `ext-posix` and `ext-redis`. * Supervisor, see [Laravel 6.x supervisor configuration](https://laravel.com/docs/6.x/queues#supervisor-configuration). diff --git a/composer.json b/composer.json index 0e6ed0c..3550ee3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ "ext-redis": "*", "laravel/horizon": "^3.0", "composer/installers": "^1.0" - }, "archive": { "exclude": [ diff --git a/updates/version.yaml b/updates/version.yaml index 465f767..12d7820 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1,2 +1,2 @@ 1.0.0: "First version of Vdlp.Horizon" -1.1.0: "Removed the dependency of the October CMS module. Moved Horizon Assets. See CHANGELOG for more details." +2.0.0: "Removed the dependency of the October CMS module. Moved Horizon Assets. See CHANGELOG for more details."