PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Stream / Append.php

Append.php in ManageWP Worker 4.9.25, at src/MWP/Stream/Append.php

132 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 /**
12 * Append stream.
13 */
14 class MWP_Stream_Append implements MWP_Stream_Interface
15 {
16
17 /**
18 * @var MWP_Stream_Interface[]
19 */
20 private $streams = array();
21
22 private $current = 0;
23
24 /**
25 * Add a stream to the AppendStream
26 *
27 * @param MWP_Stream_Interface $stream Stream to append. Must be readable.
28 */
29 public function addStream(MWP_Stream_Interface $stream)
30 {
31 $this->streams[] = $stream;
32 }
33
34 /**
35 * @return bool
36 */
37 public function isSeekable()
38 {
39 return false;
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function seek($offset, $whence = SEEK_SET)
46 {
47 return false;
48 }
49
50 /**
51 * {@inheritdoc}
52 */
53 public function eof()
54 {
55 return $this->isAtLastStream() && $this->getCurrentStream()->eof();
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 public function read($length)
62 {
63 $data = '';
64
65 while (!$this->eof()) {
66 while ($this->getCurrentStream()->eof() && !$this->eof()) {
67 $this->moveToNextStream();
68 }
69
70 $currentStreamData = $this->getCurrentStream()->read($length);
71 $data .= $currentStreamData;
72 $length -= strlen($currentStreamData);
73
74 if ($length <= 0) {
75 break;
76 }
77 }
78
79 return $data;
80 }
81
82 /**
83 * {@inheritdoc}
84 */
85 public function close()
86 {
87 foreach ($this->streams as $stream) {
88 $stream->close();
89 }
90 }
91
92 /**
93 * Tell is not supported.
94 */
95 public function tell()
96 {
97 return false;
98 }
99
100 public function __toString()
101 {
102 $buffer = '';
103
104 while (!$this->eof()) {
105 $buffer .= $this->read(1048576);
106 }
107
108 return $buffer;
109 }
110
111 private function moveToNextStream()
112 {
113 if ($this->current >= count($this->streams)) {
114 return false;
115 }
116
117 $this->current++;
118
119 return true;
120 }
121
122 private function isAtLastStream()
123 {
124 return $this->current === count($this->streams) - 1;
125 }
126
127 private function getCurrentStream()
128 {
129 return $this->streams[$this->current];
130 }
131 }
132