-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
214 additions
and
49 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
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,28 @@ | ||
<?php | ||
|
||
namespace Sensiolabs\GotenbergBundle\Formatter; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
final readonly class AssetBaseDirFormatter | ||
{ | ||
private string $baseDir; | ||
|
||
public function __construct(private Filesystem $filesystem, private string $projectDir, string $baseDir) | ||
{ | ||
$this->baseDir = rtrim($baseDir, '/'); | ||
} | ||
|
||
public function resolve(string $path): string | ||
{ | ||
if ($this->filesystem->isAbsolutePath($path)) { | ||
return $path; | ||
} | ||
|
||
if ($this->filesystem->isAbsolutePath($this->baseDir)) { | ||
return "{$this->baseDir}/{$path}"; | ||
} | ||
|
||
return "{$this->projectDir}/{$this->baseDir}/{$path}"; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Sensiolabs\GotenbergBundle\Twig; | ||
|
||
use Sensiolabs\GotenbergBundle\Builder\AbstractChromiumPdfBuilder; | ||
use Symfony\Component\Mime\Part\File; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
final class GotenbergAssetExtension extends AbstractExtension | ||
{ | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('gotenberg_asset', $this->getAssetUrl(...), ['needs_context' => true]), | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function getAssetUrl(array $context, string $path): string | ||
{ | ||
$builder = $context['_builder']; | ||
|
||
if (!$builder instanceof AbstractChromiumPdfBuilder) { | ||
throw new \LogicException('You need to extend from AbstractChromiumPdfBuilder to use gotenberg_asset function.'); | ||
} | ||
|
||
$builder->addAsset($path); | ||
|
||
return (new File($path))->getFilename(); | ||
} | ||
} |
Oops, something went wrong.