-
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
6506e94
commit e629813
Showing
23 changed files
with
258 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,6 @@ public static function hasExtension(string $extension): bool | |
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
final readonly class ConvertOptions | ||
final readonly class Pdf2ImgConvertOptions | ||
{ | ||
/** | ||
* ConvertOptions constructor. | ||
|
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 |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
|
||
namespace CodeInc\DocumentCloud\Pdf2Img; | ||
|
||
/** | ||
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
enum Pdf2ImgOutputFormat | ||
{ | ||
case webp; | ||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
final readonly class ConvertOptions | ||
final readonly class Pdf2TxtConvertOptions | ||
{ | ||
/** | ||
* ConvertOptions constructor. | ||
|
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,71 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Code Inc. <https://www.codeinc.co> | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
namespace CodeInc\DocumentCloud\Util; | ||
|
||
use CodeInc\DocumentCloud\Exception\FileOpenException; | ||
use CodeInc\DocumentCloud\Exception\FileWriteException; | ||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use InvalidArgumentException; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use RuntimeException; | ||
|
||
/** | ||
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
class StreamUtils | ||
{ | ||
/** | ||
* Opens a local file and creates a stream from it. | ||
* | ||
* @param string $path The path to the file. | ||
* @param string $openMode The mode used to open the file. | ||
* @param StreamFactoryInterface|null $streamFactory The PSR-17 stream factory. | ||
* @return StreamInterface | ||
* @throws FileOpenException | ||
*/ | ||
public static function createStreamFromFile( | ||
string $path, | ||
string $openMode = 'r', | ||
?StreamFactoryInterface $streamFactory = null | ||
): StreamInterface { | ||
$streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); | ||
|
||
try { | ||
return $streamFactory->createStreamFromFile($path, $openMode); | ||
} catch (RuntimeException|InvalidArgumentException $exception) { | ||
throw new FileOpenException($exception->getMessage(), previous: $exception); | ||
} | ||
} | ||
|
||
/** | ||
* Saves a stream to a local file. | ||
* | ||
* @param StreamInterface $stream | ||
* @param string $path The path to the file. | ||
* @param string $openMode The mode used to open the file. | ||
* @throws FileOpenException | ||
* @throws FileWriteException | ||
*/ | ||
public static function saveStreamToFile(StreamInterface $stream, string $path, string $openMode = 'w'): void | ||
{ | ||
$f = fopen($path, $openMode); | ||
if ($f === false) { | ||
throw new FileOpenException("The file '$path' could not be opened"); | ||
} | ||
|
||
if (stream_copy_to_stream($stream->detach(), $f) === false) { | ||
throw new FileWriteException("The stream could not be copied to the file '$path'"); | ||
} | ||
|
||
fclose($f); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
class EndpointUrl | ||
class UrlUtils | ||
{ | ||
/** | ||
* Returns the URL of an endpoint. | ||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
final readonly class ConvertOptions | ||
final readonly class WatermarkerConvertOptions | ||
{ | ||
/** | ||
* ConvertOptions constructor. | ||
|
Oops, something went wrong.