From 89ca1dbce3267cbb02b6dde111db752975f96dcc Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Thu, 3 Oct 2019 01:16:54 +0100 Subject: [PATCH] Updating the package * Allow to install laravel 6 minor releases * Updating the service provider * Cleaning/Refactoring --- README.md | 4 ++-- composer.json | 10 ++++---- helpers.php | 2 +- src/HashManager.php | 36 +++++++++++++---------------- src/HasherServiceProvider.php | 24 ++++++------------- tests/HasherServiceProviderTest.php | 5 ++-- 6 files changed, 34 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 025a9f3..75ce5a9 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/Hasher/releas * Flexible hash manager. * Well documented & IDE Friendly. * Well tested with maximum code quality. - * Laravel `5.0` to `6.0` are supported. + * Laravel `5.x | 6.x` are supported. * Made with :heart: & :coffee:. ## Table of contents @@ -49,7 +49,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail. - [All Contributors][link-contributors] [badge_license]: https://img.shields.io/packagist/l/arcanedev/hasher.svg?style=flat-square -[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.0%20to%206.0-orange.svg?style=flat-square +[badge_laravel]: https://img.shields.io/badge/For%20Laravel-5.x%20|%206.x-orange.svg?style=flat-square [badge_build]: https://img.shields.io/travis/ARCANEDEV/Hasher.svg?style=flat-square [badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/Hasher.svg?style=flat-square diff --git a/composer.json b/composer.json index 0f5872f..150be62 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,13 @@ "license": "MIT", "require": { "php": ">=7.2.0", - "arcanedev/support": "~5.0.0", - "hashids/hashids": "~4.0" + "arcanedev/support": "^5.0", + "hashids/hashids": "^4.0" }, "require-dev": { - "orchestra/testbench": "~4.0.0", - "phpunit/phpunit": "~8.0", - "phpunit/phpcov": "~6.0" + "orchestra/testbench": "^4.0.0", + "phpunit/phpunit": "^8.0", + "phpunit/phpcov": "^6.0" }, "autoload": { "psr-4": { diff --git a/helpers.php b/helpers.php index 7902bf4..2f84ab9 100644 --- a/helpers.php +++ b/helpers.php @@ -8,7 +8,7 @@ * * @return \Arcanedev\Hasher\Contracts\HashManager */ - function hasher() { + function hasher(): HashManager { return app(HashManager::class); } } diff --git a/src/HashManager.php b/src/HashManager.php index 93e06f2..821a34e 100644 --- a/src/HashManager.php +++ b/src/HashManager.php @@ -1,7 +1,7 @@ buildDrivers(); } @@ -53,7 +53,7 @@ public function __construct($app) */ public function getDefaultDriver() { - return $this->getHasherConfig('default.driver'); + return $this->config('default.driver'); } /** @@ -63,7 +63,7 @@ public function getDefaultDriver() */ public function getDefaultOption() { - return $this->option ?? $this->getHasherConfig('default.option', 'main'); + return $this->option ?? $this->config('default.option', 'main'); } /** @@ -75,7 +75,7 @@ public function getDefaultOption() */ public function option($option = null) { - if ( ! is_null($option)) { + if ($this->option !== $option) { $this->option = $option; $this->buildDrivers(); } @@ -116,11 +116,9 @@ public function driver($driver = null) /** * Build all hash drivers. */ - private function buildDrivers() + private function buildDrivers(): void { - $drivers = $this->getHasherConfig('drivers', []); - - foreach ($drivers as $name => $driver) { + foreach ($this->config('drivers', []) as $name => $driver) { $this->buildDriver($name, $driver); } } @@ -129,15 +127,13 @@ private function buildDrivers() * Build the driver. * * @param string $name - * @param array $driver - * - * @return \Arcanedev\Hasher\Contracts\HashDriver + * @param array $params */ - private function buildDriver($name, array $driver) + private function buildDriver(string $name, array $params): void { - return $this->drivers[$name] = new $driver['driver']( - Arr::get($driver, 'options.'.$this->getDefaultOption(), []) - ); + $this->drivers[$name] = $this->container->make($params['driver'], [ + 'options' => $params['options'][$this->getDefaultOption()] ?? [], + ]); } /** @@ -177,8 +173,8 @@ public function decode($hashed) * * @return mixed */ - protected function getHasherConfig($name, $default = null) + protected function config(string $name, $default = null) { - return $this->app->make('config')->get("hasher.$name", $default); + return $this->config->get("hasher.$name", $default); } } diff --git a/src/HasherServiceProvider.php b/src/HasherServiceProvider.php index 9fce75c..0050743 100644 --- a/src/HasherServiceProvider.php +++ b/src/HasherServiceProvider.php @@ -1,6 +1,7 @@ */ -class HasherServiceProvider extends ServiceProvider +class HasherServiceProvider extends ServiceProvider implements DeferrableProvider { /* ----------------------------------------------------------------- | Properties @@ -22,13 +23,6 @@ class HasherServiceProvider extends ServiceProvider */ protected $package = 'hasher'; - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = true; - /* ----------------------------------------------------------------- | Main Methods | ----------------------------------------------------------------- @@ -37,25 +31,21 @@ class HasherServiceProvider extends ServiceProvider /** * Register the service provider. */ - public function register() + public function register(): void { parent::register(); $this->registerConfig(); // Services - $this->singleton(Contracts\HashManager::class, function ($app) { - return new HashManager($app); - }); + $this->singleton(Contracts\HashManager::class, HashManager::class); } /** * Boot the service provider. */ - public function boot() + public function boot(): void { - parent::boot(); - $this->publishConfig(); } @@ -64,7 +54,7 @@ public function boot() * * @return array */ - public function provides() + public function provides(): array { return [ Contracts\HashManager::class, diff --git a/tests/HasherServiceProviderTest.php b/tests/HasherServiceProviderTest.php index b1ce88b..1d26dad 100644 --- a/tests/HasherServiceProviderTest.php +++ b/tests/HasherServiceProviderTest.php @@ -47,8 +47,9 @@ public function it_can_be_instantiated() { $expectations = [ \Illuminate\Support\ServiceProvider::class, - \Arcanedev\Support\ServiceProvider::class, - \Arcanedev\Support\PackageServiceProvider::class, + \Illuminate\Contracts\Support\DeferrableProvider::class, + \Arcanedev\Support\Providers\ServiceProvider::class, + \Arcanedev\Support\Providers\PackageServiceProvider::class, \Arcanedev\Hasher\HasherServiceProvider::class, ];