1
|
|
|
<?php |
2
|
|
|
namespace HDNET\Importr\Service\Targets; |
3
|
|
|
|
4
|
|
|
use HDNET\Importr\Domain\Model\Strategy; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Description of ExtbaseModel |
8
|
|
|
* |
9
|
|
|
* @author tim |
10
|
|
|
*/ |
11
|
|
|
class Dummy extends AbstractTarget implements TargetInterface |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
protected $possibleResults = [ |
15
|
|
|
TargetInterface::RESULT_IGNORED, |
16
|
|
|
TargetInterface::RESULT_INSERT, |
17
|
|
|
TargetInterface::RESULT_ERROR, |
18
|
|
|
TargetInterface::RESULT_UNSURE, |
19
|
|
|
TargetInterface::RESULT_UPDATE, |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function getConfiguration() |
26
|
|
|
{ |
27
|
|
|
$configuration = parent::getConfiguration(); |
28
|
|
|
$configuration['sleepSeconds'] = (isset($configuration['sleepSeconds'])) ? (int)$configuration['sleepSeconds'] : 1; |
29
|
|
|
$configuration['result'] = (isset($configuration['result'])) ? (int)$configuration['result'] : 'unsure'; |
30
|
|
|
return $configuration; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Strategy $strategy |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function start(Strategy $strategy) |
39
|
|
|
{ |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param array $entry |
44
|
|
|
* |
45
|
|
|
* @throws \Exception |
46
|
|
|
* @return int|void |
47
|
|
|
*/ |
48
|
|
|
public function processEntry(array $entry) |
49
|
|
|
{ |
50
|
|
|
$configuration = $this->getConfiguration(); |
51
|
|
|
if ($configuration['sleepSeconds'] > 0) { |
52
|
|
|
sleep($configuration['sleepSeconds']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($configuration['result'] == 'random') { |
56
|
|
|
$configuration['result'] = $this->possibleResults[rand(0, sizeof($this->possibleResults) - 1)]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!in_array($configuration['result'], $this->possibleResults)) { |
60
|
|
|
throw new \Exception( |
61
|
|
|
'Invalid result param "' . $configuration['result'] . '". Have to be one of: ' . var_export( |
62
|
|
|
$results, |
63
|
|
|
true |
64
|
|
|
), |
65
|
|
|
12617283 |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $configuration['result']; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function end() |
73
|
|
|
{ |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|