From b0853b7304790f4ebed094cc2e888defdf320d05 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 30 Nov 2021 13:51:38 +0200 Subject: [PATCH 1/5] fix: Remove emited event when registering repositories. --- src/Events/AddedRepositories.php | 11 ----------- src/Restify.php | 2 -- 2 files changed, 13 deletions(-) delete mode 100644 src/Events/AddedRepositories.php diff --git a/src/Events/AddedRepositories.php b/src/Events/AddedRepositories.php deleted file mode 100644 index ed257c3c2..000000000 --- a/src/Events/AddedRepositories.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Tue, 30 Nov 2021 11:52:03 +0000 Subject: [PATCH 2/5] Fix styling --- src/Restify.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Restify.php b/src/Restify.php index 74f0acb9b..e19a5f663 100644 --- a/src/Restify.php +++ b/src/Restify.php @@ -2,7 +2,6 @@ namespace Binaryk\LaravelRestify; -use Binaryk\LaravelRestify\Events\AddedRepositories; use Binaryk\LaravelRestify\Events\RestifyBeforeEach; use Binaryk\LaravelRestify\Events\RestifyStarting; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; From a8ebde3e0081fd88eea95bdb7cadb341322fd8ef Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 30 Nov 2021 13:53:13 +0200 Subject: [PATCH 3/5] fix: wip --- UPGRADING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index 97b9253d1..0eab387fd 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -2,6 +2,10 @@ Because there are many breaking changes an upgrade is not that easy. There are many edge cases this guide does not cover. We accept PRs to improve this guide. +## From 6.2.1 to 6.3.0 + +- The `src/Events/AddedRepositories.php` event was removed because of a [conflict with telescope](https://github.com/laravel/telescope/issues/1152). + ## From 5.x to 6.x ### Filtering From dd4238247a78c989ce534c420b7034a494d70ba1 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 30 Nov 2021 15:54:34 +0200 Subject: [PATCH 4/5] fix: tests --- src/LaravelRestifyServiceProvider.php | 13 ------- src/Listeners/MountMissingRepositories.php | 16 -------- src/Restify.php | 45 ++++++++++++---------- src/RestifyApplicationServiceProvider.php | 5 +-- 4 files changed, 27 insertions(+), 52 deletions(-) delete mode 100644 src/Listeners/MountMissingRepositories.php diff --git a/src/LaravelRestifyServiceProvider.php b/src/LaravelRestifyServiceProvider.php index 5ce645a50..d8345bab4 100644 --- a/src/LaravelRestifyServiceProvider.php +++ b/src/LaravelRestifyServiceProvider.php @@ -13,12 +13,9 @@ use Binaryk\LaravelRestify\Commands\SetupCommand; use Binaryk\LaravelRestify\Commands\StoreCommand; use Binaryk\LaravelRestify\Commands\StubCommand; -use Binaryk\LaravelRestify\Events\AddedRepositories; use Binaryk\LaravelRestify\Http\Middleware\RestifyInjector; -use Binaryk\LaravelRestify\Listeners\MountMissingRepositories; use Binaryk\LaravelRestify\Repositories\Repository; use Illuminate\Contracts\Http\Kernel as HttpKernel; -use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -38,8 +35,6 @@ public function boot(): void $this->registerPublishing(); } - $this->listeners(); - $this->app->make(HttpKernel::class)->pushMiddleware(RestifyInjector::class); } @@ -95,12 +90,4 @@ public static function migrationFileExists(string $migrationFileName): bool return false; } - - private function listeners(): void - { - Event::listen( - AddedRepositories::class, - [MountMissingRepositories::class, 'handle'], - ); - } } diff --git a/src/Listeners/MountMissingRepositories.php b/src/Listeners/MountMissingRepositories.php deleted file mode 100644 index 57c120bf3..000000000 --- a/src/Listeners/MountMissingRepositories.php +++ /dev/null @@ -1,16 +0,0 @@ -repositories)->each(function (string $repository) { - (new BootRepository($repository))->boot(); - }); - } -} diff --git a/src/Restify.php b/src/Restify.php index e19a5f663..13e2d4558 100644 --- a/src/Restify.php +++ b/src/Restify.php @@ -2,6 +2,7 @@ namespace Binaryk\LaravelRestify; +use Binaryk\LaravelRestify\Bootstrap\BootRepository; use Binaryk\LaravelRestify\Events\RestifyBeforeEach; use Binaryk\LaravelRestify\Events\RestifyStarting; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; @@ -57,7 +58,7 @@ public static function repositoryForKey(string $key): ?string /** * Get the repository class name for a given model. * - * @param string $model + * @param string $model * @return string */ public static function repositoryForModel($model) @@ -74,7 +75,7 @@ public static function repositoryForModel($model) /** * Get the repository class name for a given table name. * - * @param string $table + * @param string $table * @return string */ public static function repositoryForTable($table) @@ -87,7 +88,7 @@ public static function repositoryForTable($table) /** * Register the given repositories. * - * @param array $repositories + * @param array $repositories * @return static */ public static function repositories(array $repositories) @@ -96,6 +97,9 @@ public static function repositories(array $repositories) array_merge(static::$repositories, $repositories) ); + collect($repositories)->each(function (string $repository) { + (new BootRepository($repository))->boot(); + }); return new static; } @@ -115,12 +119,13 @@ public static function repositoriesFrom(string $directory): void foreach ((new Finder)->in($directory)->files() as $repository) { $repository = $namespace.str_replace( - ['/', '.php'], - ['\\', ''], - Str::after($repository->getPathname(), app_path().DIRECTORY_SEPARATOR) - ); + ['/', '.php'], + ['\\', ''], + Str::after($repository->getPathname(), app_path().DIRECTORY_SEPARATOR) + ); - if (is_subclass_of($repository, Repository::class) && (new ReflectionClass($repository))->isInstantiable()) { + if (is_subclass_of($repository, + Repository::class) && (new ReflectionClass($repository))->isInstantiable()) { $repositories[] = $repository; } } @@ -133,12 +138,12 @@ public static function repositoriesFrom(string $directory): void /** * Get the URI path prefix utilized by Restify. * - * @param null $plus + * @param null $plus * @return string */ public static function path($plus = null) { - if (! is_null($plus)) { + if (!is_null($plus)) { return config('restify.base', '/restify-api').'/'.$plus; } @@ -150,7 +155,7 @@ public static function path($plus = null) * * This listener is added in the RestifyApplicationServiceProvider * - * @param \Closure|string $callback + * @param \Closure|string $callback * @return void */ public static function starting($callback) @@ -159,7 +164,7 @@ public static function starting($callback) } /** - * @param \Closure|string $callback + * @param \Closure|string $callback */ public static function beforeEach($callback) { @@ -169,7 +174,7 @@ public static function beforeEach($callback) /** * Set the callback used for intercepting any request exception. * - * @param \Closure|string $callback + * @param \Closure|string $callback */ public static function exceptionHandler($callback) { @@ -179,8 +184,8 @@ public static function exceptionHandler($callback) public static function globallySearchableRepositories(RestifyRequest $request): array { return collect(static::$repositories) - ->filter(fn ($repository) => $repository::authorizedToUseRepository($request)) - ->filter(fn ($repository) => $repository::$globallySearchable) + ->filter(fn($repository) => $repository::authorizedToUseRepository($request)) + ->filter(fn($repository) => $repository::$globallySearchable) ->sortBy(static::sortResourcesWith()) ->all(); } @@ -195,7 +200,7 @@ public static function sortResourcesWith() /** * Humanize the given value into a proper name. * - * @param string $value + * @param string $value * @return string */ public static function humanize($value) @@ -225,10 +230,10 @@ public static function isRestify(Request $request): bool $request->is(trim($path.'/*', '/')) || $request->is('restify-api/*') || collect(static::$repositories) - ->filter(fn ($repository) => $repository::prefix()) - ->some(fn ($repository) => $request->is($repository::prefix().'/*')) || + ->filter(fn($repository) => $repository::prefix()) + ->some(fn($repository) => $request->is($repository::prefix().'/*')) || collect(static::$repositories) - ->filter(fn ($repository) => $repository::indexPrefix()) - ->some(fn ($repository) => $request->is($repository::indexPrefix().'/*')); + ->filter(fn($repository) => $repository::indexPrefix()) + ->some(fn($repository) => $request->is($repository::indexPrefix().'/*')); } } diff --git a/src/RestifyApplicationServiceProvider.php b/src/RestifyApplicationServiceProvider.php index 91170297a..a76a29806 100644 --- a/src/RestifyApplicationServiceProvider.php +++ b/src/RestifyApplicationServiceProvider.php @@ -7,6 +7,7 @@ use Binaryk\LaravelRestify\Http\Controllers\Auth\RegisterController; use Binaryk\LaravelRestify\Http\Controllers\Auth\ResetPasswordController; use Binaryk\LaravelRestify\Http\Controllers\Auth\VerifyController; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; @@ -33,9 +34,7 @@ public function boot() */ protected function repositories(): void { - if ((false === is_dir(app_path('Restify'))) && ! mkdir($concurrentDirectory = app_path('Restify')) && ! is_dir($concurrentDirectory)) { - throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); - } + app(Filesystem::class)->ensureDirectoryExists(app_path('Restify')); Restify::repositoriesFrom(app_path('Restify')); } From 4503a8d7ea40151a8420f2a8ee953802cab511c0 Mon Sep 17 00:00:00 2001 From: binaryk Date: Tue, 30 Nov 2021 13:54:58 +0000 Subject: [PATCH 5/5] Fix styling --- src/Restify.php | 30 ++++++++++++----------- src/RestifyApplicationServiceProvider.php | 1 - 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Restify.php b/src/Restify.php index 13e2d4558..f4d744388 100644 --- a/src/Restify.php +++ b/src/Restify.php @@ -119,13 +119,15 @@ public static function repositoriesFrom(string $directory): void foreach ((new Finder)->in($directory)->files() as $repository) { $repository = $namespace.str_replace( - ['/', '.php'], - ['\\', ''], - Str::after($repository->getPathname(), app_path().DIRECTORY_SEPARATOR) - ); - - if (is_subclass_of($repository, - Repository::class) && (new ReflectionClass($repository))->isInstantiable()) { + ['/', '.php'], + ['\\', ''], + Str::after($repository->getPathname(), app_path().DIRECTORY_SEPARATOR) + ); + + if (is_subclass_of( + $repository, + Repository::class + ) && (new ReflectionClass($repository))->isInstantiable()) { $repositories[] = $repository; } } @@ -143,7 +145,7 @@ public static function repositoriesFrom(string $directory): void */ public static function path($plus = null) { - if (!is_null($plus)) { + if (! is_null($plus)) { return config('restify.base', '/restify-api').'/'.$plus; } @@ -184,8 +186,8 @@ public static function exceptionHandler($callback) public static function globallySearchableRepositories(RestifyRequest $request): array { return collect(static::$repositories) - ->filter(fn($repository) => $repository::authorizedToUseRepository($request)) - ->filter(fn($repository) => $repository::$globallySearchable) + ->filter(fn ($repository) => $repository::authorizedToUseRepository($request)) + ->filter(fn ($repository) => $repository::$globallySearchable) ->sortBy(static::sortResourcesWith()) ->all(); } @@ -230,10 +232,10 @@ public static function isRestify(Request $request): bool $request->is(trim($path.'/*', '/')) || $request->is('restify-api/*') || collect(static::$repositories) - ->filter(fn($repository) => $repository::prefix()) - ->some(fn($repository) => $request->is($repository::prefix().'/*')) || + ->filter(fn ($repository) => $repository::prefix()) + ->some(fn ($repository) => $request->is($repository::prefix().'/*')) || collect(static::$repositories) - ->filter(fn($repository) => $repository::indexPrefix()) - ->some(fn($repository) => $request->is($repository::indexPrefix().'/*')); + ->filter(fn ($repository) => $repository::indexPrefix()) + ->some(fn ($repository) => $request->is($repository::indexPrefix().'/*')); } } diff --git a/src/RestifyApplicationServiceProvider.php b/src/RestifyApplicationServiceProvider.php index a76a29806..d86ce4fb0 100644 --- a/src/RestifyApplicationServiceProvider.php +++ b/src/RestifyApplicationServiceProvider.php @@ -12,7 +12,6 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use ReflectionException; -use RuntimeException; class RestifyApplicationServiceProvider extends ServiceProvider {