Passed
Push — develop ( 6fe1b7...4c812d )
by Nikolay
05:04
created

recreateAnnotationsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
declare(strict_types=1);
21
22
namespace MikoPBX\Common\Providers;
23
24
use Phalcon\Annotations\Adapter\Memory;
25
26
use Phalcon\Di;
27
use Phalcon\Di\DiInterface;
28
use Phalcon\Di\ServiceProviderInterface;
29
30
/**
31
 * Main database connection is created based in the parameters defined in the configuration file
32
 */
33
class ModelsAnnotationsProvider implements ServiceProviderInterface
34
{
35
    public const SERVICE_NAME = 'annotations';
36
37
    /**
38
     * Register Models metadata service provider
39
     *
40
     * @param \Phalcon\Di\DiInterface $di
41
     */
42
    public function register(DiInterface $di): void
43
    {
44
        $di->setShared(
45
            self::SERVICE_NAME,
46
            function (){
47
                return new Memory();
48
            }
49
        );
50
    }
51
52
    /**
53
     * Recreates modules service after enable or disable them
54
     */
55
    public static function recreateAnnotationsProvider(): void
56
    {
57
        $di = Di::getDefault();
58
        $di->remove(self::SERVICE_NAME);
59
        $di->register(new self());
60
    }
61
}