Skip to content

Commit 256764d

Browse files
committed
fix streams
1 parent 89430cd commit 256764d

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

Stream/InputStream.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Marshaller\Stream;
6+
7+
final class InputStream extends Stream
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct('php://input', 'placeholder');
12+
}
13+
}

Stream/MemoryStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
final class MemoryStream extends Stream
88
{
9-
public function __construct()
9+
public function __construct(string $mode = 'w+b')
1010
{
11-
parent::__construct('php://memory', readable: true, writable: true);
11+
parent::__construct('php://memory', $mode);
1212
}
1313
}

Stream/OutputStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ final class OutputStream extends Stream
88
{
99
public function __construct()
1010
{
11-
parent::__construct('php://output', readable: true, writable: false);
11+
parent::__construct('php://output', 'placeholder');
1212
}
1313
}

Stream/StdinStream.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\Marshaller\Stream;
6+
7+
final class StdinStream extends Stream
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct('php://stdin', 'placeholder');
12+
}
13+
}

Stream/StdoutStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ final class StdoutStream extends Stream
88
{
99
public function __construct()
1010
{
11-
parent::__construct('php://stdout', readable: true, writable: false);
11+
parent::__construct('php://stdout', 'placeholder');
1212
}
1313
}

Stream/Stream.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ abstract class Stream implements StreamInterface
1313

1414
protected function __construct(
1515
protected readonly string $filename,
16-
protected bool $readable,
17-
protected bool $writable,
16+
protected readonly string $mode,
1817
) {
1918
}
2019

@@ -24,9 +23,7 @@ final public function stream()
2423
return $this->stream;
2524
}
2625

27-
$mode = sprintf('%s%sb', $this->readable ? 'r' : '', $this->writable ? 'w' : '');
28-
29-
if (false === $stream = fopen($this->filename, $mode)) {
26+
if (false === $stream = fopen($this->filename, $this->mode)) {
3027
throw new \RuntimeException(sprintf('Cannot open "%s" stream', $this->filename));
3128
}
3229

Stream/TempStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
final class TempStream extends Stream
88
{
9-
public function __construct(int $memoryThreshold = 2048)
9+
public function __construct(int $memoryThreshold = 2048, string $mode = 'w+b')
1010
{
11-
parent::__construct(sprintf('php://temp/maxmemory:%d', $memoryThreshold), readable: true, writable: true);
11+
parent::__construct(sprintf('php://temp/maxmemory:%d', $memoryThreshold), $mode);
1212
}
1313
}

Tests/Stream/StreamTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testCreateStream(): void
1414
$stream = new class () extends Stream {
1515
public function __construct()
1616
{
17-
parent::__construct('php://memory', readable: true, writable: true);
17+
parent::__construct('php://memory', 'w+b');
1818
}
1919
};
2020

@@ -29,7 +29,7 @@ public function testToString(): void
2929
$stream = new class () extends Stream {
3030
public function __construct()
3131
{
32-
parent::__construct('php://memory', readable: true, writable: true);
32+
parent::__construct('php://memory', 'w+b');
3333
}
3434
};
3535

0 commit comments

Comments
 (0)