From 6a3ad4350e0a1a22275844c5bac55787075bd03e Mon Sep 17 00:00:00 2001 From: "Ryan C. Durham" Date: Thu, 29 Jan 2015 17:58:23 +0000 Subject: [PATCH 1/5] Update illuminate/support requirement to 5.0.*@dev --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b0b6969..bf7fe42 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ ], "require": { "php": ">=5.3.0", - "illuminate/support": "4.x", + "illuminate/support": "5.0.*@dev", + "illuminate/contracts": "5.0.*@dev", "hashids/hashids": "1.0.x" }, "autoload": { From caa805a779e8299ece748dea28524fdb1363297c Mon Sep 17 00:00:00 2001 From: "Ryan C. Durham" Date: Thu, 29 Jan 2015 18:31:13 +0000 Subject: [PATCH 2/5] Update Service Provider for Laravel 5 --- src/Mitch/Hashids/HashidsServiceProvider.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mitch/Hashids/HashidsServiceProvider.php b/src/Mitch/Hashids/HashidsServiceProvider.php index 0e5adf8..ff08887 100644 --- a/src/Mitch/Hashids/HashidsServiceProvider.php +++ b/src/Mitch/Hashids/HashidsServiceProvider.php @@ -12,7 +12,9 @@ class HashidsServiceProvider extends ServiceProvider */ public function boot() { - $this->package('mitch/hashids'); + $this->publishes([ + __DIR__.'/../../config/config.php' => config_path('hashids.php'), + ]); } /** @@ -23,6 +25,8 @@ public function boot() public function register() { + $this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'hashids'); + $this->registerHashids(); } @@ -30,9 +34,9 @@ protected function registerHashids() { $this->app->bind('Hashids\Hashids', function ($app) { return new Hashids( - $app['config']['app.key'], - $app['config']['hashids::length'], - $app['config']['hashids::alphabet'] + config('app.key'), + config('hashids.length'), + config('hashids.alphabet') ); }); } From ffe81ef0397e6692ee3df8b63a88b991eb86782d Mon Sep 17 00:00:00 2001 From: "Ryan C. Durham" Date: Fri, 30 Jan 2015 05:03:51 +0000 Subject: [PATCH 3/5] Update Readme --- README.md | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index faa0dd5..fefd3b6 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,8 @@ Use hashids when you do not want to expose your database ids to the user. ## Installation Begin by installing the package through Composer. Edit your project's `composer.json` file to require `mitch/hashids`. - ```php - "require": { - "mitch/hashids": "1.x" - } - ``` - -Next use Composer to update your project from the the Terminal: - - ```php - php composer.phar update + ```bash + $ composer require mitch/hashids ``` Once the package has been installed you'll need to add the service provider. Open your `app/config/app.php` configuration file, and add a new item to the `providers` array. @@ -35,7 +27,7 @@ After doing this you also need to add an alias. In your `app/config/app.php` fil Now last but not least you need to publish to package configuration from your Terminal: ```php - php artisan config:publish mitch/hashids + php artisan vendor:publish ``` ## Usage From ab44a07de1f13073853d92d66f3ecc73334678ed Mon Sep 17 00:00:00 2001 From: "Ryan C. Durham" Date: Fri, 30 Jan 2015 05:05:07 +0000 Subject: [PATCH 4/5] Update Readme --- README.md | 110 +++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index fefd3b6..715a3d5 100644 --- a/README.md +++ b/README.md @@ -8,27 +8,27 @@ Use hashids when you do not want to expose your database ids to the user. ## Installation Begin by installing the package through Composer. Edit your project's `composer.json` file to require `mitch/hashids`. - ```bash - $ composer require mitch/hashids - ``` +```bash +$ composer require mitch/hashids +``` Once the package has been installed you'll need to add the service provider. Open your `app/config/app.php` configuration file, and add a new item to the `providers` array. - ```php - 'Mitch\Hashids\HashidsServiceProvider' - ``` +```php +'Mitch\Hashids\HashidsServiceProvider' +``` After doing this you also need to add an alias. In your `app/config/app.php` file, add this to the `aliases` array. - ```php - 'Hashids' => 'Mitch\Hashids\Hashids' - ``` +```php +'Hashids' => 'Mitch\Hashids\Hashids' +``` Now last but not least you need to publish to package configuration from your Terminal: - ```php - php artisan vendor:publish - ``` +```php +php artisan vendor:publish +``` ## Usage Once you've followed all the steps and completed the installation you can use Hashids. @@ -36,69 +36,69 @@ Once you've followed all the steps and completed the installation you can use Ha ### Encoding You can simply encrypt on id: - ```php - Hashids::encode(1); // Creating hash... Ri7Bi - ``` +```php +Hashids::encode(1); // Creating hash... Ri7Bi +``` or multiple.. - ```php - Hashids::encode(1, 21, 12, 12, 666); // Creating hash... MMtaUpSGhdA - ``` +```php +Hashids::encode(1, 21, 12, 12, 666); // Creating hash... MMtaUpSGhdA +``` ### Decoding It's the same thing but the other way around: - ```php - Hashids::decode('Ri7Bi'); +```php +Hashids::decode('Ri7Bi'); - // Returns - array (size=1) - 0 => int 1 - ``` +// Returns +array (size=1) + 0 => int 1 +``` or multiple.. - ```php - Hashids::decode('MMtaUpSGhdA'); - - // Returns - array (size=5) - 0 => int 1 - 1 => int 21 - 2 => int 12 - 3 => int 12 - 4 => int 666 - ``` +```php +Hashids::decode('MMtaUpSGhdA'); + +// Returns +array (size=5) + 0 => int 1 + 1 => int 21 + 2 => int 12 + 3 => int 12 + 4 => int 666 +``` ### Injecting Hashids Now it's also possible to have Hashids injected into your class. Lets look at this controller as an example.. - ```php - class ExampleController extends BaseController - { - protected $hashids; - - public function __construct(Hashids\Hashids $hashids) - { - $this->hashids = $hashids; - } - - public function getIndex() - { - $hash = $this->hashids->encode(1); - return View::make('example.index', compact('hash')); - } - } - ``` +```php +class ExampleController extends BaseController +{ + protected $hashids; + + public function __construct(Hashids\Hashids $hashids) + { + $this->hashids = $hashids; + } + + public function getIndex() + { + $hash = $this->hashids->encode(1); + return View::make('example.index', compact('hash')); + } +} +``` The original classname and namespace has been bound in the IoC container to return our instantiated Hashids class. ### Using IoC Create a Hashids instance with the IoC - ```php - App::make('Hashids\Hashids')->encode(1); - ``` +```php +App::make('Hashids\Hashids')->encode(1); +``` ## That's it! Documentation about [Hashids can be found here](https://github.com/ivanakimov/hashids.php). From 6e2d8b91f2e138807a9a659b23242ce6aac15dca Mon Sep 17 00:00:00 2001 From: Ryan Durham Date: Fri, 30 Jan 2015 19:08:27 -0800 Subject: [PATCH 5/5] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf7fe42..f3266c9 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-master": "2.x-dev" } } }