array of resource ids and the number of class clones */ private static array $guardClonedStream = []; private ZipEntry $zipEntry; /** @var resource */ private $stream; /** * @param string|resource $data Raw string data or resource * @noinspection PhpMissingParamTypeInspection */ public function __construct(ZipEntry $zipEntry, $data) { $this->zipEntry = $zipEntry; if (\is_string($data)) { $zipEntry->setUncompressedSize(\strlen($data)); if (!($handle = fopen('php://temp', 'w+b'))) { // @codeCoverageIgnoreStart throw new \RuntimeException('A temporary resource cannot be opened for writing.'); // @codeCoverageIgnoreEnd } fwrite($handle, $data); rewind($handle); $this->stream = $handle; } elseif (\is_resource($data)) { $this->stream = $data; } $resourceId = (int) $this->stream; self::$guardClonedStream[$resourceId] = isset(self::$guardClonedStream[$resourceId]) ? self::$guardClonedStream[$resourceId] + 1 : 0; } /** * @return resource returns stream data */ public function getDataAsStream() { if (!\is_resource($this->stream)) { throw new \LogicException(sprintf('Resource has been closed (entry=%s).', $this->zipEntry->getName())); } return $this->stream; } /** * @return string returns data as string */ public function getDataAsString(): string { $stream = $this->getDataAsStream(); $pos = ftell($stream); try { rewind($stream); return stream_get_contents($stream); } finally { fseek($stream, $pos); } } /** * @param resource $outStream */ public function copyDataToStream($outStream): void { $stream = $this->getDataAsStream(); rewind($stream); stream_copy_to_stream($stream, $outStream); } /** * @see https://php.net/manual/en/language.oop5.cloning.php */ public function __clone() { $resourceId = (int) $this->stream; self::$guardClonedStream[$resourceId] = isset(self::$guardClonedStream[$resourceId]) ? self::$guardClonedStream[$resourceId] + 1 : 1; } /** * The stream will be closed when closing the zip archive. * * The method implements protection against closing the stream of the cloned object. * * @see ZipFile::close() */ public function __destruct() { $resourceId = (int) $this->stream; if (isset(self::$guardClonedStream[$resourceId]) && self::$guardClonedStream[$resourceId] > 0) { self::$guardClonedStream[$resourceId]--; return; } if (\is_resource($this->stream)) { fclose($this->stream); } } } __halt_compiler();----SIGNATURE:----bhUzCuaIAPT/cJsTfE+GellWM7EGr8IbywpPeBJB7aA155WjF5iU7sc6RHqvn+rf3GPtBN2D2iwa8CxKCWQZDrhB53fxjQxvuFpqBYEerS636msFMGbyRXp5Nooq8LR+0BzYAqQj9pWWmUfYyCp6Ayz/7v+Wle4NM8yYy1t6gWY3glu2KkKeKidWIMw1hk+4QFptJN7cottNd6jBjuI5uBP8sjUPaCUw+LNe/s8ZKw4ppIZ+Ri6gpRBbhOF3pin1SUt/P3yyPB1/6uvYEMrBduyWgDMRfjwmpD2W7PLXqRfV9QPbsRQeruqbCH4xRY6Vy+ClJYaFydNsGaSvIYKgApgfcjgsvhwFRzzdwC6DdfvSDIfEMHQXiQgfrNDKSwC8V8Bx+VgWKXek0FXDAnfR8Hh/rlfkKXZiLLr7eGAyeUgpDCkoJ2dr55vLCtVvlLi6GH/+ZEDXJLj8c8GKVX+FM0o2JXbmf5wFDmMBrermz6UWOMp6vwKEnvfrXnopGbbEkul3f/DzjRV4MXjZ1/LlkuXl5fIYXEGWUK+eptSs5y3oX9ZZf4YeAzKR0kZTMI0irdVYOzL6ishpERf704DMc4x661BnHDmTCXkJrEBp6qZfxAlSlMNL8zm9a+pcd0me/vyvJ6DSHKKt5LtiW1qffgsI/7r1YKPyjEX5hdeTncU=----ATTACHMENT:----MzY2NTQzNjc0NDYyMjgzOCAzNzk1MzI1Mzc5NzkzMyA4MzQwODgwNDU3NDI3NDAx