forked from pimcore/pimcore
-
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.
Added Gotenberg support for creating page and version previews (pimco…
…re#16608) * Added Gotenberg support for creating page and version previews * Update lib/Image/HtmlToImage.php Co-authored-by: JiaJia Ji <[email protected]> * Update lib/Image/HtmlToImage.php Co-authored-by: JiaJia Ji <[email protected]> * Making Stan happy * added upgrade notes * docs * Update composer.json Co-authored-by: JiaJia Ji <[email protected]> * deprected Chromium support * Update lib/Image/HtmlToImage.php Co-authored-by: JiaJia Ji <[email protected]> * Added compatibility layer and deprecation notice * make PhpStan happy --------- Co-authored-by: JiaJia Ji <[email protected]>
- Loading branch information
Showing
11 changed files
with
325 additions
and
148 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
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,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pimcore\Helper; | ||
|
||
use Gotenberg\Gotenberg as GotenbergAPI; | ||
use Gotenberg\Stream; | ||
use Pimcore\Config; | ||
use function class_exists; | ||
use function method_exists; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class GotenbergHelper | ||
{ | ||
private static bool $validPing = false; | ||
|
||
/** | ||
* | ||
* @throws \Exception | ||
*/ | ||
public static function isAvailable(): bool | ||
{ | ||
if (self::$validPing) { | ||
return true; | ||
} | ||
|
||
if (!class_exists(GotenbergAPI::class, true)) { | ||
return false; | ||
} | ||
|
||
$request = null; | ||
|
||
/** @var GotenbergAPI|object $chrome */ | ||
$chrome = GotenbergAPI::chromium(Config::getSystemConfiguration('gotenberg')['base_url']); | ||
if(method_exists($chrome, 'html')) { | ||
// gotenberg/gotenberg-php API Client v1 | ||
$request = $chrome->html(Stream::string('dummy.html', '<body></body>')); | ||
} elseif(method_exists($chrome, 'screenshot')) { | ||
$request = $chrome->screenshot()->html(Stream::string('dummy.html', '<body></body>')); | ||
} | ||
|
||
if($request) { | ||
try { | ||
GotenbergAPI::send($request); | ||
self::$validPing = true; | ||
|
||
return true; | ||
} catch (\Exception $e) { | ||
// nothing to do | ||
} | ||
} | ||
|
||
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
Oops, something went wrong.