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
Use site_url to build form cache #7193
Merged
kuzmany
merged 2 commits into
mautic:staging
from
acquia:staging.form-html-cache-action
Apr 12, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
app/bundles/CoreBundle/EventListener/RouterSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2018 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\CoreBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class RouterSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var RouterInterface | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $baseUrl; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $scheme; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $host; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $httpsPort; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $httpPort; | ||
|
||
/** | ||
* RouterSubscriber constructor. | ||
* | ||
* @param RouterInterface $router | ||
* @param null|string $scheme | ||
* @param null|string $host | ||
* @param null|string $httpsPort | ||
* @param null|string $httpPort | ||
* @param null|string $baseUrl | ||
*/ | ||
public function __construct(RouterInterface $router, $scheme, $host, $httpsPort, $httpPort, $baseUrl) | ||
{ | ||
$this->router = $router; | ||
$this->scheme = $scheme; | ||
$this->host = $host; | ||
$this->httpsPort = $httpsPort; | ||
$this->httpPort = $httpPort; | ||
$this->baseUrl = $baseUrl; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
KernelEvents::REQUEST => ['setRouterRequestContext', 1], | ||
]; | ||
} | ||
|
||
/** | ||
* This forces generated routes to be the same as what is configured as Mautic's site_url | ||
* in order to prevent mismatches between cached URLs generated during web requests and URLs generated | ||
* via CLI/cron jobs. | ||
* | ||
* @param GetResponseEvent $event | ||
*/ | ||
public function setRouterRequestContext(GetResponseEvent $event) | ||
{ | ||
if (empty($this->host)) { | ||
return; | ||
} | ||
|
||
if (!$event->isMasterRequest()) { | ||
return; | ||
} | ||
|
||
if ('dev' === MAUTIC_ENV) { | ||
$this->baseUrl = '/index_dev.php'.$this->baseUrl; | ||
} | ||
|
||
$context = $this->router->getContext(); | ||
$context->setBaseUrl($this->baseUrl); | ||
$context->setScheme($this->scheme); | ||
$context->setHost($this->host); | ||
$context->setHttpPort($this->httpPort); | ||
$context->setHttpsPort($this->httpsPort); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 doesn't appear to work for any dev site that isn't at root.
For example, all mautibox PRs now redirect haphazardly:
https://mautibox.com/index_dev.php/7210/s/dashboard
Can we remove this? I don't see it as needed.
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.
@alanhartless what do you think?
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'll be a pain for developing if none of the URLs you click on has
index_dev.php
in it. I'd rather fix this to work with paths than just remove it.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.
Agreed... will you be doing that or should I?
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.
#7572