1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pgs\HashIdBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Hashids\Hashids; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
7
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
8
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
9
|
|
|
|
10
|
|
|
class Configuration implements ConfigurationInterface |
11
|
|
|
{ |
12
|
|
|
const ROOT_NAME = 'pgs_hash_id'; |
13
|
|
|
|
14
|
|
|
const NODE_CONVERTER = 'converter'; |
15
|
|
|
const NODE_CONVERTER_HASHIDS = 'hashids'; |
16
|
|
|
const NODE_CONVERTER_HASHIDS_SALT = 'salt'; |
17
|
|
|
const NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH = 'min_hash_length'; |
18
|
|
|
const NODE_CONVERTER_HASHIDS_ALPHABET = 'alphabet'; |
19
|
|
|
|
20
|
6 |
|
public function getConfigTreeBuilder(): TreeBuilder |
21
|
|
|
{ |
22
|
6 |
|
$treeBuilder = new TreeBuilder(self::ROOT_NAME); |
23
|
6 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
24
|
6 |
|
$rootNode = $treeBuilder->getRootNode(); |
25
|
|
|
} else { |
26
|
|
|
// BC layer for symfony/config 4.1 and older |
27
|
|
|
$rootNode = $treeBuilder->root(self::ROOT_NAME); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
$rootNode |
30
|
6 |
|
->children() |
31
|
6 |
|
->arrayNode(self::NODE_CONVERTER)->addDefaultsIfNotSet() |
32
|
6 |
|
->children() |
33
|
6 |
|
->append($this->addHashidsConverterNode()) |
34
|
6 |
|
->end() |
35
|
6 |
|
->end() |
36
|
6 |
|
->end(); |
37
|
|
|
|
38
|
6 |
|
return $treeBuilder; |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
private function addHashidsConverterNode(): ArrayNodeDefinition |
42
|
|
|
{ |
43
|
6 |
|
$node = new ArrayNodeDefinition(self::NODE_CONVERTER_HASHIDS); |
44
|
|
|
|
45
|
6 |
|
if (!class_exists(Hashids::class)) { |
46
|
|
|
return $node; |
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
return $node->addDefaultsIfNotSet() |
50
|
6 |
|
->children() |
51
|
6 |
|
->scalarNode(self::NODE_CONVERTER_HASHIDS_SALT) |
52
|
6 |
|
->defaultNull() |
53
|
6 |
|
->end() |
54
|
6 |
|
->scalarNode(self::NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH) |
|
|
|
|
55
|
6 |
|
->defaultValue(10) |
56
|
6 |
|
->end() |
57
|
6 |
|
->scalarNode(self::NODE_CONVERTER_HASHIDS_ALPHABET) |
58
|
6 |
|
->defaultValue('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') |
59
|
6 |
|
->end() |
60
|
6 |
|
->end(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.