Skip to content

Commit

Permalink
Merge pull request #16 from ARCANEDEV/update-package
Browse files Browse the repository at this point in the history
Updating the package
  • Loading branch information
arcanedev-maroc committed Oct 3, 2019
2 parents 8e49a6d + 89ca1db commit b636f50
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 47 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @return \Arcanedev\Hasher\Contracts\HashManager
*/
function hasher() {
function hasher(): HashManager {
return app(HashManager::class);
}
}
36 changes: 16 additions & 20 deletions src/HashManager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace Arcanedev\Hasher;

use Arcanedev\Hasher\Contracts\HashManager as HashManagerContract;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Manager;

/**
Expand Down Expand Up @@ -32,11 +32,11 @@ class HashManager extends Manager implements HashManagerContract
/**
* HashManager constructor.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Contracts\Container\Container $container
*/
public function __construct($app)
public function __construct(Container $container)
{
parent::__construct($app);
parent::__construct($container);

$this->buildDrivers();
}
Expand All @@ -53,7 +53,7 @@ public function __construct($app)
*/
public function getDefaultDriver()
{
return $this->getHasherConfig('default.driver');
return $this->config('default.driver');
}

/**
Expand All @@ -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');
}

/**
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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()] ?? [],
]);
}

/**
Expand Down Expand Up @@ -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);
}
}
24 changes: 7 additions & 17 deletions src/HasherServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php namespace Arcanedev\Hasher;

use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
use Arcanedev\Support\Providers\PackageServiceProvider as ServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;

/**
* Class HasherServiceProvider
*
* @package Arcanedev\Hasher
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class HasherServiceProvider extends ServiceProvider
class HasherServiceProvider extends ServiceProvider implements DeferrableProvider
{
/* -----------------------------------------------------------------
| Properties
Expand All @@ -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
| -----------------------------------------------------------------
Expand All @@ -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();
}

Expand All @@ -64,7 +54,7 @@ public function boot()
*
* @return array
*/
public function provides()
public function provides(): array
{
return [
Contracts\HashManager::class,
Expand Down
5 changes: 3 additions & 2 deletions tests/HasherServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down

0 comments on commit b636f50

Please sign in to comment.