Skip to content

[DependencyInjection][FrameworkBundle] Use php-serialize to dump the container for debug/lint commands #60597

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 30, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

To unlock #60568 this uses serialize() to dump the container, next to the XML dump.

@carsonbot carsonbot added this to the 7.4 milestone May 30, 2025
@nicolas-grekas nicolas-grekas changed the title [DependencyInjection][FrameworkBundle] Use php-serialize to dump the … [DependencyInjection][FrameworkBundle] Use php-serialize to dump the container for debug/link commands May 30, 2025
@symfony symfony deleted a comment from carsonbot May 30, 2025
@nicolas-grekas nicolas-grekas force-pushed the dump-container-ser branch 4 times, most recently from 965f23d to 013e6ce Compare May 30, 2025 14:27
$container->getCompilerPassConfig()->setBeforeOptimizationPasses([]);
$container->getCompilerPassConfig()->setOptimizationPasses([]);
$container->getCompilerPassConfig()->setBeforeRemovingPasses([]);
if (str_ends_with($file, '.xml') && is_file(substr_replace($file, '.ser', -4))) {
Copy link
Member

Choose a reason for hiding this comment

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

The .ser file name extension seems common in Java. It makes sense to use it for serialized data in PHP too.

Copy link
Member Author

Choose a reason for hiding this comment

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

So you agree with this line, that's what you mean, isn't it?

@nicolas-grekas nicolas-grekas force-pushed the dump-container-ser branch 2 times, most recently from e804022 to 930c4a6 Compare June 2, 2025 08:15
*/
trait ArgumentTrait
{
public function __serialize(): array
Copy link
Member Author

@nicolas-grekas nicolas-grekas Jun 2, 2025

Choose a reason for hiding this comment

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

I figured out that the resulting serialized payload had a LOT of repeated strings.
The added __serialize methods reduce its size from 2.8M to 829K on a skeleton webapp.
This might be interesting to Drupal folks I suppose /cc @alexpott
For reference, the xml is 590K.

Copy link
Member

Choose a reason for hiding this comment

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

should we add tests covering the fact that serializing an argument and then unserializing it works fine, to avoid introducing bugs in that logic (which seems to rely on the fact that the default unserialization of PHP is able to process the returned data without implementing __unserialize) ?

Copy link
Member

Choose a reason for hiding this comment

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

btw, this might also prevent contributors from reverting the usage of default property values (submitting a PR to use constructor promoted properties again).

@nicolas-grekas nicolas-grekas changed the title [DependencyInjection][FrameworkBundle] Use php-serialize to dump the container for debug/link commands [DependencyInjection][FrameworkBundle] Use php-serialize to dump the container for debug/lint commands Jun 2, 2025
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.

5 participants