Skip to content

Commit 5f62621

Browse files
author
Daniel
committed
First commit
0 parents  commit 5f62621

File tree

10 files changed

+263
-0
lines changed

10 files changed

+263
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
7+
before_script:
8+
- curl -s http://getcomposer.org/installer | php
9+
- php composer.phar install --dev
10+
11+
script: phpunit

LICENCE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The BSD 2-Clause License
2+
Copyright (c) 2013, Daniel Stainback
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Hashids for Laravel 4.1
2+
3+
[![Latest Stable Version](https://poser.pugx.org/torann/hashids/v/stable.png)](https://packagist.org/packages/torann/hashids) [![Total Downloads](https://poser.pugx.org/torann/hashids/downloads.png)](https://packagist.org/packages/torann/hashids)
4+
5+
This package uses the classes created by [hashids.org](http://www.hashids.org/ "http://www.hashids.org/")
6+
7+
Generate hashes from numbers, like YouTube or Bitly. Use hashids when you do not want to expose your database ids to the user.
8+
9+
----------
10+
11+
## Installation
12+
13+
- [Hashids on Packagist](https://packagist.org/packages/torann/hashids)
14+
- [Hashids on GitHub](https://github.com/torann/laravel-hashids)
15+
16+
To get the latest version of Hashids simply require it in your `composer.json` file.
17+
18+
~~~
19+
"torann/hashids": "dev-master"
20+
~~~
21+
22+
You'll then need to run `composer install` to download it and have the autoloader updated.
23+
24+
Once Hashids is installed you need to register the service provider with the application. Open up `app/config/app.php` and find the `providers` key.
25+
26+
27+
```php
28+
'Torann\Hashids\HashidsServiceProvider'
29+
```
30+
31+
> There is no need to add the Facade, the package will add it for you.
32+
33+
34+
### Publish the config
35+
36+
Run this on the command line from the root of your project:
37+
38+
$ php artisan config:publish torann/hashids
39+
40+
This will publish Hashids' config to ``app/config/packages/torann/hashids/``.
41+
42+
## Usage
43+
44+
Once you've followed all the steps and completed the installation you can use Hashids.
45+
46+
### Encrypting
47+
48+
You can simply encrypt on id:
49+
50+
```php
51+
Hashids::encrypt(1); // Returns Ri7Bi
52+
```
53+
54+
or multiple..
55+
56+
```php
57+
Hashids::encrypt(1, 21, 12, 12, 666); // Returns MMtaUpSGhdA
58+
```
59+
60+
### Decrypting
61+
62+
```php
63+
Hashids::decrypt(Ri7Bi);
64+
65+
// Returns
66+
array (size=1)
67+
0 => int 1
68+
```
69+
70+
or multiple..
71+
72+
```php
73+
Hashids::decrypt(MMtaUpSGhdA);
74+
75+
// Returns
76+
array (size=5)
77+
0 => int 1
78+
1 => int 21
79+
2 => int 12
80+
3 => int 12
81+
4 => int 666
82+
```
83+
84+
All credit for Hashids goes to Ivan Akimov (@ivanakimov), thanks to for making it!

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "torann/hashids",
3+
"description": "Laravel 4.1 package for Hashids",
4+
"keywords": ["laravel", "promise", "roles", "permissions", "group", "user"],
5+
"license": "BSD 2-Clause",
6+
"authors": [
7+
{
8+
"name": "Daniel Stainback",
9+
"email": "daniel@lyften.com"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.3.0",
14+
"illuminate/support": "4.1.x",
15+
"hashids/hashids": "*"
16+
},
17+
"autoload": {
18+
"psr-0": {
19+
"Torann\\Hashids": "src/"
20+
}
21+
},
22+
"extra": {
23+
"branch-alias": {
24+
"dev-master": "0.3-dev"
25+
}
26+
},
27+
"minimum-stability": "dev"
28+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/Torann/Hashids/Facade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php namespace Torann\Hashids;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
class Facade extends Facade {
6+
7+
/**
8+
* Get the registered component.
9+
*
10+
* @return object
11+
*/
12+
protected static function getFacadeAccessor() { return 'hashids'; }
13+
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php namespace Torann\Hashids;
2+
3+
use Hashids\Hashids;
4+
use Illuminate\Support\ServiceProvider;
5+
6+
class HashidsServiceProvider extends ServiceProvider {
7+
8+
/**
9+
* Bootstrap the application events.
10+
*
11+
* @return void
12+
*/
13+
public function boot()
14+
{
15+
// Register the package namespace
16+
$this->package('torann/hashids');
17+
18+
// Add 'Assets' facade alias
19+
AliasLoader::getInstance()->alias('Hashids', 'Torann\Hashids\Facade');
20+
}
21+
22+
/**
23+
* Register the service provider.
24+
*
25+
* @return void
26+
*/
27+
public function register()
28+
{
29+
// Bind 'hashids' shared component to the IoC container
30+
$this->app->singleton('hashids', function($app)
31+
{
32+
// Read settings from config file
33+
$config = $app->config->get('hashids::config', array());
34+
35+
return new Hashids($config['salt'], $config['length'], $config['alphabet']);
36+
});
37+
}
38+
39+
/**
40+
* Get the services provided by the provider.
41+
*
42+
* @return array
43+
*/
44+
public function provides()
45+
{
46+
return array();
47+
}
48+
49+
}

src/config/config.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
return array(
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Custom Salt
8+
|--------------------------------------------------------------------------
9+
|
10+
| Hashids supports personalizing your hashes by accepting a salt value.
11+
| If you don't want others to decrypt your hashes, provide a unique
12+
| string used for salting.
13+
|
14+
*/
15+
16+
'salt' => null,
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Hash Length
21+
|--------------------------------------------------------------------------
22+
|
23+
| By default, hashes are going to be the shortest possible. You can also
24+
| set the minimum hash length to obfuscate how large the number behind
25+
| the hash is.
26+
|
27+
*/
28+
29+
'length' => 0,
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Custom alphabet
34+
|--------------------------------------------------------------------------
35+
|
36+
| The default alphabet contains all lowercase and uppercase letters
37+
| and numbers. f you'd like to make it longer, you can add more
38+
| characters like - @ $ % ^ & * ( ) [ ] { }
39+
|
40+
*/
41+
42+
'alphabet' => null,
43+
44+
);

tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)