From 959cb40d3855b0564f09e9634e040ac886b53b46 Mon Sep 17 00:00:00 2001 From: Aslam Date: Tue, 11 Apr 2023 00:42:52 +0700 Subject: [PATCH 1/3] Pint Style Changes --- ...21_232515_create_shareable_links_table.php | 4 ++-- ...notify_column_to_shareable_links_table.php | 4 ++-- ...hash_column_from_shareable_links_table.php | 4 ++-- src/Events/LinkWasVisited.php | 6 ++++-- .../ShareableLinkPasswordController.php | 8 +++++--- src/Http/Middleware/ValidateShareableLink.php | 12 +++++------ src/Shareable/Shareable.php | 5 +++-- src/Shareable/ShareableLink.php | 10 ++++++---- src/Shareable/ShareableLinkBuilder.php | 20 ++++++++++--------- src/ShareableLinkServiceProvider.php | 20 ++++++++++--------- .../ShareableLinkPasswordControllerTest.php | 4 ++-- .../Middleware/ValidateShareableLinkTest.php | 8 +++++--- tests/Shareable/ShareableLinkBuilderTest.php | 2 +- tests/TestCase.php | 11 +++++----- 14 files changed, 65 insertions(+), 53 deletions(-) diff --git a/database/migrations/2017_05_21_232515_create_shareable_links_table.php b/database/migrations/2017_05_21_232515_create_shareable_links_table.php index 356c41d..2cf637e 100644 --- a/database/migrations/2017_05_21_232515_create_shareable_links_table.php +++ b/database/migrations/2017_05_21_232515_create_shareable_links_table.php @@ -1,8 +1,8 @@ route('shareable_link'); - if (!$link->isActive()) { + if (! $link->isActive()) { return redirect(config('shareable-model.redirect_routes.inactive')); } @@ -32,7 +32,7 @@ public function handle(Request $request, Closure $next) return redirect(config('shareable-model.redirect_routes.expired')); } - if ($link->requiresPassword() && !session($link->uuid)) { + if ($link->requiresPassword() && ! session($link->uuid)) { return redirect(url(config('shareable-model.redirect_routes.password_protected'), $link->uuid)); } diff --git a/src/Shareable/Shareable.php b/src/Shareable/Shareable.php index 954a20e..fbd5959 100644 --- a/src/Shareable/Shareable.php +++ b/src/Shareable/Shareable.php @@ -1,9 +1,10 @@ -password); + return ! is_null($this->password); } public function shouldNotify(): bool diff --git a/src/Shareable/ShareableLinkBuilder.php b/src/Shareable/ShareableLinkBuilder.php index 8442e7f..32771dc 100644 --- a/src/Shareable/ShareableLinkBuilder.php +++ b/src/Shareable/ShareableLinkBuilder.php @@ -1,29 +1,31 @@ - $this->expirationDate, 'uuid' => $uuid, 'url' => $this->buildUrl($uuid), - 'should_notify' => $this->shouldNotify + 'should_notify' => $this->shouldNotify, ]); return $this->entity->links()->save($link); @@ -91,7 +93,7 @@ public function build() private function buildUrl(Hexadecimal $uuid): string { - if (!$this->prefix) { + if (! $this->prefix) { return url($this->baseUrl, [$uuid]); } diff --git a/src/ShareableLinkServiceProvider.php b/src/ShareableLinkServiceProvider.php index 2b0c11c..a12b612 100644 --- a/src/ShareableLinkServiceProvider.php +++ b/src/ShareableLinkServiceProvider.php @@ -1,11 +1,13 @@ -publishes([ - __DIR__ . '/../config/shareable-model.php' => config_path('shareable-model.php'), - __DIR__ . '/../resources/views/password.blade.php' => resource_path('views/vendor/shareable-model'), + __DIR__.'/../config/shareable-model.php' => config_path('shareable-model.php'), + __DIR__.'/../resources/views/password.blade.php' => resource_path('views/vendor/shareable-model'), ]); - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } public function register(): void { - $this->mergeConfigFrom(__DIR__ . '/../config/shareable-model.php', 'shareable-model'); - $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); - $this->loadViewsFrom(__DIR__ . '/../resources/views', 'shareable-model'); + $this->mergeConfigFrom(__DIR__.'/../config/shareable-model.php', 'shareable-model'); + $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'shareable-model'); } } diff --git a/tests/Http/Controller/ShareableLinkPasswordControllerTest.php b/tests/Http/Controller/ShareableLinkPasswordControllerTest.php index b4a1098..27958cc 100644 --- a/tests/Http/Controller/ShareableLinkPasswordControllerTest.php +++ b/tests/Http/Controller/ShareableLinkPasswordControllerTest.php @@ -2,9 +2,9 @@ namespace Sassnowski\LaravelShareableModel\Tests\Http\Controller; -use Sassnowski\LaravelShareableModel\Tests\TestCase; -use Sassnowski\LaravelShareableModel\Tests\Models\Upload; use Sassnowski\LaravelShareableModel\Shareable\ShareableLink; +use Sassnowski\LaravelShareableModel\Tests\Models\Upload; +use Sassnowski\LaravelShareableModel\Tests\TestCase; class ShareableLinkPasswordControllerTest extends TestCase { diff --git a/tests/Http/Middleware/ValidateShareableLinkTest.php b/tests/Http/Middleware/ValidateShareableLinkTest.php index 87911cd..c1a8cb0 100644 --- a/tests/Http/Middleware/ValidateShareableLinkTest.php +++ b/tests/Http/Middleware/ValidateShareableLinkTest.php @@ -1,13 +1,15 @@ - Date: Tue, 11 Apr 2023 00:44:28 +0700 Subject: [PATCH 2/3] Add laravel/pint package --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 080b2ce..0a01c8f 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "require-dev": { "doctrine/dbal": "^3.5", "ergebnis/composer-normalize": "^2.29", + "laravel/pint": "^1.8", "mockery/mockery": "^1.4.4", "nunomaduro/larastan": "^2.5.1", "orchestra/testbench": "^8.0", From cf5714b4823578b48eb072918dad4ea3461f8628 Mon Sep 17 00:00:00 2001 From: Aslam Date: Tue, 11 Apr 2023 01:58:13 +0700 Subject: [PATCH 3/3] Feat - ignore migration --- src/BaseShareableLink.php | 25 ++++++++++++ src/ShareableLinkServiceProvider.php | 60 +++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 src/BaseShareableLink.php diff --git a/src/BaseShareableLink.php b/src/BaseShareableLink.php new file mode 100644 index 0000000..434600e --- /dev/null +++ b/src/BaseShareableLink.php @@ -0,0 +1,25 @@ +app->singleton('baseshareablelink', function () { + return new BaseShareableLink(); + }); + + $this->mergeConfigFrom(__DIR__.'/../config/shareable-model.php', 'shareable-model'); + $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'shareable-model'); + } + /** * Perform post-registration booting of services. */ public function boot(): void + { + $this->registerRouteModelBinding(); + $this->registerMigrations(); + $this->registerPublishing(); + } + + /** + * Register route binding resolution. + * + * @return void + */ + protected function registerRouteModelBinding() { Route::bind('shareable_link', function ($value) { try { @@ -24,19 +50,33 @@ public function boot(): void throw new ModelNotFoundException($e->getMessage()); } }); + } - $this->publishes([ - __DIR__.'/../config/shareable-model.php' => config_path('shareable-model.php'), - __DIR__.'/../resources/views/password.blade.php' => resource_path('views/vendor/shareable-model'), - ]); - - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + /** + * Register migration files. + * + * @return void + */ + protected function registerMigrations() + { + if ($this->app->runningInConsole() && BaseShareableLink::$runsMigrations) { + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + } } - public function register(): void + /** + * Register the package's publishable resources. + * + * @return void + */ + protected function registerPublishing() { - $this->mergeConfigFrom(__DIR__.'/../config/shareable-model.php', 'shareable-model'); - $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); - $this->loadViewsFrom(__DIR__.'/../resources/views', 'shareable-model'); + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../database/migrations' => database_path('migrations'), + __DIR__.'/../config/shareable-model.php' => config_path('shareable-model.php'), + __DIR__.'/../resources/views/password.blade.php' => resource_path('views/vendor/shareable-model'), + ]); + } } }