Skip to content

Commit

Permalink
MERGE Merge branch '5.0' into 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kdambekalns committed Feb 14, 2020
2 parents 80b1aea + 88da52e commit 6ae035e
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ prototype(Neos.Fusion:Fragment) < prototype(Neos.Fusion:Component) {
#
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 6ae035e

Please sign in to comment.