Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Ssi.php

class Ssi

Ssi implements the SSI capabilities to Request and Response instances.

@author Sebastian Krebs <krebs.seb@gmail.com>

Hierarchy

  • class \Symfony\Component\HttpKernel\HttpCache\AbstractSurrogate implements \Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
    • class \Symfony\Component\HttpKernel\HttpCache\Ssi extends \Symfony\Component\HttpKernel\HttpCache\AbstractSurrogate

Expanded class hierarchy of Ssi

6 string references to 'Ssi'
Ssi::getName in vendor/symfony/http-kernel/HttpCache/Ssi.php
Returns surrogate name.
Ssi::process in vendor/symfony/http-kernel/HttpCache/Ssi.php
Replaces a Response Surrogate tags with the included resource content.
SsiFragmentRenderer::getName in vendor/symfony/http-kernel/Fragment/SsiFragmentRenderer.php
Gets the name of the strategy.
xa3.php in core/lib/Drupal/Component/Transliteration/data/xa3.php
xa4.php in core/lib/Drupal/Component/Transliteration/data/xa4.php

... See full list

File

vendor/symfony/http-kernel/HttpCache/Ssi.php, line 22

Namespace

Symfony\Component\HttpKernel\HttpCache
View source
class Ssi extends AbstractSurrogate {
    public function getName() : string {
        return 'ssi';
    }
    public function addSurrogateControl(Response $response) : void {
        if (str_contains($response->getContent(), '<!--#include')) {
            $response->headers
                ->set('Surrogate-Control', 'content="SSI/1.0"');
        }
    }
    public function renderIncludeTag(string $uri, ?string $alt = null, bool $ignoreErrors = true, string $comment = '') : string {
        return \sprintf('<!--#include virtual="%s" -->', $uri);
    }
    public function process(Request $request, Response $response) : Response {
        $type = $response->headers
            ->get('Content-Type');
        if (!$type) {
            $type = 'text/html';
        }
        $parts = explode(';', $type);
        if (!\in_array($parts[0], $this->contentTypes, true)) {
            return $response;
        }
        // we don't use a proper XML parser here as we can have SSI tags in a plain text response
        $content = $response->getContent();
        $boundary = self::generateBodyEvalBoundary();
        $chunks = preg_split('#<!--\\#include\\s+(.*?)\\s*-->#', $content, -1, \PREG_SPLIT_DELIM_CAPTURE);
        $i = 1;
        while (isset($chunks[$i])) {
            $options = [];
            preg_match_all('/(virtual)="([^"]*?)"/', $chunks[$i], $matches, \PREG_SET_ORDER);
            foreach ($matches as $set) {
                $options[$set[1]] = $set[2];
            }
            if (!isset($options['virtual'])) {
                throw new \RuntimeException('Unable to process an SSI tag without a "virtual" attribute.');
            }
            $chunks[$i] = $boundary . $options['virtual'] . "\n\n\n";
            $i += 2;
        }
        $content = $boundary . implode('', $chunks) . $boundary;
        $response->setContent($content);
        $response->headers
            ->set('X-Body-Eval', 'SSI');
        // remove SSI/1.0 from the Surrogate-Control header
        $this->removeFromControl($response);
        return $response;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractSurrogate::addSurrogateCapability public function Adds Surrogate-capability to the given Request. Overrides SurrogateInterface::addSurrogateCapability
AbstractSurrogate::createCacheStrategy public function Returns a new cache strategy instance. Overrides SurrogateInterface::createCacheStrategy
AbstractSurrogate::generateBodyEvalBoundary protected static function
AbstractSurrogate::handle public function Handles a Surrogate from the cache. Overrides SurrogateInterface::handle
AbstractSurrogate::hasSurrogateCapability public function Checks that at least one surrogate has Surrogate capability. Overrides SurrogateInterface::hasSurrogateCapability
AbstractSurrogate::needsParsing public function Checks that the Response needs to be parsed for Surrogate tags. Overrides SurrogateInterface::needsParsing
AbstractSurrogate::removeFromControl protected function Remove the Surrogate from the Surrogate-Control header.
AbstractSurrogate::__construct public function
Ssi::addSurrogateControl public function Adds HTTP headers to specify that the Response needs to be parsed for Surrogate. Overrides SurrogateInterface::addSurrogateControl
Ssi::getName public function Returns surrogate name. Overrides SurrogateInterface::getName
Ssi::process public function Replaces a Response Surrogate tags with the included resource content. Overrides SurrogateInterface::process
Ssi::renderIncludeTag public function Renders a Surrogate tag. Overrides SurrogateInterface::renderIncludeTag
RSS feed
Powered by Drupal