public function evaluate()
{
$resource = $this->getResource();
if ($resource !== null) {
$uri = false;
if ($resource instanceof PersistentResource) {
$uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
}
if ($uri === false) {
throw new TypoScriptException('The specified resource is invalid', 1386458728);
}
return $uri;
}
$path = $this->getPath();
if ($path === null) {
throw new TypoScriptException('Neither "resource" nor "path" were specified', 1386458763);
}
if (strpos($path, 'resource://') === 0) {
$matches = array();
if (preg_match('#^resource://([^/]+)/Public/(.*)#', $path, $matches) !== 1) {
throw new TypoScriptException(sprintf('The specified path "%s" does not point to a public resource.', $path), 1386458851);
}
$package = $matches[1];
$path = $matches[2];
} else {
$package = $this->getPackage();
if ($package === null) {
$controllerContext = $this->tsRuntime->getControllerContext();
/** @var $actionRequest ActionRequest */
$actionRequest = $controllerContext->getRequest();
$package = $actionRequest->getControllerPackageKey();
}
}
$localize = $this->isLocalize();
if ($localize === true) {
$resourcePath = 'resource://' . $package . '/Public/' . $path;
$localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath);
$matches = array();
if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) {
$package = $matches[1];
$path = $matches[2];
}
}
return $this->resourceManager->getPublicPackageResourceUri($package, $path);
}