This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
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
1 parent
666e314
commit e936c8a
Showing
1 changed file
with
30 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,30 +24,45 @@ | |
* Class WatermarkerClient | ||
* | ||
* @package CodeInc\WatermarkerClient | ||
* @author Joan Fabrégat <[email protected]> | ||
* @link https://github.com/codeinchq/watermarker-php-client | ||
* @link https://github.com/codeinchq/watermarker | ||
* @author Joan Fabrégat <[email protected]> | ||
* @link https://github.com/codeinchq/watermarker-php-client | ||
* @link https://github.com/codeinchq/watermarker | ||
* @license MIT <https://opensource.org/licenses/MIT> | ||
*/ | ||
class WatermarkerClient | ||
readonly class WatermarkerClient | ||
{ | ||
private ClientInterface $client; | ||
private StreamFactoryInterface $streamFactory; | ||
private RequestFactoryInterface $requestFactory; | ||
|
||
/** | ||
* WatermarkerClient constructor. | ||
* | ||
* @param string $baseUrl The base URL of the WATERMARKER API. | ||
* @param ClientInterface|null $client The HTTP client (optional, uses the PSR-18 discovery by | ||
* default). | ||
* @param StreamFactoryInterface|null $streamFactory The stream factory (optional, uses the PSR-17 discovery by | ||
* default). | ||
* @param RequestFactoryInterface|null $requestFactory The request factory (optional, uses the PSR-17 discovery by | ||
* default). | ||
*/ | ||
public function __construct( | ||
private readonly string $baseUrl, | ||
private ClientInterface|null $client = null, | ||
private StreamFactoryInterface|null $streamFactory = null, | ||
private RequestFactoryInterface|null $requestFactory = null, | ||
private string $baseUrl, | ||
ClientInterface|null $client = null, | ||
StreamFactoryInterface|null $streamFactory = null, | ||
RequestFactoryInterface|null $requestFactory = null, | ||
) { | ||
$this->client ??= Psr18ClientDiscovery::find(); | ||
$this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); | ||
$this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory(); | ||
$this->client = $client ?? Psr18ClientDiscovery::find(); | ||
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory(); | ||
$this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); | ||
} | ||
|
||
/** | ||
* Applies a watermark to an image using the WATERMARKER API. | ||
* | ||
* @param StreamInterface|resource|string $imageStream The PDF content. | ||
* @param StreamInterface|resource|string $imageStream The PDF content. | ||
* @param StreamInterface|resource|string $watermarkStream The watermark content. | ||
* @param ConvertOptions $options The convert options. | ||
* @param ConvertOptions $options The convert options. | ||
* @return StreamInterface | ||
* @throws Exception | ||
*/ | ||
|
@@ -107,7 +122,7 @@ public function apply( | |
/** | ||
* Opens a local file and creates a stream from it. | ||
* | ||
* @param string $path The path to the file. | ||
* @param string $path The path to the file. | ||
* @param string $openMode The mode used to open the file. | ||
* @return StreamInterface | ||
* @throws Exception | ||
|
@@ -126,7 +141,7 @@ public function createStreamFromFile(string $path, string $openMode = 'r'): Stre | |
* Saves a stream to a local file. | ||
* | ||
* @param StreamInterface $stream | ||
* @param string $path The path to the file. | ||
* @param string $path The path to the file. | ||
* @param string $openMode The mode used to open the file. | ||
* @throws Exception | ||
*/ | ||
|