Skip to content

Commit 8c23321

Browse files
committed
update dependecies
1 parent a8456fc commit 8c23321

File tree

3 files changed

+119
-75
lines changed

3 files changed

+119
-75
lines changed

api.include.php

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,18 +1515,16 @@ public function createStream(string $content = ''): StreamInterface
15151515

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

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

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

15321530
return Stream::create($resource);
@@ -2143,6 +2141,9 @@ public function getAttributes(): array
21432141
return $this->attributes;
21442142
}
21452143

2144+
/**
2145+
* @return mixed
2146+
*/
21462147
public function getAttribute($attribute, $default = null)
21472148
{
21482149
if (false === \array_key_exists($attribute, $this->attributes)) {
@@ -2358,16 +2359,20 @@ public function getSize() /*:?int*/
23582359

23592360
public function tell(): int
23602361
{
2361-
if (false === $result = \ftell($this->stream)) {
2362-
throw new \RuntimeException('Unable to determine stream position');
2362+
if (!isset($this->stream)) {
2363+
throw new \RuntimeException('Stream is detached');
2364+
}
2365+
2366+
if (false === $result = @\ftell($this->stream)) {
2367+
throw new \RuntimeException('Unable to determine stream position: ' . (\error_get_last()['message'] ?? ''));
23632368
}
23642369

23652370
return $result;
23662371
}
23672372

23682373
public function eof(): bool
23692374
{
2370-
return !$this->stream || \feof($this->stream);
2375+
return !isset($this->stream) || \feof($this->stream);
23712376
}
23722377

23732378
public function isSeekable(): bool
@@ -2377,6 +2382,10 @@ public function isSeekable(): bool
23772382

23782383
public function seek($offset, $whence = \SEEK_SET) /*:void*/
23792384
{
2385+
if (!isset($this->stream)) {
2386+
throw new \RuntimeException('Stream is detached');
2387+
}
2388+
23802389
if (!$this->seekable) {
23812390
throw new \RuntimeException('Stream is not seekable');
23822391
}
@@ -2398,15 +2407,19 @@ public function isWritable(): bool
23982407

23992408
public function write($string): int
24002409
{
2410+
if (!isset($this->stream)) {
2411+
throw new \RuntimeException('Stream is detached');
2412+
}
2413+
24012414
if (!$this->writable) {
24022415
throw new \RuntimeException('Cannot write to a non-writable stream');
24032416
}
24042417

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

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

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

24202433
public function read($length): string
24212434
{
2435+
if (!isset($this->stream)) {
2436+
throw new \RuntimeException('Stream is detached');
2437+
}
2438+
24222439
if (!$this->readable) {
24232440
throw new \RuntimeException('Cannot read from non-readable stream');
24242441
}
24252442

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

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

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

24432460
return $contents;
24442461
}
24452462

2463+
/**
2464+
* @return mixed
2465+
*/
24462466
public function getMetadata($key = null)
24472467
{
24482468
if (!isset($this->stream)) {
@@ -2539,7 +2559,7 @@ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename
25392559

25402560
if (\UPLOAD_ERR_OK === $this->error) {
25412561
// Depending on the value set file or stream variable.
2542-
if (\is_string($streamOrFile)) {
2562+
if (\is_string($streamOrFile) && '' !== $streamOrFile) {
25432563
$this->file = $streamOrFile;
25442564
} elseif (\is_resource($streamOrFile)) {
25452565
$this->stream = Stream::create($streamOrFile);
@@ -2573,11 +2593,11 @@ public function getStream(): StreamInterface
25732593
return $this->stream;
25742594
}
25752595

2576-
try {
2577-
return Stream::create(\fopen($this->file, 'r'));
2578-
} catch (\Throwable $e) {
2579-
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened.', $this->file));
2596+
if (false === $resource = @\fopen($this->file, 'r')) {
2597+
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $this->file, \error_get_last()['message'] ?? ''));
25802598
}
2599+
2600+
return Stream::create($resource);
25812601
}
25822602

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

25912611
if (null !== $this->file) {
2592-
$this->moved = 'cli' === \PHP_SAPI ? \rename($this->file, $targetPath) : \move_uploaded_file($this->file, $targetPath);
2612+
$this->moved = 'cli' === \PHP_SAPI ? @\rename($this->file, $targetPath) : @\move_uploaded_file($this->file, $targetPath);
2613+
2614+
if (false === $this->moved) {
2615+
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s": %s', $targetPath, \error_get_last()['message'] ?? ''));
2616+
}
25932617
} else {
25942618
$stream = $this->getStream();
25952619
if ($stream->isSeekable()) {
25962620
$stream->rewind();
25972621
}
25982622

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

2627+
$dest = Stream::create($resource);
2628+
26062629
while (!$stream->eof()) {
26072630
if (!$dest->write($stream->read(1048576))) {
26082631
break;
@@ -2611,10 +2634,6 @@ public function moveTo($targetPath) /*:void*/
26112634

26122635
$this->moved = true;
26132636
}
2614-
2615-
if (false === $this->moved) {
2616-
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s"', $targetPath));
2617-
}
26182637
}
26192638

26202639
public function getSize(): int
@@ -7876,9 +7895,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
78767895
$method = $request->getMethod();
78777896
if ($method == 'POST' && in_array($path, ['login', 'register', 'password'])) {
78787897
$body = $request->getParsedBody();
7879-
$username = isset($body->username) ? $body->username : '';
7880-
$password = isset($body->password) ? $body->password : '';
7881-
$newPassword = isset($body->newPassword) ? $body->newPassword : '';
7898+
$usernameFormFieldName = $this->getProperty('usernameFormField', 'username');
7899+
$passwordFormFieldName = $this->getProperty('passwordFormField', 'username');
7900+
$newPasswordFormFieldName = $this->getProperty('newPasswordFormField', 'username');
7901+
$username = isset($body->usernameFormFieldName) ? $body->usernameFormFieldName : '';
7902+
$password = isset($body->passwordFormFieldName) ? $body->passwordFormFieldName : '';
7903+
$newPassword = isset($body->newPasswordFormFieldName) ? $body->newPasswordFormFieldName : '';
78827904
$tableName = $this->getProperty('usersTable', 'users');
78837905
$table = $this->reflection->getTable($tableName);
78847906
$usernameColumnName = $this->getProperty('usernameColumn', 'username');

0 commit comments

Comments
 (0)