1 | <?php |
||
17 | class SlowSpeedTransferException extends TransferException |
||
18 | { |
||
19 | /** |
||
20 | * Speed at the moment of exception in bytes per second |
||
21 | * |
||
22 | * @var double |
||
23 | */ |
||
24 | private $speed; |
||
25 | |||
26 | /** |
||
27 | * Duration of low speed in seconds |
||
28 | * |
||
29 | * @var int |
||
30 | */ |
||
31 | private $duration; |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | 1 | public function __construct( |
|
49 | |||
50 | /** |
||
51 | * Create exception for slow receive speed |
||
52 | * |
||
53 | * @param SocketInterface $socket Socket |
||
54 | * @param double $speed Speed at the moment of exception in bytes per second |
||
55 | * @param int $duration Duration of low speed in seconds |
||
56 | * |
||
57 | * @return SlowSpeedTransferException |
||
58 | */ |
||
59 | 1 | public static function tooSlowDataReceiving(SocketInterface $socket, $speed, $duration) |
|
60 | { |
||
61 | 1 | return new self( |
|
62 | 1 | $socket, |
|
63 | 1 | self::DIRECTION_RECV, |
|
64 | 1 | $speed, |
|
65 | 1 | $duration, |
|
66 | 'Data transfer is going to be aborted because of too slow speed.' |
||
67 | 1 | ); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Create exception for slow send speed |
||
72 | * |
||
73 | * @param SocketInterface $socket Socket |
||
74 | * @param double $speed Speed at the moment of exception in bytes per second |
||
75 | * @param int $duration Duration of low speed in seconds |
||
76 | * |
||
77 | * @return SlowSpeedTransferException |
||
78 | */ |
||
79 | public static function tooSlowDataSending(SocketInterface $socket, $speed, $duration) |
||
80 | { |
||
81 | return new self( |
||
82 | $socket, |
||
83 | self::DIRECTION_SEND, |
||
84 | $speed, |
||
85 | $duration, |
||
86 | 'Data transfer is going to be aborted because of too slow speed.' |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Return speed at the moment of exception in bytes per second |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | public function getSpeed() |
||
99 | |||
100 | /** |
||
101 | * Return duration of low speed in seconds |
||
102 | * |
||
103 | * @return int |
||
104 | */ |
||
105 | public function getDuration() |
||
109 | } |
||
110 |