|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Async sockets |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace AsyncSockets\RequestExecutor; |
|
12
|
|
|
|
|
13
|
|
|
use AsyncSockets\Configuration\Configuration; |
|
14
|
|
|
use AsyncSockets\RequestExecutor\Pipeline\EventCaller; |
|
15
|
|
|
use AsyncSockets\RequestExecutor\Pipeline\Pipeline; |
|
16
|
|
|
use AsyncSockets\RequestExecutor\Pipeline\PipelineFactory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class RequestExecutor |
|
20
|
|
|
*/ |
|
21
|
|
|
class NativeRequestExecutor extends AbstractRequestExecutor |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Pipeline |
|
25
|
|
|
* |
|
26
|
|
|
* @var Pipeline |
|
27
|
|
|
*/ |
|
28
|
|
|
private $pipeline; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* PipelineFactory |
|
32
|
|
|
* |
|
33
|
|
|
* @var PipelineFactory |
|
34
|
|
|
*/ |
|
35
|
|
|
private $pipelineFactory; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* RequestExecutor constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param PipelineFactory $pipelineFactory Pipeline factory |
|
41
|
|
|
* @param Configuration $configuration Configuration for executor |
|
42
|
|
|
*/ |
|
43
|
64 |
|
public function __construct(PipelineFactory $pipelineFactory, Configuration $configuration) |
|
44
|
|
|
{ |
|
45
|
64 |
|
parent::__construct($configuration); |
|
46
|
64 |
|
$this->pipelineFactory = $pipelineFactory; |
|
47
|
64 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** {@inheritdoc} */ |
|
50
|
62 |
|
protected function initializeRequest(EventCaller $eventCaller) |
|
51
|
|
|
{ |
|
52
|
62 |
|
parent::initializeRequest($eventCaller); |
|
53
|
62 |
|
$this->pipeline = $this->pipelineFactory->createPipeline($this, $eventCaller, $this->solver); |
|
54
|
62 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** {@inheritdoc} */ |
|
57
|
62 |
|
protected function terminateRequest() |
|
58
|
1 |
|
{ |
|
59
|
62 |
|
parent::terminateRequest(); |
|
60
|
62 |
|
$this->pipeline = null; |
|
61
|
62 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** {@inheritdoc} */ |
|
64
|
62 |
|
protected function doExecuteRequest(EventCaller $eventCaller) |
|
65
|
|
|
{ |
|
66
|
62 |
|
$this->pipeline->process($this->socketBag); |
|
67
|
28 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** {@inheritdoc} */ |
|
70
|
9 |
|
protected function disconnectItems(array $items) |
|
71
|
|
|
{ |
|
72
|
9 |
|
$this->pipeline->disconnectSockets($items); |
|
73
|
9 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|