-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
BaseUriHelper.php
58 lines (51 loc) · 1.65 KB
/
BaseUriHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}
}