Skip to content

Commit f7f577f

Browse files
authored
Merge pull request #48 from sunrise-php/release/v3.8.0
v3.8
2 parents 6db6a36 + 341d8b4 commit f7f577f

File tree

8 files changed

+102
-10
lines changed

8 files changed

+102
-10
lines changed

src/FileStreamInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* It's free open-source software released under the MIT License.
5+
*
6+
* @author Anatoly Nekhay <afenric@gmail.com>
7+
* @copyright Copyright (c) 2018, Anatoly Nekhay
8+
* @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9+
* @link https://github.com/sunrise-php/http-message
10+
*/
11+
12+
namespace Sunrise\Http\Message;
13+
14+
use Psr\Http\Message\StreamInterface;
15+
16+
interface FileStreamInterface extends StreamInterface
17+
{
18+
public function getFilename(): string;
19+
}

src/HeaderInterface.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111

1212
namespace Sunrise\Http\Message;
1313

14-
use IteratorAggregate;
15-
16-
/**
17-
* @extends IteratorAggregate<int, string>
18-
*/
19-
interface HeaderInterface extends IteratorAggregate
14+
interface HeaderInterface
2015
{
2116
public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';
2217

src/Stream/FileStream.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
namespace Sunrise\Http\Message\Stream;
1313

1414
use Sunrise\Http\Message\Exception\InvalidArgumentException;
15+
use Sunrise\Http\Message\FileStreamInterface;
1516
use Sunrise\Http\Message\Stream;
1617
use Throwable;
1718

1819
use function fopen;
1920
use function is_resource;
2021
use function sprintf;
2122

22-
final class FileStream extends Stream
23+
final class FileStream extends Stream implements FileStreamInterface
2324
{
2425
/**
2526
* @throws InvalidArgumentException
@@ -29,6 +30,14 @@ public function __construct(string $filename, string $mode)
2930
parent::__construct(self::openFile($filename, $mode));
3031
}
3132

33+
public function getFilename(): string
34+
{
35+
/** @var string $filename */
36+
$filename = $this->getMetadata('uri');
37+
38+
return $filename;
39+
}
40+
3241
/**
3342
* @return resource
3443
*
@@ -46,7 +55,7 @@ private static function openFile(string $filename, string $mode)
4655
throw new InvalidArgumentException(sprintf(
4756
'Unable to open the file "%s" in the mode "%s"',
4857
$filename,
49-
$mode
58+
$mode,
5059
));
5160
}
5261

src/Stream/TempFileStream.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Sunrise\Http\Message\Stream;
1313

1414
use Sunrise\Http\Message\Exception\RuntimeException;
15+
use Sunrise\Http\Message\FileStreamInterface;
1516
use Sunrise\Http\Message\Stream;
1617

1718
use function fopen;
@@ -20,7 +21,7 @@
2021
use function sys_get_temp_dir;
2122
use function tempnam;
2223

23-
final class TempFileStream extends Stream
24+
final class TempFileStream extends Stream implements FileStreamInterface
2425
{
2526
/**
2627
* @throws RuntimeException
@@ -30,6 +31,14 @@ public function __construct(string $prefix = '')
3031
parent::__construct(self::createFile($prefix));
3132
}
3233

34+
public function getFilename(): string
35+
{
36+
/** @var string $filename */
37+
$filename = $this->getMetadata('uri');
38+
39+
return $filename;
40+
}
41+
3342
/**
3443
* @return resource
3544
*

src/Stream/TmpfileStream.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Sunrise\Http\Message\Stream;
1313

1414
use Sunrise\Http\Message\Exception\RuntimeException;
15+
use Sunrise\Http\Message\FileStreamInterface;
1516
use Sunrise\Http\Message\Stream;
1617

1718
use function is_resource;
@@ -24,7 +25,7 @@
2425
* read/write (w+b) mode. The file will be automatically deleted
2526
* when it is closed or the program terminates.
2627
*/
27-
final class TmpfileStream extends Stream
28+
final class TmpfileStream extends Stream implements FileStreamInterface
2829
{
2930
/**
3031
* @throws RuntimeException
@@ -34,6 +35,14 @@ public function __construct()
3435
parent::__construct(self::createFile());
3536
}
3637

38+
public function getFilename(): string
39+
{
40+
/** @var string $filename */
41+
$filename = $this->getMetadata('uri');
42+
43+
return $filename;
44+
}
45+
3746
/**
3847
* @return resource
3948
*

tests/Stream/FileStreamTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sunrise\Http\Message\Tests\Stream;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sunrise\Http\Message\Stream\FileStream;
9+
10+
final class FileStreamTest extends TestCase
11+
{
12+
public function testFilename(): void
13+
{
14+
$stream = new FileStream(__FILE__, 'r');
15+
self::assertSame(__FILE__, $stream->getFilename());
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sunrise\Http\Message\Tests\Stream;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sunrise\Http\Message\Stream\TempFileStream;
9+
10+
final class TempFileStreamTest extends TestCase
11+
{
12+
public function testFilename() : void
13+
{
14+
$stream = new TempFileStream();
15+
self::assertFileExists($stream->getFilename());
16+
}
17+
}

tests/Stream/TmpfileStreamTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sunrise\Http\Message\Tests\Stream;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sunrise\Http\Message\Stream\TmpfileStream;
9+
10+
final class TmpfileStreamTest extends TestCase
11+
{
12+
public function testFilename(): void
13+
{
14+
$stream = new TmpfileStream();
15+
self::assertFileExists($stream->getFilename());
16+
}
17+
}

0 commit comments

Comments
 (0)