forked from mitchellvanw/hashids
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed namespace for better readability and easier use
- Loading branch information
1 parent
0a413a1
commit 4e3fde3
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |