Completed
Push — master ( ad6921...16742d )
by Alex
07:56
created

Service.php (1 issue)

Labels
Severity
1
<?php
2
namespace Mezon\Service;
3
4
/**
5
 * Class Service
6
 *
7
 * @package Mezon
8
 * @subpackage Service
9
 * @author Dodonov A.A.
10
 * @version v.1.0 (2019/08/17)
11
 * @copyright Copyright (c) 2019, aeon.org
12
 */
13
14
/**
15
 * Service class
16
 *
17
 * It bounds together transport, request parameters fetcher, logic, authorization and model
18
 *
19
 * @author Dodonov A.A.
20
 */
21
class Service extends \Mezon\Service\ServiceBase
22
{
23
24
    /**
25
     * Constructor
26
     *
27
     * @param mixed $serviceLogic
28
     *            Service's logic
29
     * @param mixed $serviceModel
30
     *            Service's model
31
     * @param mixed $securityProvider
32
     *            Service's security provider
33
     * @param mixed $serviceTransport
34
     *            Service's transport
35
     */
36
    public function __construct(
37
        $serviceLogic = \Mezon\Service\ServiceLogic::class,
38
        $serviceModel = \Mezon\Service\ServiceModel::class,
39
        $securityProvider = \Mezon\Security\MockProvider::class,
40
        $serviceTransport = \Mezon\Service\ServiceRestTransport\ServiceRestTransport::class)
41
    {
42
        try {
43
            parent::__construct($serviceLogic, $serviceModel, $securityProvider, $serviceTransport);
44
45
            $this->initCommonRoutes();
46
        } catch (\Exception $e) {
47
            $this->getTransport()->handleException($e);
48
        }
49
    }
50
51
    /**
52
     * Method inits common servoce's routes
53
     */
54
    protected function initCommonRoutes(): void
55
    {
56
        $this->getTransport()->addRoute('/connect/', 'connect', 'POST', 'public_call');
57
        $this->getTransport()->addRoute('/token/[a:token]/', 'setToken', 'POST');
58
        $this->getTransport()->addRoute('/self/id/', 'getSelfId', 'GET');
59
        $this->getTransport()->addRoute('/self/login/', 'getSelfLogin', 'GET');
60
        $this->getTransport()->addRoute('/login-as/', 'loginAs', 'POST');
61
    }
62
63
    /**
64
     * Method launches service
65
     *
66
     * @param Service|string $service
67
     *            name of the service class or the service object itself
68
     * @param \Mezon\Service\ServiceLogic|string $serviceLogic
69
     *            Logic of the service
70
     * @param \Mezon\Service\ServiceModel|string $serviceModel
71
     *            Model of the service
72
     * @param \Mezon\Service\ServiceSecurityProviderInterface|string $securityProvider
0 ignored issues
show
The type Mezon\Service\ServiceSecurityProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
     *            name of the service security provider class or the service security provider itself
74
     * @param \Mezon\Service\Transport|string $serviceTransport
75
     *            name of the service transport class or the service transport itself
76
     * @param bool $runService
77
     *            Shold be service lanched
78
     * @return \Mezon\Service\Service Created service
79
     * @deprecated See Service::run
80
     */
81
    public static function launch(
82
        $service,
83
        $serviceLogic = \Mezon\Service\ServiceLogic::class,
84
        $serviceModel = \Mezon\Service\ServiceModel::class,
85
        $securityProvider = \Mezon\Security\MockProvider::class,
86
        $serviceTransport = \Mezon\Service\ServiceRestTransport\ServiceRestTransport::class,
87
        bool $runService = true): \Mezon\Service\ServiceBase
88
    {
89
        if (is_string($service)) {
90
            $service = new $service($serviceLogic, $serviceModel, $securityProvider, $serviceTransport);
91
        }
92
93
        if ($runService === false) {
94
            return $service;
95
        }
96
97
        $service->run();
98
99
        return $service;
100
    }
101
102
    /**
103
     * Method launches service
104
     *
105
     * @param Service|string $service
106
     *            name of the service class or the service object itself
107
     * @param \Mezon\Service\ServiceLogic|string $serviceLogic
108
     *            Logic of the service
109
     * @param \Mezon\Service\ServiceModel|string $serviceModel
110
     *            Model of the service
111
     * @param \Mezon\Service\ServiceSecurityProviderInterface|string $securityProvider
112
     *            name of the service security provider class or the service security provider itself
113
     * @param \Mezon\Service\Transport|string $serviceTransport
114
     *            name of the service transport class or the service transport itself
115
     * @param bool $runService
116
     *            Shold be service lanched
117
     * @return \Mezon\Service\Service Created service
118
     */
119
    public static function start(
120
        $service,
121
        $serviceLogic = \Mezon\Service\ServiceLogic::class,
122
        $serviceModel = \Mezon\Service\ServiceModel::class,
123
        $securityProvider = \Mezon\Security\MockProvider::class,
124
        $serviceTransport = \Mezon\Service\ServiceRestTransport\ServiceRestTransport::class,
125
        bool $runService = true): \Mezon\Service\ServiceBase
126
    {
127
        if (is_string($service)) {
128
            $service = new $service($serviceLogic, $serviceModel, $securityProvider, $serviceTransport);
129
        }
130
131
        if ($runService === false) {
132
            return $service;
133
        }
134
135
        $service->run();
136
137
        return $service;
138
    }
139
}
140