-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stadly\FileWaiter; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use Stadly\FileWaiter\Exception\StreamCouldNotBeOpened; | ||
use Stadly\Http\Header\Value\Date; | ||
use Stadly\Http\Header\Value\EntityTag\EntityTag; | ||
use Stadly\Http\Header\Value\MediaType\MediaType; | ||
|
||
/** | ||
* Interface for file adapters. | ||
*/ | ||
interface Adapter | ||
{ | ||
/** | ||
* @return StreamInterface File stream that can be used to read from the file. | ||
* @throws StreamCouldNotBeOpened If the file stream could not be opened. | ||
*/ | ||
public function getFileStream(): StreamInterface; | ||
|
||
/** | ||
* @return string|null File name, or null if not known. | ||
*/ | ||
public function getFileName(): ?string; | ||
|
||
/** | ||
* @return int|null File size, or null if not known. | ||
*/ | ||
public function getFileSize(): ?int; | ||
|
||
/** | ||
* @return MediaType|null Media type of the file, or null if not known. | ||
*/ | ||
public function getMediaType(): ?MediaType; | ||
|
||
/** | ||
* @return Date|null Date when the file was last modified, or null if not known. | ||
*/ | ||
public function getLastModifiedDate(): ?Date; | ||
|
||
/** | ||
* @return EntityTag|null Entity tag for the file, or null if not known. | ||
*/ | ||
public function getEntityTag(): ?EntityTag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stadly\FileWaiter\Exception; | ||
|
||
use RuntimeException; | ||
use Throwable; | ||
|
||
/** | ||
* Exception thrown when a file stream could not be opened. | ||
*/ | ||
final class StreamCouldNotBeOpened extends RuntimeException | ||
{ | ||
/** | ||
* @var string Path to file. | ||
*/ | ||
private $filePath; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $filePath Path to file. | ||
* @param Throwable $previous Previous exception, used for exception chaining. | ||
*/ | ||
public function __construct(string $filePath, ?Throwable $previous = null) | ||
{ | ||
$this->filePath = $filePath; | ||
|
||
parent::__construct('File stream could not be opened: ' . $filePath, /*code*/0, $previous); | ||
} | ||
|
||
/** | ||
* @return string Path to file. | ||
*/ | ||
public function getFilePath(): string | ||
{ | ||
return $this->filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stadly\FileWaiter\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Stadly\FileWaiter\Exception\StreamCouldNotBeOpened | ||
* @covers ::<protected> | ||
* @covers ::<private> | ||
*/ | ||
final class StreamCouldNotBeOpenedTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::__construct | ||
*/ | ||
public function testCanConstructException(): void | ||
{ | ||
$exception = new StreamCouldNotBeOpened('foo/bar.baz'); | ||
|
||
// Force generation of code coverage | ||
$exceptionConstruct = new StreamCouldNotBeOpened('foo/bar.baz'); | ||
self::assertEquals($exception, $exceptionConstruct); | ||
} | ||
|
||
/** | ||
* @covers ::getFilePath | ||
*/ | ||
public function testCanGetFilePath(): void | ||
{ | ||
$exception = new StreamCouldNotBeOpened('foo/bar.baz'); | ||
|
||
self::assertSame('foo/bar.baz', $exception->getFilePath()); | ||
} | ||
} |