Skip to content

Commit

Permalink
Merge pull request #478 from KnpLabs/v2-unstable-change-interfaces
Browse files Browse the repository at this point in the history
fix: Change interfaces function names
  • Loading branch information
Swanoo authored Jun 23, 2023
2 parents f0c3a85 + efc2878 commit 857cad1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Core/Bridge/FromFileToStringToPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
use KnpLabs\Snappy\Core\FileToPdf;
use KnpLabs\Snappy\Core\StringToPdf;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;

final class FromFileToStringToPdf implements FileToPdf
{
public function __construct(private StringToPdf $stringToPdf)
{
}

public function generate(SplFileInfo $file, ArrayAccess|array $options = []): StreamInterface
public function generateFromFile(\SplFileInfo $file, \ArrayAccess|array $options = []): StreamInterface
{
return $this->stringToPdf->generate(
return $this->stringToPdf->generateFromString(
file_get_contents($file->getPathname()),
$options,
);
Expand Down
7 changes: 3 additions & 4 deletions src/Core/Bridge/FromStringToFileToPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
use KnpLabs\Snappy\Core\FileToPdf;
use KnpLabs\Snappy\Core\StringToPdf;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;

final class FromStringToFileToPdf implements StringToPdf
{
public function __construct(private FileToPdf $fileToPdf)
{
}

public function generate(string $html, ArrayAccess|array $options = []): StreamInterface
public function generateFromString(string $html, \ArrayAccess|array $options = []): StreamInterface
{
$path = tempnam(sys_get_temp_dir(), 'snappy_');

try {
file_put_contents($path, $html);

$file = new SplFileInfo($path);
$file = new \SplFileInfo($path);

$stream = $this->fileToPdf->generate($file, $options);
$stream = $this->fileToPdf->generateFromFile($file, $options);
} finally {
unlink($path);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Core/FileToPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace KnpLabs\Snappy\Core;

use ArrayAccess;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;

interface FileToPdf
{
public function generate(SplFileInfo $file, ArrayAccess|array $options = []): StreamInterface;
public function generateFromFile(\SplFileInfo $file, \ArrayAccess|array $options = []): StreamInterface;
}
4 changes: 1 addition & 3 deletions src/Core/StringToPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace KnpLabs\Snappy\Core;

use ArrayAccess;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;

interface StringToPdf
{
public function generate(string $html, ArrayAccess|array $options = []): StreamInterface;
public function generateFromString(string $html, \ArrayAccess|array $options = []): StreamInterface;
}
11 changes: 11 additions & 0 deletions src/Core/UriToPdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace KnpLabs\Snappy\Core;

use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;

interface UriToPdf
{
public function generateFromUri(UriInterface $url, \ArrayAccess|array $options = []): StreamInterface;
}

0 comments on commit 857cad1

Please sign in to comment.