|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Helpers\JobRunner; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication; |
|
6
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer; |
|
7
|
|
|
use eXpansion\Framework\Core\Helpers\Structures\HttpRequest; |
|
8
|
|
|
use eXpansion\Framework\Core\Helpers\Structures\HttpResult; |
|
9
|
|
|
use oliverde8\AsynchronousJobs\Job; |
|
10
|
|
|
use oliverde8\AsynchronousJobs\Job\CallbackCurl; |
|
11
|
|
|
use oliverde8\AsynchronousJobs\JobRunner; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Factory |
|
16
|
|
|
* |
|
17
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
18
|
|
|
* @copyright 2017 Smile |
|
19
|
|
|
* @package Tests\eXpansion\Framework\Core\Helpers\JobRunner |
|
20
|
|
|
*/ |
|
21
|
|
|
class Factory implements ListenerInterfaceExpTimer |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @return JobRunner |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function getJobRunner() |
|
27
|
|
|
{ |
|
28
|
2 |
|
return JobRunner::getInstance('expansion', PHP_BINARY, 'var/tmp/asynchronous'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param $url |
|
33
|
|
|
* @param $callback |
|
34
|
|
|
* @param null|mixed $additionalData |
|
35
|
|
|
* @param array $options |
|
36
|
|
|
* |
|
37
|
|
|
* @param array|\stdClass $parameters one dimensional array or \stdClass with post key-value pairs |
|
38
|
|
|
* @return CallbackCurl |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function createCurlJob($url, $callback, $additionalData = null, $options = [], $parameters = []) |
|
41
|
|
|
{ |
|
42
|
1 |
|
$curlJob = new HttpRequest(); |
|
43
|
1 |
|
$curlJob->setCallback($callback); |
|
44
|
1 |
|
$curlJob->setUrl($url); |
|
45
|
1 |
|
$curlJob->setOptions($options); |
|
46
|
1 |
|
$curlJob->setParameters($parameters); |
|
|
|
|
|
|
47
|
1 |
|
$curlJob->setAdditionalData($additionalData); |
|
48
|
|
|
|
|
49
|
1 |
|
return $curlJob; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param Job $job |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function startJob(Job $job) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$job->start(); |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function onPreLoop() |
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function onPostLoop() |
|
67
|
|
|
{ |
|
68
|
1 |
|
$this->getJobRunner()->proccess(); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function onEverySecond() |
|
72
|
|
|
{ |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.