Completed
Push — master ( 220ce5...be682d )
by
unknown
17s
created

Factory::onPreLoop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
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
        if (is_object($parameters)) {
47
            $parameters = (array)$parameters;
48
        }
49 1
        $curlJob->setParameters($parameters);
50 1
        $curlJob->setAdditionalData($additionalData);
51
52 1
        return $curlJob;
53
    }
54
55
    /**
56
     * @param Job $job
57
     */
58 1
    public function startJob(Job $job)
59
    {
60 1
        $job->start();
61 1
    }
62
63
64
    public function onPreLoop()
65
    {
66
67
    }
68
69 1
    public function onPostLoop()
70
    {
71 1
        $this->getJobRunner()->proccess();
72 1
    }
73
74
    public function onEverySecond()
75
    {
76
77
    }
78
}
79