Completed
Branch 0.4-dev (f2f961)
by Evgenij
02:48
created

ReadEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 5
crap 1
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
namespace AsyncSockets\Event;
11
12
use AsyncSockets\Frame\FrameInterface;
13
use AsyncSockets\Frame\PartialFrame;
14
use AsyncSockets\RequestExecutor\RequestExecutorInterface;
15
use AsyncSockets\Socket\SocketInterface;
16
17
/**
18
 * Class ReadEvent
19
 */
20
class ReadEvent extends IoEvent
21
{
22
    /**
23
     * Data read from network
24
     *
25
     * @var FrameInterface
26
     */
27
    private $frame;
28
29
    /**
30
     * Flag if data are out of band
31
     *
32
     * @var bool
33
     */
34
    private $isOutOfBand;
35
36
    /**
37
     * Constructor
38
     *
39
     * @param RequestExecutorInterface $executor Request executor object
40
     * @param SocketInterface          $socket Socket for this request
41
     * @param mixed                    $context Any optional user data for event
42
     * @param FrameInterface           $frame Network data for read operation
43
     * @param bool                     $isOutOfBand Flag if data are out of band
44
     */
45 51
    public function __construct(
46
        RequestExecutorInterface $executor,
47
        SocketInterface $socket,
48
        $context,
49
        FrameInterface $frame,
50
        $isOutOfBand = false
51
    ) {
52 51
        parent::__construct($executor, $socket, $context, EventType::READ);
53 51
        $this->frame       = $frame;
54 51
        $this->isOutOfBand = $isOutOfBand;
55 51
    }
56
57
    /**
58
     * Return response frame
59
     *
60
     * @return FrameInterface
61
     */
62 9
    public function getFrame()
63
    {
64 9
        return $this->frame;
65
    }
66
67
    /**
68
     * Return true, if frame in this event is partial
69
     *
70
     * @return bool
71
     */
72 3
    public function isPartial()
73
    {
74 3
        return $this->frame instanceof PartialFrame;
75
    }
76
77
    /**
78
     * Return true if data are out of band
79
     *
80
     * @return bool
81
     */
82 8
    public function isOutOfBand()
83
    {
84 8
        return $this->isOutOfBand;
85
    }
86
}
87