Skip to content

Commit 60ab19b

Browse files
committed
initial commit
0 parents  commit 60ab19b

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

DependencyInjection/Configuration.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace cayetanosoriano\HashidsBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('cayetanosoriano_hashids');
22+
$rootNode
23+
->children()
24+
->scalarNode('salt')->defaultNull()->end()
25+
->scalarNode('min_hash_length')->defaultValue(0)->end()
26+
->scalarNode('alphabet')->defaultValue('')->end()
27+
;
28+
return $treeBuilder;
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace cayetanosoriano\HashidsBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
10+
/**
11+
* This is the class that loads and manages your bundle configuration
12+
*
13+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14+
*/
15+
class cayetanosorianoHashidsExtension extends Extension
16+
{
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$configuration = new Configuration();
23+
$config = $this->processConfiguration($configuration, $configs);
24+
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.yml');
27+
$container->setParameter('cayetanosoriano_hashids.salt', $config['salt']);
28+
$container->setParameter('cayetanosoriano_hashids.min_hash_length', $config['min_hash_length']);
29+
$container->setParameter('cayetanosoriano_hashids.alphabet', $config['alphabet']);
30+
31+
32+
}
33+
}

Resources/config/services.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
Hashids.class: Hashids\Hashids
3+
4+
services:
5+
hashids:
6+
class: "%Hashids.class%"
7+
arguments: ["%cayetanosoriano_hashids.salt%", "%cayetanosoriano_hashids.min_hash_length%", "%cayetanosoriano_hashids.alphabet%"]

cayetanosorianoHashidsBundle.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace cayetanosoriano\HashidsBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class cayetanosorianoHashidsBundle extends Bundle
8+
{
9+
}

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "neoshadybeat/hashids-bundle",
3+
"description": "Bundle for integration of hashids lib to the container",
4+
"keywords": ["hashids"],
5+
"type": "symfony-bundle",
6+
"require": {
7+
"hashids/hashids": "0.3",
8+
"symfony/symfony": ">= 2.0.0",
9+
},
10+
"authors": [
11+
{
12+
"name": "Cayetano Soriano",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"minimum-stability": "dev"
17+
}

0 commit comments

Comments
 (0)