Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
AbstractSurrogate.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel\HttpCache;
013
014 use Symfony\Component\HttpFoundation\Request;
015 use Symfony\Component\HttpFoundation\Response;
016 use Symfony\Component\HttpKernel\HttpKernelInterface;
017
018 /**
019 * Abstract class implementing Surrogate capabilities to Request and Response instances.
020 *
021 * @author Fabien Potencier <fabien@symfony.com>
022 * @author Robin Chalas <robin.chalas@gmail.com>
023 */
024 abstract class AbstractSurrogate implements SurrogateInterface
025 {
026 protected $contentTypes;
027 protected $phpEscapeMap = [
028 ['<?', '<%', '<s', '<S'],
029 ['<?php echo "<?"; ?>', '<?php echo "<%"; ?>', '<?php echo "<s"; ?>', '<?php echo "<S"; ?>'],
030 ];
031
032 /**
033 * @param array $contentTypes An array of content-type that should be parsed for Surrogate information
034 * (default: text/html, text/xml, application/xhtml+xml, and application/xml)
035 */
036 public function __construct(array $contentTypes = ['text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'])
037 {
038 $this->contentTypes = $contentTypes;
039 }
040
041 /**
042 * Returns a new cache strategy instance.
043 *
044 * @return ResponseCacheStrategyInterface A ResponseCacheStrategyInterface instance
045 */
046 public function createCacheStrategy()
047 {
048 return new ResponseCacheStrategy();
049 }
050
051 /**
052 * {@inheritdoc}
053 */
054 public function hasSurrogateCapability(Request $request)
055 {
056 if (null === $value = $request->headers->get('Surrogate-Capability')) {
057 return false;
058 }
059
060 return false !== strpos($value, sprintf('%s/1.0', strtoupper($this->getName())));
061 }
062
063 /**
064 * {@inheritdoc}
065 */
066 public function addSurrogateCapability(Request $request)
067 {
068 $current = $request->headers->get('Surrogate-Capability');
069 $new = sprintf('symfony="%s/1.0"', strtoupper($this->getName()));
070
071 $request->headers->set('Surrogate-Capability', $current ? $current.', '.$new : $new);
072 }
073
074 /**
075 * {@inheritdoc}
076 */
077 public function needsParsing(Response $response)
078 {
079 if (!$control = $response->headers->get('Surrogate-Control')) {
080 return false;
081 }
082
083 $pattern = sprintf('#content="[^"]*%s/1.0[^"]*"#', strtoupper($this->getName()));
084
085 return (bool) preg_match($pattern, $control);
086 }
087
088 /**
089 * {@inheritdoc}
090 */
091 public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
092 {
093 $subRequest = Request::create($uri, Request::METHOD_GET, [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all());
094
095 try {
096 $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
097
098 if (!$response->isSuccessful()) {
099 throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
100 }
101
102 return $response->getContent();
103 } catch (\Exception $e) {
104 if ($alt) {
105 return $this->handle($cache, $alt, '', $ignoreErrors);
106 }
107
108 if (!$ignoreErrors) {
109 throw $e;
110 }
111 }
112
113 return '';
114 }
115
116 /**
117 * Remove the Surrogate from the Surrogate-Control header.
118 */
119 protected function removeFromControl(Response $response)
120 {
121 if (!$response->headers->has('Surrogate-Control')) {
122 return;
123 }
124
125 $value = $response->headers->get('Surrogate-Control');
126 $upperName = strtoupper($this->getName());
127
128 if (sprintf('content="%s/1.0"', $upperName) == $value) {
129 $response->headers->remove('Surrogate-Control');
130 } elseif (preg_match(sprintf('#,\s*content="%s/1.0"#', $upperName), $value)) {
131 $response->headers->set('Surrogate-Control', preg_replace(sprintf('#,\s*content="%s/1.0"#', $upperName), '', $value));
132 } elseif (preg_match(sprintf('#content="%s/1.0",\s*#', $upperName), $value)) {
133 $response->headers->set('Surrogate-Control', preg_replace(sprintf('#content="%s/1.0",\s*#', $upperName), '', $value));
134 }
135 }
136 }
137