Passed
Push — develop ( 31ebc6...f6a1e0 )
by Nikolay
04:27
created

MarketPlaceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
c 0
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 2
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 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 MikoPBX\Core\System\Util;
25
use MikoPBX\Service\License;
26
use Phalcon\Di\DiInterface;
27
use Phalcon\Di\ServiceProviderInterface;
28
use SimpleXMLElement;
29
use Throwable;
30
31
/**
32
 * The LicenseProvider class is responsible for registering the license service.
33
 *
34
 * @package MikoPBX\Common\Providers
35
 *
36
 * @method  bool checkModules()
37
 * @method  bool checkPBX()
38
 * @method  SimpleXMLElement|string getLicenseInfo(string $key)
39
 * @method  bool | string getTrialLicense(array $params)
40
 * @method  bool | string addTrial(string $productId)
41
 * @method  bool | string activateCoupon(string $coupon)
42
 * @method  void changeLicenseKey(string $newKey)
43
 * @method  void sendLicenseMetrics(string $key, array $params)
44
 * @method  array captureFeature(string $featureId)
45
 * @method  array featureAvailable(string $featureId)
46
 * @method  array releaseFeature(string $featureId)
47
 * @method  string translateLicenseErrorMessage(string $message)
48
 * @method  array ping()
49
 *
50
 * @package MikoPBX\Common\Providers
51
 */
52
class MarketPlaceProvider implements ServiceProviderInterface
53
{
54
    public const SERVICE_NAME = 'license';
55
56
    /**
57
     * Register license service provider
58
     *
59
     * @param DiInterface $di The DI container.
60
     */
61
    public function register(DiInterface $di): void
62
    {
63
        $di->setShared(
64
            self::SERVICE_NAME,
65
            function () {
66
                try {
67
                    return new License('http://127.0.0.1:8223');
68
                } catch (Throwable $e){
69
                    Util::sysLogMsg(__CLASS__, $e->getMessage());
70
                }
71
                return null;
72
            }
73
        );
74
    }
75
}