Add [AllowDynamicProperties] in the base view class for J5. Move the _prepareDocument above the display call in the base view class. Remove all backward compatibility issues, so JCB will not need the [Backward Compatibility] plugin to run. Added new import powers for custom import of spreadsheets. Move the setDocument and _prepareDocument above the display in the site view and custom admin view. Update the trashhelper layout to work in Joomla 5. Add AllowDynamicProperties (Joomla 4+5) to view class to allow Custom Dynamic Get methods to work without issues. Fix Save failed issue in dynamicGet. #1148. Move all [TEXT, EDITOR, TEXTAREA] fields from [NOT NULL] to [NULL]. Add the DateHelper class and improve the date methods. Add simple SessionHelper class. Add first classes for the new import engine. Improve the [VDM Registry] to be Joomla Registry Compatible. Move all registries to the [VDM Registry] class. Fix Checked Out to be null and not 0. (#1194). Fix created_by, modified_by, checked_out fields in the compiler of the SQL. (#1194). Update all core date fields in table class. (#1188). Update created_by, modified_by, checked_out fields in table class. Implementation of the decentralized Super-Power CORE repository network. (#1190). Fix the noticeboard to display Llewellyn's Joomla Social feed.
161 lines
3.9 KiB
PHP
161 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ZipStream\Test;
|
|
|
|
use Psr\Http\Message\StreamInterface;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class ResourceStream implements StreamInterface
|
|
{
|
|
public function __construct(
|
|
/**
|
|
* @var resource
|
|
*/
|
|
private $stream
|
|
) {
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
if ($this->isSeekable()) {
|
|
$this->seek(0);
|
|
}
|
|
return (string) stream_get_contents($this->stream);
|
|
}
|
|
|
|
public function close(): void
|
|
{
|
|
$stream = $this->detach();
|
|
if ($stream) {
|
|
fclose($stream);
|
|
}
|
|
}
|
|
|
|
public function detach()
|
|
{
|
|
$result = $this->stream;
|
|
// According to the interface, the stream is left in an unusable state;
|
|
/** @psalm-suppress PossiblyNullPropertyAssignmentValue */
|
|
$this->stream = null;
|
|
return $result;
|
|
}
|
|
|
|
public function seek(int $offset, int $whence = SEEK_SET): void
|
|
{
|
|
if (!$this->isSeekable()) {
|
|
throw new RuntimeException();
|
|
}
|
|
if (fseek($this->stream, $offset, $whence) !== 0) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException();
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
}
|
|
|
|
public function isSeekable(): bool
|
|
{
|
|
return (bool)$this->getMetadata('seekable');
|
|
}
|
|
|
|
public function getMetadata(?string $key = null)
|
|
{
|
|
$metadata = stream_get_meta_data($this->stream);
|
|
return $key !== null ? @$metadata[$key] : $metadata;
|
|
}
|
|
|
|
public function getSize(): ?int
|
|
{
|
|
$stats = fstat($this->stream);
|
|
return $stats['size'];
|
|
}
|
|
|
|
public function tell(): int
|
|
{
|
|
$position = ftell($this->stream);
|
|
if ($position === false) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException();
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return $position;
|
|
}
|
|
|
|
public function eof(): bool
|
|
{
|
|
return feof($this->stream);
|
|
}
|
|
|
|
public function rewind(): void
|
|
{
|
|
$this->seek(0);
|
|
}
|
|
|
|
public function write(string $string): int
|
|
{
|
|
if (!$this->isWritable()) {
|
|
throw new RuntimeException();
|
|
}
|
|
if (fwrite($this->stream, $string) === false) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException();
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return strlen($string);
|
|
}
|
|
|
|
public function isWritable(): bool
|
|
{
|
|
$mode = $this->getMetadata('mode');
|
|
if (!is_string($mode)) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException('Could not get stream mode from metadata!');
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return preg_match('/[waxc+]/', $mode) === 1;
|
|
}
|
|
|
|
public function read(int $length): string
|
|
{
|
|
if (!$this->isReadable()) {
|
|
throw new RuntimeException();
|
|
}
|
|
$result = fread($this->stream, $length);
|
|
if ($result === false) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException();
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function isReadable(): bool
|
|
{
|
|
$mode = $this->getMetadata('mode');
|
|
if (!is_string($mode)) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException('Could not get stream mode from metadata!');
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return preg_match('/[r+]/', $mode) === 1;
|
|
}
|
|
|
|
public function getContents(): string
|
|
{
|
|
if (!$this->isReadable()) {
|
|
throw new RuntimeException();
|
|
}
|
|
$result = stream_get_contents($this->stream);
|
|
if ($result === false) {
|
|
// @codeCoverageIgnoreStart
|
|
throw new RuntimeException();
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
return $result;
|
|
}
|
|
}
|