Skip to content

Commit

Permalink
BUGFIX: Replace baseUri in cache identifiers
Browse files Browse the repository at this point in the history
Since Flow 6.0 the httpRequest.baseUri is gone and we
need to replace it in the cache identifiers to avoid wrong
cache behavior.
  • Loading branch information
kitsunet committed Feb 7, 2020
1 parent 513a522 commit 88da52e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Classes/Eel/BaseUriHelper.php
@@ -0,0 +1,58 @@
<?php
namespace Neos\Fusion\Eel;

use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Flow\Http\BaseUriProvider;
use Neos\Flow\Http\Helper\RequestInformationHelper;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;

/**
* This is a purely internal helper to provide baseUris for Caching.
* It will be moved to a more sensible package in the future so do
* not rely on the classname for now.
*
* @internal
*/
class BaseUriHelper implements ProtectedContextAwareInterface
{
/**
* @Flow\Inject
* @var BaseUriProvider
*/
protected $baseUriProvider;

/**
* @param ServerRequestInterface|null $fallbackRequest
* @return UriInterface
* @throws \Exception
*/
public function getConfiguredBaseUriOrFallbackToCurrentRequest(ServerRequestInterface $fallbackRequest = null): UriInterface
{
try {
$baseUri = $this->baseUriProvider->getConfiguredBaseUriOrFallbackToCurrentRequest();
} catch (\Exception $e) {
// We are avoiding an exception here in favor of trying more fallback variants.
}

if (isset($baseUri)) {
return $baseUri;
}

if ($fallbackRequest === null) {
throw new \Exception('Could not determine baseUri for current process and no fallback HTTP request was given, maybe running in a CLI command.', 1581002260);
}

return RequestInformationHelper::generateBaseUri($fallbackRequest);
}

/**
* @param string $methodName
* @return bool
*/
public function allowsCallOfMethod($methodName): bool
{
return true;
}
}
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Expand Up @@ -47,3 +47,4 @@ Neos:
I18n: 'Neos\Flow\I18n\EelHelper\TranslationHelper'
File: 'Neos\Eel\Helper\FileHelper'
q: 'Neos\Eel\FlowQuery\FlowQuery::q'
BaseUri: 'Neos\Fusion\Eel\BaseUriHelper'
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Root.fusion
Expand Up @@ -177,5 +177,5 @@ prototype(Neos.Fusion:ResourceUri) {
#
prototype(Neos.Fusion:GlobalCacheIdentifiers) < prototype(Neos.Fusion:RawArray) {
format = ${request.format}
baseUri = ${String.toString(request.httpRequest.baseUri)}
baseUri = ${String.toString(BaseUri.getConfiguredBaseUriOrFallbackToCurrentRequest(request.httpRequest))}
}

0 comments on commit 88da52e

Please sign in to comment.