Skip to content

Commit

Permalink
update dependecies
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Feb 17, 2022
1 parent a8456fc commit 8c23321
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 75 deletions.
90 changes: 56 additions & 34 deletions api.include.php
Expand Up @@ -1515,18 +1515,16 @@ public function createStream(string $content = ''): StreamInterface

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
{
try {
$resource = @\fopen($filename, $mode);
} catch (\Throwable $e) {
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $filename));
if ('' === $filename) {
throw new \RuntimeException('Path cannot be empty');
}

if (false === $resource) {
if (false === $resource = @\fopen($filename, $mode)) {
if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) {
throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode));
}

throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $filename));
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? ''));
}

return Stream::create($resource);
Expand Down Expand Up @@ -2143,6 +2141,9 @@ public function getAttributes(): array
return $this->attributes;
}

/**
* @return mixed
*/
public function getAttribute($attribute, $default = null)
{
if (false === \array_key_exists($attribute, $this->attributes)) {
Expand Down Expand Up @@ -2358,16 +2359,20 @@ public function getSize() /*:?int*/

public function tell(): int
{
if (false === $result = \ftell($this->stream)) {
throw new \RuntimeException('Unable to determine stream position');
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}

if (false === $result = @\ftell($this->stream)) {
throw new \RuntimeException('Unable to determine stream position: ' . (\error_get_last()['message'] ?? ''));
}

return $result;
}

public function eof(): bool
{
return !$this->stream || \feof($this->stream);
return !isset($this->stream) || \feof($this->stream);
}

public function isSeekable(): bool
Expand All @@ -2377,6 +2382,10 @@ public function isSeekable(): bool

public function seek($offset, $whence = \SEEK_SET) /*:void*/
{
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}

if (!$this->seekable) {
throw new \RuntimeException('Stream is not seekable');
}
Expand All @@ -2398,15 +2407,19 @@ public function isWritable(): bool

public function write($string): int
{
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}

if (!$this->writable) {
throw new \RuntimeException('Cannot write to a non-writable stream');
}

// We can't know the size after writing anything
$this->size = null;

if (false === $result = \fwrite($this->stream, $string)) {
throw new \RuntimeException('Unable to write to stream');
if (false === $result = @\fwrite($this->stream, $string)) {
throw new \RuntimeException('Unable to write to stream: ' . (\error_get_last()['message'] ?? ''));
}

return $result;
Expand All @@ -2419,12 +2432,16 @@ public function isReadable(): bool

public function read($length): string
{
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}

if (!$this->readable) {
throw new \RuntimeException('Cannot read from non-readable stream');
}

if (false === $result = \fread($this->stream, $length)) {
throw new \RuntimeException('Unable to read from stream');
if (false === $result = @\fread($this->stream, $length)) {
throw new \RuntimeException('Unable to read from stream: ' . (\error_get_last()['message'] ?? ''));
}

return $result;
Expand All @@ -2433,16 +2450,19 @@ public function read($length): string
public function getContents(): string
{
if (!isset($this->stream)) {
throw new \RuntimeException('Unable to read stream contents');
throw new \RuntimeException('Stream is detached');
}

if (false === $contents = \stream_get_contents($this->stream)) {
throw new \RuntimeException('Unable to read stream contents');
if (false === $contents = @\stream_get_contents($this->stream)) {
throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? ''));
}

return $contents;
}

/**
* @return mixed
*/
public function getMetadata($key = null)
{
if (!isset($this->stream)) {
Expand Down Expand Up @@ -2539,7 +2559,7 @@ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename

if (\UPLOAD_ERR_OK === $this->error) {
// Depending on the value set file or stream variable.
if (\is_string($streamOrFile)) {
if (\is_string($streamOrFile) && '' !== $streamOrFile) {
$this->file = $streamOrFile;
} elseif (\is_resource($streamOrFile)) {
$this->stream = Stream::create($streamOrFile);
Expand Down Expand Up @@ -2573,11 +2593,11 @@ public function getStream(): StreamInterface
return $this->stream;
}

try {
return Stream::create(\fopen($this->file, 'r'));
} catch (\Throwable $e) {
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $this->file));
if (false === $resource = @\fopen($this->file, 'r')) {
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $this->file, \error_get_last()['message'] ?? ''));
}

return Stream::create($resource);
}

public function moveTo($targetPath) /*:void*/
Expand All @@ -2589,20 +2609,23 @@ public function moveTo($targetPath) /*:void*/
}

if (null !== $this->file) {
$this->moved = 'cli' === \PHP_SAPI ? \rename($this->file, $targetPath) : \move_uploaded_file($this->file, $targetPath);
$this->moved = 'cli' === \PHP_SAPI ? @\rename($this->file, $targetPath) : @\move_uploaded_file($this->file, $targetPath);

if (false === $this->moved) {
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s": %s', $targetPath, \error_get_last()['message'] ?? ''));
}
} else {
$stream = $this->getStream();
if ($stream->isSeekable()) {
$stream->rewind();
}

try {
// Copy the contents of a stream into another stream until end-of-file.
$dest = Stream::create(\fopen($targetPath, 'w'));
} catch (\Throwable $e) {
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $targetPath));
if (false === $resource = @\fopen($targetPath, 'w')) {
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $targetPath, \error_get_last()['message'] ?? ''));
}

$dest = Stream::create($resource);

while (!$stream->eof()) {
if (!$dest->write($stream->read(1048576))) {
break;
Expand All @@ -2611,10 +2634,6 @@ public function moveTo($targetPath) /*:void*/

$this->moved = true;
}

if (false === $this->moved) {
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s"', $targetPath));
}
}

public function getSize(): int
Expand Down Expand Up @@ -7876,9 +7895,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$method = $request->getMethod();
if ($method == 'POST' && in_array($path, ['login', 'register', 'password'])) {
$body = $request->getParsedBody();
$username = isset($body->username) ? $body->username : '';
$password = isset($body->password) ? $body->password : '';
$newPassword = isset($body->newPassword) ? $body->newPassword : '';
$usernameFormFieldName = $this->getProperty('usernameFormField', 'username');
$passwordFormFieldName = $this->getProperty('passwordFormField', 'username');
$newPasswordFormFieldName = $this->getProperty('newPasswordFormField', 'username');
$username = isset($body->usernameFormFieldName) ? $body->usernameFormFieldName : '';
$password = isset($body->passwordFormFieldName) ? $body->passwordFormFieldName : '';
$newPassword = isset($body->newPasswordFormFieldName) ? $body->newPasswordFormFieldName : '';
$tableName = $this->getProperty('usersTable', 'users');
$table = $this->reflection->getTable($tableName);
$usernameColumnName = $this->getProperty('usernameColumn', 'username');
Expand Down

0 comments on commit 8c23321

Please sign in to comment.