PluginProbe
ManageWP Worker / trunk
ManageWP Worker vtrunk
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 / Decorator.php

Decorator.php in ManageWP Worker trunk, at src/MWP/Stream/Decorator.php

112 lines 2.5 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 <[email protected]>
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 abstract class MWP_Stream_Decorator implements MWP_Stream_Interface
12 {
13
14 private $initialized = false;
15
16 /**
17 * @var MWP_Stream_Interface
18 */
19 private $stream;
20
21 /**
22 * @param MWP_Stream_Interface|null $stream
23 *
24 * Note: Type hint removed from $stream parameter to fix PHP 8.4+ deprecation warning
25 * about implicitly nullable parameters while maintaining backward compatibility with PHP 5.5+.
26 * The nullable type syntax (?MWP_Stream_Interface) is not supported in PHP 5.5-7.0.
27 */
28 public function __construct($stream = null)
29 {
30 $this->stream = $stream;
31
32 if ($this->stream) {
33 $this->initialized = true;
34 }
35 }
36
37 protected function getStream()
38 {
39 if (!$this->stream) {
40 $this->stream = $this->createStream();
41 }
42
43 return $this->stream;
44 }
45
46 protected function createStream()
47 {
48 return null;
49 }
50
51 /**
52 * Closes the stream and any underlying resources.
53 */
54 public function close()
55 {
56 $this->getStream()->close();
57 }
58
59 /**
60 * Returns the current position of the file read/write pointer
61 *
62 * @return int|bool Returns the position of the file pointer or false on error
63 */
64 public function tell()
65 {
66 return $this->getStream()->tell();
67 }
68
69 /**
70 * @return bool
71 */
72 public function isSeekable()
73 {
74 return $this->getStream()->isSeekable();
75 }
76
77 /**
78 * @param int $offset
79 * @param int $whence
80 *
81 * @return bool
82 */
83 public function seek($offset, $whence = SEEK_SET)
84 {
85 return $this->getStream()->seek($offset, $whence);
86 }
87
88 /**
89 * Returns true if the stream is at the end of the stream.
90 *
91 * @return bool
92 */
93 public function eof()
94 {
95 return $this->getStream()->eof();
96 }
97
98 /**
99 * Read data from the stream
100 *
101 * @param int $length Read up to $length bytes from the object and return
102 * them. Fewer than $length bytes may be returned if
103 * underlying stream call returns fewer bytes.
104 *
105 * @return string Returns the data read from the stream.
106 */
107 public function read($length)
108 {
109 return $this->getStream()->read($length);
110 }
111 }
112