-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
[RTM] Support for replaying headers #749
[RTM] Support for replaying headers #749
Conversation
composer.json
Outdated
@@ -122,5 +124,7 @@ | |||
"dev-develop": "4.4.x-dev" | |||
}, | |||
"contao-manager-plugin": "Contao\\CoreBundle\\ContaoManager\\Plugin" | |||
} | |||
}, | |||
"minimum-stability": "dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary if you suffix the requirement with @dev
. If that's an issue with an included package, simply require it in the root as well (with @dev
).
} | ||
|
||
$headers = $event->getHeaders(); | ||
$headers->set('Contao-Page-Layout', $mobile ? 'mobile' : 'desktop'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to call this Contao-Mobile-Layout
with true
only value or the header not being present. Also, creating a $headers
variable is fairly unnecessary here, but I guess you're aware of that. Just a matter of choice :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like my version better. This applies to both, the header name and the variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was that the header would not need to be present for 90% of pages (if not in mobile mode). Also, the Vary would only be needed if the current page actually has a mobile layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could introduce new layout types using the same header with @Toflar's variant. Therefore I am also in favor of his approach.
src/Resources/config/listener.yml
Outdated
arguments: | ||
- "%contao.security.disable_ip_check%" | ||
tags: | ||
- { name: kernel.event_listener, event: t42.header_replay, method: onReplay } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I remember Symfony events, the correct way to name the method would be according to the event name. So t42.header_replay
would result in an onHeaderReplay
method. Also, if you follow that convention, you do not need to name the method (it will be discovered automatically).
On a side note, I think the event should be called terminal42.header_replay
to not introduce another "namespace".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would look shit, which is why I decided not to do it. onTerminal42HeaderReplay()
is not a nice method name at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be onHeaderReplay
. The key is not used. Think of kernel.response
=> onResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's onKernelResponse
.
No. It has to be present due to dependencies. I know about the @dev setting.
|
cd4aa42
to
51a60f7
Compare
cf5c60f
to
fbee6c7
Compare
src/ContaoManager/Plugin.php
Outdated
@@ -43,7 +44,7 @@ class Plugin implements BundlePluginInterface, RoutingPluginInterface | |||
public function getBundles(ParserInterface $parser) | |||
{ | |||
return [ | |||
BundleConfig::create(KnpMenuBundle::class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is a rebase-bug! Fixed in 9fdb93e.
{ | ||
$request = $event->getRequest(); | ||
|
||
$this->framework->initialize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty sure we should check for a Contao scope before booting the framework on EVERY request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On every request with a Cookie
or Authorization
header, yeah. We could do that? How do I do this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean only for routes with _scope=frontend
.
*/ | ||
public function onReplay(HeaderReplayEvent $event) | ||
{ | ||
$request = $event->getRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies here. The event listener should only be triggered on $request->attributes->get('_scope') === 'backend'
(actually use the constant!)
Scope checks implemented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides my two comments and a lot of missing phpDocs the PR looks good to me. 😄
case 'desktop': | ||
$mobile = false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid initializing the framework if there is a TL_VIEW
cookie:
if ($request->cookies->has('TL_VIEW')) {
$mobile = 'mobile' === $request->cookies->get('TL_VIEW');
} else {
$this->framework->initialize();
$mobile = $this->framework->getAdapter(Environment::class)->get('agent')->mobile;
}
// TODO: Add support for proxies so they can vary on member context and page layout | ||
if (FE_USER_LOGGED_IN === true || BE_USER_LOGGED_IN === true || $objPage->isMobile || $objPage->protected || $this->hasAuthenticatedBackendUser()) | ||
// Vary on page layout | ||
$response->setVary(['Contao-Page-Layout'], false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is legacy code, so we must not use the short array notation.
@leofeyer comments addressed. |
Implements our terminal42/header-replay-bundle to support "splitting up" user context provided by cookies (or authorization header or whatever you like) into whatever headers you like that are then replayed as master request onto the application so you can vary on them. Please read the whole README of the header-replay-bundle to understand the concept.
Vary
on itToDo's
Adjust your
AppCache
according to the README. PR for the Managed Edition: contao/manager-bundle#26