Skip to content

Commit

Permalink
Improved service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Jan 30, 2016
1 parent 5cc509f commit 57acec1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.2.2 (released 2016-01-30)

- Improved service provider

## 2.2.1 (released 2016-01-17)

- Lumen 5.2 support
Expand Down
32 changes: 13 additions & 19 deletions src/HashidsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Vinkla\Hashids;

use Hashids\Hashids;
use Illuminate\Contracts\Container\Container as Application;
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;
Expand Down Expand Up @@ -59,62 +59,56 @@ protected function setupConfig()
*/
public function register()
{
$this->registerFactory($this->app);
$this->registerManager($this->app);
$this->registerBindings($this->app);
$this->registerFactory();
$this->registerManager();
$this->registerBindings();
}

/**
* Register the factory class.
*
* @param \Illuminate\Contracts\Container\Container $app
*
* @return void
*/
protected function registerFactory(Application $app)
protected function registerFactory()
{
$app->singleton('hashids.factory', function () {
$this->app->singleton('hashids.factory', function () {
return new HashidsFactory();
});

$app->alias('hashids.factory', HashidsFactory::class);
$this->app->alias('hashids.factory', HashidsFactory::class);
}

/**
* Register the manager class.
*
* @param \Illuminate\Contracts\Container\Container $app
*
* @return void
*/
protected function registerManager(Application $app)
protected function registerManager()
{
$app->singleton('hashids', function ($app) {
$this->app->singleton('hashids', function (Container $app) {
$config = $app['config'];
$factory = $app['hashids.factory'];

return new HashidsManager($config, $factory);
});

$app->alias('hashids', HashidsManager::class);
$this->app->alias('hashids', HashidsManager::class);
}

/**
* Register the bindings.
*
* @param \Illuminate\Contracts\Container\Container $app
*
* @return void
*/
protected function registerBindings(Application $app)
protected function registerBindings()
{
$app->bind('hashids.connection', function ($app) {
$this->app->bind('hashids.connection', function (Container $app) {
$manager = $app['hashids'];

return $manager->connection();
});

$app->alias('hashids.connection', Hashids::class);
$this->app->alias('hashids.connection', Hashids::class);
}

/**
Expand Down

0 comments on commit 57acec1

Please sign in to comment.