Skip to content

Commit

Permalink
Changed namespace for better readability and easier use
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellvanw committed Apr 27, 2013
1 parent 0a413a1 commit 4e3fde3
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mitch/Hashids/Exceptions/UndefinedSaltException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php namespace Mitch\Hashids\Exceptions;

use Exception;

class UndefinedSaltException extends Exception {}
14 changes: 14 additions & 0 deletions src/Mitch/Hashids/Facades/Hashids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Mitch\Hashids\Facades;

use Illuminate\Support\Facades\Facade;

class Hashids extends Facade {

/**
* Get the registered component.
*
* @return object
*/
protected static function getFacadeAccessor(){ return 'hashids'; }

}
101 changes: 101 additions & 0 deletions src/Mitch/Hashids/HashidsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php namespace Mitch\Hashids;

use Hashids\Hashids;
use Mitch\Hashids\Exceptions\UndefinedSaltException;
use Illuminate\Support\ServiceProvider;

class HashidsServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('mitch/hashids');
}

/**
* Register the service provider.
*
* @return void
*/

public function register()
{
$this->registerHashidsSalt();

$this->registerHashidsLength();

$this->registerHashids();
}

protected function registerHashidsSalt()
{
$this->app->bind('hashids.salt', function()
{
return $this->getSalt();
});
}

protected function registerHashidsLength()
{
$this->app->bind('hashids.length', function()
{
return $this->getLength();
});
}

protected function registerHashids()
{
$this->app['hashids'] = $this->app->share(function($app)
{
return new Hashids($app->make('hashids.salt'), $app->make('hashids.length'));
});
}

/**
* Get the length used for encrypting and decrypting hashes.
*
* @return string
*/
protected function getSalt()
{
$salt = $this->app['config']['hashids::salt'];

if (! $salt) {
throw new UndefinedSaltException('No salt has been set in the configuration.');
}

return $salt;
}

/**
* Get the length used for the length of the hash.
*
* @return string
*/
protected function getLength()
{
return $this->app['config']['hashids::length'];
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('hashids');
}

}

0 comments on commit 4e3fde3

Please sign in to comment.