Skip to content

Refactor/deprecate content methods#274

Open
marilenaRM wants to merge 5 commits into
sensiolabs:1.xfrom
marilenaRM:refactor/deprecate-content-methods
Open

Refactor/deprecate content methods#274
marilenaRM wants to merge 5 commits into
sensiolabs:1.xfrom
marilenaRM:refactor/deprecate-content-methods

Conversation

@marilenaRM

Copy link
Copy Markdown
Q A
Gotenberg API version ? 8.x
Bug fix ? yes + Refactor
New feature ? no
BC break ? no
Issues Fix #257

Description

Summary

  • Extract header/footer methods from ContentTrait into a new dedicated PageMarginalTrait; ChromiumPdfTrait resolves the conflict via insteadof so PDF builders transparently use the real implementation
  • Deprecate content(), contentRaw() and contentFile() on UrlPdfBuilder and UrlScreenshotBuilder via a new DeprecatedBodyContentTrait (these builders receive their body from the URL, not from injected HTML)
  • Fix three bugs in docs/generate.php: @example tags were silently dropped when a method was seen via multiple traits, an empty description from a @deprecated-only docblock could overwrite a non-empty one, and deprecated
    no-op stubs appeared in the generated docs without any content

See UPGRADE-1.2.md for migration instructions.

Replaces #266

Test plan

  • ./vendor/bin/phpunit — all tests pass
  • ./vendor/bin/phpstan analyse — no new errors
  • ./vendor/bin/php-cs-fixer fix --diff — no changes
  • dagger call generate-docs export --path . — docs regenerated cleanly, deprecated methods absent from output
  • Confirm HtmlPdfBuilder::header() uses PageMarginalTrait (not the deprecated stub)
  • Confirm UrlPdfBuilder::content() fires E_USER_DEPRECATED

Marilena Ruffelaere added 3 commits May 19, 2026 11:12
header*, footer* methods move to the new PageMarginalTrait. The original
methods remain in ContentTrait as deprecated no-ops (E_USER_DEPRECATED,
will be removed in 2.0) for BC, allowing existing code to receive a
deprecation warning rather than a runtime error.

ChromiumPdfTrait is updated to prefer PageMarginalTrait over the
deprecated ContentTrait stubs via insteadof. Screenshot builders keep
using ContentTrait directly since Gotenberg does not support headers and
footers for screenshots; the deprecated stubs are filtered out of the
generated documentation.

The deprecation message was corrected: the stubs in ContentTrait are
only ever called by builders that do not use PageMarginalTrait (e.g.
screenshot builders), so saying "Use PageMarginalTrait instead" would
be misleading. The message now states that header/footer support is
not available on the current builder.
Since the page body is fetched from the URL itself, content(),
contentRaw() and contentFile() are meaningless on URL-based builders.
They are now deprecated via DeprecatedBodyContentTrait (no-op +
E_USER_DEPRECATED) and will be removed in 2.0.
Three bugs fixed in docs/generate.php:

- @example merge: when a method appears in multiple traits (e.g. via
  insteadof resolution), the @example from the winning trait was silently
  discarded because the merge loop did not handle the example tag. The
  last seen @example now wins.

- Description merge: a docblock containing only tags (@deprecated, @see,
  etc.) produces an empty description array [], which is distinct from
  [''] and incorrectly satisfied the overwrite condition, erasing a
  previously collected verbose description. The condition now guards
  against both empty forms.

- Deprecated method filtering: public methods whose resolved docblock
  carries @deprecated are now excluded from the generated output. This
  prevents no-op stubs from appearing in the documentation without any
  useful content.
@marilenaRM marilenaRM force-pushed the refactor/deprecate-content-methods branch from b84f329 to ca5d371 Compare May 19, 2026 09:12
@Neirda24 Neirda24 added this to the v1.4 milestone May 19, 2026
public function header(string $template, array $context = []): static
{
return $this->withRenderedPart(Part::Header, $template, $context);
@trigger_error(\sprintf('Since sensiolabs/gotenberg-bundle 1.2: "%s" is deprecated and will be removed in 2.0. Header/footer support has been moved to "%s"; this builder does not support it.', __METHOD__, PageMarginalTrait::class), \E_USER_DEPRECATED);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about https://www.php.net/manual/en/class.deprecated.php ?

Ex:

#[Deprecated(message:'Will be removed in 2.0. Use Sensiolabs\GotenbergBundle\Builder\Behaviors\Chromium\PageMarginalTrait instead', since:'sensiolabs/GotenbergBundle:1.3')]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done!

@marilenaRM marilenaRM requested a review from Jean-Beru June 8, 2026 15:45
trait DeprecatedBodyContentTrait
{
/**
* @deprecated since 1.2, will be removed in 2.0. The page body is provided by the URL.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @deprecated since 1.2, will be removed in 2.0. The page body is provided by the URL.
* @deprecated since 1.4, will be removed in 2.0. The page body is provided by the URL.

This also applies to the following annotations/triggers.

Comment thread UPGRADE-1.2.md

### `UrlPdfBuilder` and `UrlScreenshotBuilder`: `content*` methods deprecated

The `content()`, `contentRaw()` and `contentFile()` methods are deprecated on `UrlPdfBuilder` and `UrlScreenshotBuilder`. Since the page body is provided by the URL itself, these methods have no effect. Use `url()` or `route()` instead. They will be removed in 2.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be in the UPGRADE-1.4.md file.

Comment thread UPGRADE-1.2.md

### `ContentTrait`: header and footer methods moved to `PageMarginalTrait`

The `header()`, `headerRaw()`, `headerFile()`, `footer()`, `footerRaw()` and `footerFile()` methods have been moved out of `ContentTrait` into the new dedicated `PageMarginalTrait`. These methods are still accessible through `ContentTrait` in 1.2 but will be removed in 2.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
The `header()`, `headerRaw()`, `headerFile()`, `footer()`, `footerRaw()` and `footerFile()` methods have been moved out of `ContentTrait` into the new dedicated `PageMarginalTrait`. These methods are still accessible through `ContentTrait` in 1.2 but will be removed in 2.0.
The `header()`, `headerRaw()`, `headerFile()`, `footer()`, `footerRaw()` and `footerFile()` methods have been moved out of `ContentTrait` into the new dedicated `PageMarginalTrait`. These methods are still accessible through `ContentTrait` in 1.4 but will be removed in 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Remove content* methods from UrlBuilder

3 participants