Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poc/builder v2 #118

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Poc/builder v2 #118

wants to merge 3 commits into from

Conversation

Jean-Beru
Copy link
Contributor

WIP with limited feature and a lot of old/useless files

@Jean-Beru Jean-Beru force-pushed the poc/builder_v2 branch 2 times, most recently from 86de3d0 to 5827398 Compare November 18, 2024 14:55

protected function getUrlGenerator(): UrlGeneratorInterface
{
if (!($urlGenerator = $this->dependencies->get('urlGenerator')) instanceof UrlGeneratorInterface) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!($urlGenerator = $this->dependencies->get('urlGenerator')) instanceof UrlGeneratorInterface) {
if (!($urlGenerator = $this->dependencies->get('router')) instanceof UrlGeneratorInterface) {

?

service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service_locator([
'asset_base_dir_formatter' => service('sensiolabs_gotenberg.asset.base_dir_formatter'),
'logger' => service('logger')->nullOnInvalid(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ I think this will include the wrong logger service. Not the custom channel.

$assets = $this->getBodyBag()->get('assets', []);

if (\array_key_exists($path, $assets)) {
return $this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we log a warning ? Also I think we should check if two files have the same name. I think gotenberg treat them as same file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I don't think that it will create useless logs when your Twig template use gotenberg_asset multiple times. For example, a logo displayed in the first and the last page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. maybe if both the filename is the same but the path is different

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, we can only use files under the root folder. It could be possible but we'll have to generate a unique ID depending on the file path when adding (and using) the asset.


return $this;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF


$current = $this->getBodyBag()->get('extraHttpHeaders', []);

$this->getBodyBag()->set('extraHttpHeaders', array_merge($current, $headers));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using an object like arrayiterator to always have a reference to push elements into ? Might be better than array_merge. Would also require normalizer to convert it to array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Would it be possible to replace an existing header with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally yes. I don't see why not.

*/
public function emulatedMediaType(EmulatedMediaType $mediaType): static
{
$this->getBodyBag()->set('emulatedMediaType', $mediaType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->value is missing or am I missing something ? (allowedValues)

  • EOF

{
use DependencyAwareTrait;

protected function getAssetBaseDirFormatter(): AssetBaseDirFormatter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should maybe directly be part of DependencyAwareTrait. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this dependency always be required ? Maybe the read metadata API will be the only API with no files form data 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly not. But I think it does not clutter too much the builder files and simplify things a lot.


protected function getLogger(): LoggerInterface|null
{
if (($logger = $this->dependencies->get('logger')) instanceof Environment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (($logger = $this->dependencies->get('logger')) instanceof Environment) {
if (($logger = $this->dependencies->get('logger')) instanceof LoggerInterface) {

namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies;

use Psr\Log\LoggerInterface;
use Twig\Environment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use Twig\Environment;

{
protected function createBuilder(GotenbergClientInterface $client, ContainerInterface $dependencies): BuilderInterface
{
$dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(new Filesystem(), __DIR__, 'fixtures'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be mocked if AssetBaseDirFormatter is reworked (final and without interface for now)

{
$response = $this->client->call($this->getEndpoint(), $this->bodyBag, $this->headersBag);

if (!\in_array($response->getStatusCode(), [200, 204], true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm I don't see the benefit of having this here instead of in the call method. I was thinking more in the GileResult object. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Jean-Beru Jean-Beru force-pushed the poc/builder_v2 branch 4 times, most recently from 9bdb6f7 to fdc00a1 Compare January 13, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants