/
MultisiteFileSystemSymlinkTarget.php
59 lines (50 loc) · 1.76 KB
/
MultisiteFileSystemSymlinkTarget.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
59
<?php
namespace Flowpack\DecoupledContentStore\Transfer\Resource\Target;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\ResourceManagement\Target\FileSystemSymlinkTarget;
class MultisiteFileSystemSymlinkTarget extends FileSystemSymlinkTarget
{
/**
* @var string
*/
protected $overrideHttpBaseUri;
/**
* Override the baseUri of resource publishing targets
*
* This is needed because the rendering might be executed in a CLI request that doesn't have
* a "current" base URI. It's also needed to render nodes for multiple sites.
*
* @param string $baseUri
* @throws \Neos\Utility\Exception\PropertyNotAccessibleException
*/
public static function injectBaseUriIntoRelevantResourcePublishingTargets(string $baseUri, ResourceManager $resourceManager)
{
// Make sure the base URI ends with a slash
$baseUri = rtrim($baseUri, '/') . '/';
$collections = $resourceManager->getCollections();
/** @var \Neos\Flow\ResourceManagement\Collection $collection */
foreach ($collections as $collection) {
$target = $collection->getTarget();
if ($target instanceof MultisiteFileSystemSymlinkTarget) {
$target->setOverrideHttpBaseUri($baseUri);
}
}
}
/**
* @return string
*/
protected function getResourcesBaseUri()
{
if ($this->overrideHttpBaseUri === null) {
return parent::getResourcesBaseUri();
}
return $this->overrideHttpBaseUri . $this->baseUri;
}
/**
* @param string $overrideHttpBaseUri
*/
public function setOverrideHttpBaseUri(string $overrideHttpBaseUri)
{
$this->overrideHttpBaseUri = $overrideHttpBaseUri;
}
}