1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Phiremock. |
4
|
|
|
* |
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Server\Actions; |
20
|
|
|
|
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
|
23
|
|
|
class ActionLocator |
24
|
|
|
{ |
25
|
|
|
const LIST_EXPECTATIONS = 'listExpectations'; |
26
|
|
|
const ADD_EXPECTATION = 'addExpectation'; |
27
|
|
|
const CLEAR_EXPECTATIONS = 'clearExpectations'; |
28
|
|
|
const SET_SCENARIO_STATE = 'setScenarioState'; |
29
|
|
|
const CLEAR_SCENARIOS = 'clearScenarios'; |
30
|
|
|
const COUNT_REQUESTS = 'countRequests'; |
31
|
|
|
const LIST_REQUESTS = 'listRequests'; |
32
|
|
|
const RESET_REQUESTS_COUNT = 'resetRequestsCount'; |
33
|
|
|
const RESET = 'reset'; |
34
|
|
|
|
35
|
|
|
const MANAGE_REQUEST = 'manageRequest'; |
36
|
|
|
|
37
|
|
|
const ACTION_FACTORY_METHOD_MAP = [ |
38
|
|
|
self::LIST_EXPECTATIONS => 'createListExpectations', |
39
|
|
|
self::ADD_EXPECTATION => 'createAddExpectation', |
40
|
|
|
self::CLEAR_EXPECTATIONS => 'createClearExpectations', |
41
|
|
|
|
42
|
|
|
self::SET_SCENARIO_STATE => 'createSetScenarioState', |
43
|
|
|
self::CLEAR_SCENARIOS => 'createClearScenarios', |
44
|
|
|
|
45
|
|
|
self::COUNT_REQUESTS => 'createCountRequests', |
46
|
|
|
self::LIST_REQUESTS => 'createListRequests', |
47
|
|
|
self::RESET_REQUESTS_COUNT => 'createResetRequestsCount', |
48
|
|
|
|
49
|
|
|
self::RESET => 'createReset', |
50
|
|
|
|
51
|
|
|
self::MANAGE_REQUEST => 'createSearchRequest', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** @var ActionsFactory */ |
55
|
|
|
private $factory; |
56
|
|
|
|
57
|
|
|
public function __construct(ActionsFactory $factory) |
58
|
|
|
{ |
59
|
|
|
$this->factory = $factory; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function locate(string $actionIdentifier): ActionInterface |
63
|
|
|
{ |
64
|
|
|
if (\array_key_exists($actionIdentifier, self::ACTION_FACTORY_METHOD_MAP)) { |
65
|
|
|
return $this->factory->{self::ACTION_FACTORY_METHOD_MAP[$actionIdentifier]}(); |
66
|
|
|
} |
67
|
|
|
throw new InvalidArgumentException(sprintf('Trying to get action using %s. Which is not a valid action name.', var_export($actionIdentifier, true))); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|