PinyinServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 3 1
A register() 0 9 1
A boot() 0 6 2
1
<?php
2
/**
3
 * This file is part of the mucts/laravel-pinyin.
4
 *
5
 * This source file is subject to the MIT license that is bundled
6
 * with this source code in the file LICENSE.
7
 *
8
 * @version 1.0
9
 * @author herry<[email protected]>
10
 * @copyright © 2020 MuCTS.com All Rights Reserved.
11
 */
12
13
namespace MuCTS\Laravel\Pinyin\Providers;
14
15
16
use Illuminate\Contracts\Support\DeferrableProvider;
17
use Illuminate\Support\ServiceProvider;
18
use MuCTS\Laravel\Pinyin\Pinyin;
19
20
class PinyinServiceProvider extends ServiceProvider implements DeferrableProvider
21
{
22
    public function register()
23
    {
24
        $this->mergeConfigFrom(
25
            dirname(__DIR__) . '/../config/pinyin.php', 'pinyin'
26
        );
27
        $this->app->singleton(Pinyin::class, function ($app) {
28
            return new Pinyin($app->config['pinyin']);
29
        });
30
        $this->app->alias(Pinyin::class, 'pinyin');
31
    }
32
33
    public function boot()
34
    {
35
        if (!file_exists(config_path('pinyin.php'))) {
36
            $this->publishes([
37
                dirname(__DIR__) . '/../config/pinyin.php' => config_path('pinyin.php'),
38
            ], 'config');
39
        }
40
    }
41
42
    public function provides()
43
    {
44
        return [Pinyin::class, 'pinyin'];
45
    }
46
}