This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now using DocumentFactory to simplify Document instantiation
- Loading branch information
Showing
7 changed files
with
61 additions
and
59 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,29 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\Gotenberg; | ||
|
||
use GuzzleHttp\Psr7\LazyOpenStream; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
class DocumentFactory | ||
{ | ||
/** | ||
* @param string $fileName | ||
* @param string $filePath | ||
* @return Document | ||
*/ | ||
public static function makeFromPath(string $fileName, string $filePath): Document | ||
{ | ||
return new Document($fileName, new LazyOpenStream($filePath, 'r')); | ||
} | ||
|
||
/** | ||
* @param string $fileName | ||
* @param StreamInterface $fileStream | ||
* @return Document | ||
*/ | ||
public static function makeFromStream(string $fileName, StreamInterface $fileStream): Document | ||
{ | ||
return new Document($fileName, $fileStream); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\Gotenberg; | ||
|
||
use GuzzleHttp\Psr7\LazyOpenStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DocumentFactoryTest extends TestCase | ||
{ | ||
function testMake() | ||
{ | ||
// case 1: uses a file path. | ||
$document = DocumentFactory::makeFromPath('file.pdf', __DIR__ . '/assets/file.pdf'); | ||
$this->assertNotEmpty($document->getFileStream()); | ||
|
||
// case 2: uses a stream. | ||
$document = DocumentFactory::makeFromStream('file.pdf', new LazyOpenStream(__DIR__ . '/assets/file.pdf', 'r')); | ||
$this->assertNotEmpty($document->getFileStream()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.