|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/phpviet/symfony-number-to-words |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright (c) PHP Viet |
|
6
|
|
|
* @license [MIT](https://opensource.org/licenses/MIT) |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPViet\Symfony\NumberToWords\DependencyInjection; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Config\FileLocator; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
14
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension as BaseExtension; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Vuong Minh <[email protected]> |
|
18
|
|
|
* @since 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Extension extends BaseExtension |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->prepareConfig($configs); |
|
28
|
|
|
$configuration = new Configuration(); |
|
29
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
31
|
|
|
$loader->load('services.yaml'); |
|
32
|
|
|
$definition = $container->getDefinition('n2w'); |
|
33
|
|
|
$definition->addArgument($config); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getAlias(): string |
|
40
|
|
|
{ |
|
41
|
|
|
return 'n2w'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Thiết lập cấu hình mặc định. |
|
46
|
|
|
* |
|
47
|
|
|
* @param $configs |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function prepareConfig(&$configs): void |
|
50
|
|
|
{ |
|
51
|
|
|
$defaultConfig = [ |
|
52
|
|
|
'defaults' => [ |
|
53
|
|
|
'dictionary' => 'standard', |
|
54
|
|
|
], |
|
55
|
|
|
'dictionaries' => [ |
|
56
|
|
|
'standard' => 'n2w_standard_dictionary', |
|
57
|
|
|
'south' => 'n2w_south_dictionary', |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
foreach ($configs as &$config) { |
|
62
|
|
|
$config = array_merge($defaultConfig, $config); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|