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 ServiceBase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor |
26
|
|
|
* |
27
|
|
|
* @param TransportInterface $serviceTransport |
28
|
|
|
* Service's transport |
29
|
|
|
*/ |
30
|
|
|
public function __construct(TransportInterface $serviceTransport) |
31
|
|
|
{ |
32
|
|
|
try { |
33
|
|
|
parent::__construct($serviceTransport); |
34
|
|
|
|
35
|
|
|
$this->initCommonRoutes(); |
36
|
|
|
} catch (\Exception $e) { |
37
|
|
|
$this->getTransport()->handleException($e); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Method inits common servoce's routes |
43
|
|
|
*/ |
44
|
|
|
protected function initCommonRoutes(): void |
45
|
|
|
{ |
46
|
|
|
// TODO create these methods in the Transport module, this is transport's responsibility |
47
|
|
|
// TODO in ServiceBaseLogic::__construct remove parameters $paramsFetcher and $securityProvider and make setters. It will allow us to avoid |
48
|
|
|
// code like this: |
49
|
|
|
// $serviceLogic = new Logic($serviceTransport->getParamsFetcher(), $serviceTransport->getSecurityProvider()); |
50
|
|
|
// $serviceTransport->setServiceLogic($serviceLogic); |
51
|
|
|
// and setup $paramsFetcher and $securityProvider in this call $serviceTransport->setServiceLogic($serviceLogic); |
52
|
|
|
// this will make our code more neat and short |
53
|
|
|
// TODO make Transport accept null instead of $securityProvider - in this way no security is provided for the implemented logic, this will |
54
|
|
|
// help us to make code shortener and avoid creating $securityProvider = new MockProvider(); wich does nothing |
55
|
|
|
$this->getTransport()->addRoute('/connect/', 'connect', 'POST', 'public_call'); |
56
|
|
|
$this->getTransport()->addRoute('/token/[a:token]/', 'setToken', 'POST'); |
57
|
|
|
$this->getTransport()->addRoute('/self/id/', 'getSelfId', 'GET'); |
58
|
|
|
$this->getTransport()->addRoute('/self/login/', 'getSelfLogin', 'GET'); |
59
|
|
|
$this->getTransport()->addRoute('/login-as/', 'loginAs', 'POST'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|