Bootstrap   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 6 1
A registerComponent() 0 6 2
A registerSingletonClasses() 0 10 1
1
<?php
2
/**
3
 * @link https://github.com/phpviet/yii-number-to-words
4
 *
5
 * @copyright (c) PHP Viet
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace phpviet\yii\numberToWords;
10
11
use yii\base\Application;
12
use yii\base\BootstrapInterface;
13
use PHPViet\NumberToWords\Dictionary;
14
use PHPViet\NumberToWords\SouthDictionary;
15
use PHPViet\NumberToWords\DictionaryInterface;
16
17
/**
18
 * @author Vuong Minh <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Bootstrap implements BootstrapInterface
22
{
23
    /**
24
     * Đối tượng application đang cần boot.
25
     *
26
     * @var Application
27
     */
28
    protected $app;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function bootstrap($app): void
34
    {
35
        $this->app = $app;
36
        $this->registerComponent();
37
        $this->registerSingletonClasses();
38
    }
39
40
    /**
41
     * Đăng ký component vào app.
42
     */
43
    protected function registerComponent(): void
44
    {
45
        if (! $this->app->get('n2w', false)) {
46
            $this->app->set('n2w', ['class' => N2W::class]);
47
        }
48
    }
49
50
    /**
51
     * Đăng ký các singleton classes vào container tối ưu việc khởi tạo đối tượng mới khi thay đổi từ điển.
52
     */
53
    protected function registerSingletonClasses(): void
54
    {
55
        $this->app->setContainer([
56
            'singletons' => [
57
                Dictionary::class => Dictionary::class,
58
                DictionaryInterface::class => Dictionary::class,
59
                SouthDictionary::class => SouthDictionary::class,
60
            ],
61
        ]);
62
    }
63
}
64