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

Fix php error #639

Merged
merged 2 commits into from
Jan 9, 2025
Merged

Fix php error #639

merged 2 commits into from
Jan 9, 2025

Conversation

richardhj
Copy link
Contributor

Fixes #638

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Jan 9, 2025

Think the CacheControlListener need also be adopted. I'm getting:

TypeError: FOS\HttpCacheBundle\EventListener\CacheControlListener::__construct(): Argument #2 ($ttlHeader) must be of type string, null given, called in /home/runner/work/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Tests/Application/var/cache/website/test/ContainerY4qBT6C/Sulu_Bundle_WebsiteBundle_Tests_Application_KernelTestDebugContainer.php on line 530

Update see: #639 (comment)

@richardhj richardhj marked this pull request as draft January 9, 2025 08:52
@dbu
Copy link
Contributor

dbu commented Jan 9, 2025

damn, did not realize how defaults in the configuration work. and looks like we did not add enough tests to discover this issue, sorry.

to avoid side effects like always enabling the cache control listener even when not wanted, lets use the fallback in the FOSHttpCacheExtension class as @94noni originally proposed with the default value if nothing is in the array.

the default will then only matter if people write ttl_header: ~ but afaik it is best practice to do that.

to make things more explicit, lets add a public constant in the src/EventListener/CacheControlListener.php class and reference that both from Configuration and from FOSHttpCacheExtension to avoid the magic string. do you want to do that @richardhj ? then i can tag a patch version with the fix.

@richardhj
Copy link
Contributor Author

Should be ready to review

@@ -48,7 +49,7 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['debug']['enabled'] || (!empty($config['cache_control']))) {
Copy link
Contributor

@alexander-schranz alexander-schranz Jan 9, 2025

Choose a reason for hiding this comment

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

@dbu Do we want to have the CacheControlListener registered if only the new ttl_header config is defined, for maybe just the debug ENVs?

If not we would need to go with: count($config['cache_control']) > 1 and addDefaultsIfNotSet in the config. The ?? would not be required then also.

Copy link
Contributor

Choose a reason for hiding this comment

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

i can't see a use case for configuring the ttl_header but not configuring any reverse_proxy_ttl at all.

if we merge as is now, my understanding is that the behaviour is the same as before, except that the ttl_header configuration is respected if overwritten, but does not cause errors if not explicitly mentioned by the user. am i missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it will not break, it just register a listener which does then nothing as no rules are configured.

Copy link
Contributor

Choose a reason for hiding this comment

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

i clarified with alexander, we leave it like this. the cleanest way would be to count if there are any cache_control.rules, but this is not the bug and could have edge case side effects if somebody relies on the cache control service to exist even without rules if there is any configuration.

could be a cleanup for 4.x. when we count the rules, we can also addDefaultsIfNotSet on the ttl_header

Copy link
Contributor

@94noni 94noni left a comment

Choose a reason for hiding this comment

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

lets do it that way in fine 👍🏻

@dbu dbu merged commit 0f593e4 into FriendsOfSymfony:3.x Jan 9, 2025
12 checks passed
@dbu
Copy link
Contributor

dbu commented Jan 9, 2025

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.

4 participants