FluidTYPO3\Vhs\Service\AssetService::generateTagForAssetType PHP Method

generateTagForAssetType() protected method

protected generateTagForAssetType ( string $type, string $content, string $file = null, string $integrity = null ) : string
$type string
$content string
$file string
$integrity string
return string
    protected function generateTagForAssetType($type, $content, $file = null, $integrity = null)
    {
        /** @var TagBuilder $tagBuilder */
        $tagBuilder = $this->objectManager->get(TagBuilder::class);
        if (null === $file && true === empty($content)) {
            $content = '<!-- Empty tag content -->';
        }
        switch ($type) {
            case 'js':
                $tagBuilder->setTagName('script');
                $tagBuilder->forceClosingTag(true);
                $tagBuilder->addAttribute('type', 'text/javascript');
                if (null === $file) {
                    $tagBuilder->setContent($content);
                } else {
                    $tagBuilder->addAttribute('src', $file);
                }
                if (null !== $integrity && !empty($integrity)) {
                    $tagBuilder->addAttribute('integrity', $integrity);
                }
                break;
            case 'css':
                if (null === $file) {
                    $tagBuilder->setTagName('style');
                    $tagBuilder->forceClosingTag(true);
                    $tagBuilder->addAttribute('type', 'text/css');
                    $tagBuilder->setContent($content);
                } else {
                    $tagBuilder->forceClosingTag(false);
                    $tagBuilder->setTagName('link');
                    $tagBuilder->addAttribute('rel', 'stylesheet');
                    $tagBuilder->addAttribute('href', $file);
                }
                if (null !== $integrity && !empty($integrity)) {
                    $tagBuilder->addAttribute('integrity', $integrity);
                }
                break;
            case 'meta':
                $tagBuilder->forceClosingTag(false);
                $tagBuilder->setTagName('meta');
                break;
            default:
                if (null === $file) {
                    return $content;
                } else {
                    throw new \RuntimeException('Attempt to include file based asset with unknown type ("' . $type . '")', 1358645219);
                }
                break;
        }
        return $tagBuilder->render();
    }