Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roukmoute authored and Mathias Strasser committed Jun 14, 2016
0 parents commit e3d2b34
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Mathias STRASSER

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# HashidsBundle

Integrates [hashids/hashids][1] in a Symfony2 project.
## Installation

Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:

```
composer require roukmoute/hashids-bundle
```

This command requires you to have Composer installed globally.

## Enable the Bundle

Then, enable the bundle by adding the following line in the ``app/AppKernel.php``
file of your project:

```php
<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// …
new Roukmoute\HashidsBundle\RoukmouteHashidsBundle()
);
// …
```

The configuration looks as follows :

```yaml
roukmoute_hashids:

# if set, the hashids will differ from everyone else's
salt: ""

# if set, will generate minimum length for the id
# 0 — meaning hashes will be the shortest possible length
min_hash_length: 0

# if set, will use only characters of alphabet string
alphabet: ""
```
## Usage
```php
$hashids = $this->get('hashids');
```

Next it's the same things of [official documentation][2]

[1]: https://github.com/ivanakimov/hashids.php
[2]: http://hashids.org/php/
15 changes: 15 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="hashids"
class="Hashids\Hashids"
>
<argument>%hashids.salt%</argument>
<argument>%hashids.min_hash_length%</argument>
<argument>%hashids.alphabet%</argument>
</service>
</services>
</container>
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "roukmoute/hashids-bundle",
"type": "symfony-bundle",
"description": "Integrates hashids/hashids in a Symfony project",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
"name": "Mathias STRASSER",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Roukmoute\\HashidsBundle\\": "/src"
}
},
"require": {
"hashids/hashids": "^1.0"
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
}
}
33 changes: 33 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Roukmoute\HashidsBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('roukmoute_hashids');

$rootNode
->children()
->scalarNode('salt')
->defaultValue('')
->info('if set, the hashids will differ from everyone else\'s')
->end()
->integerNode('min_hash_length')
->info('if set, will generate minimum length for the id')
->defaultValue(0)
->min(0)
->end()
->scalarNode('alphabet')
->info('if set, will use only characters of alphabet string')
->defaultValue('')
->end()
->end();

return $treeBuilder;
}
}
23 changes: 23 additions & 0 deletions src/DependencyInjection/RoukmouteHashidsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Roukmoute\HashidsBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class RoukmouteHashidsExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('services.xml');

$container->setParameter('hashids.salt', $config['salt']);
$container->setParameter('hashids.min_hash_length', $config['min_hash_length']);
$container->setParameter('hashids.alphabet', $config['alphabet']);
}
}
8 changes: 8 additions & 0 deletions src/RoukmouteHashidsBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Roukmoute\HashidsBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class RoukmouteHashidsBundle extends Bundle
{
}

0 comments on commit e3d2b34

Please sign in to comment.