comparison vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
11 11
12 namespace Symfony\Component\HttpKernel\Fragment; 12 namespace Symfony\Component\HttpKernel\Fragment;
13 13
14 use Symfony\Component\HttpFoundation\Request; 14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\HttpFoundation\Response; 15 use Symfony\Component\HttpFoundation\Response;
16 use Symfony\Component\Templating\EngineInterface;
17 use Symfony\Component\HttpKernel\Controller\ControllerReference; 16 use Symfony\Component\HttpKernel\Controller\ControllerReference;
18 use Symfony\Component\HttpKernel\UriSigner; 17 use Symfony\Component\HttpKernel\UriSigner;
18 use Symfony\Component\Templating\EngineInterface;
19 use Twig\Environment; 19 use Twig\Environment;
20 use Twig\Error\LoaderError; 20 use Twig\Error\LoaderError;
21 use Twig\Loader\ExistsLoaderInterface; 21 use Twig\Loader\ExistsLoaderInterface;
22 22
23 /** 23 /**
79 * 79 *
80 * * default: The default content (it can be a template name or the content) 80 * * default: The default content (it can be a template name or the content)
81 * * id: An optional hx:include tag id attribute 81 * * id: An optional hx:include tag id attribute
82 * * attributes: An optional array of hx:include tag attributes 82 * * attributes: An optional array of hx:include tag attributes
83 */ 83 */
84 public function render($uri, Request $request, array $options = array()) 84 public function render($uri, Request $request, array $options = [])
85 { 85 {
86 if ($uri instanceof ControllerReference) { 86 if ($uri instanceof ControllerReference) {
87 if (null === $this->signer) { 87 if (null === $this->signer) {
88 throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.'); 88 throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.');
89 } 89 }
90 90
91 // we need to sign the absolute URI, but want to return the path only. 91 // we need to sign the absolute URI, but want to return the path only.
92 $uri = substr($this->signer->sign($this->generateFragmentUri($uri, $request, true)), strlen($request->getSchemeAndHttpHost())); 92 $uri = substr($this->signer->sign($this->generateFragmentUri($uri, $request, true)), \strlen($request->getSchemeAndHttpHost()));
93 } 93 }
94 94
95 // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content. 95 // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
96 $uri = str_replace('&', '&', $uri); 96 $uri = str_replace('&', '&', $uri);
97 97
100 $content = $this->templating->render($template); 100 $content = $this->templating->render($template);
101 } else { 101 } else {
102 $content = $template; 102 $content = $template;
103 } 103 }
104 104
105 $attributes = isset($options['attributes']) && is_array($options['attributes']) ? $options['attributes'] : array(); 105 $attributes = isset($options['attributes']) && \is_array($options['attributes']) ? $options['attributes'] : [];
106 if (isset($options['id']) && $options['id']) { 106 if (isset($options['id']) && $options['id']) {
107 $attributes['id'] = $options['id']; 107 $attributes['id'] = $options['id'];
108 } 108 }
109 $renderedAttributes = ''; 109 $renderedAttributes = '';
110 if (count($attributes) > 0) { 110 if (\count($attributes) > 0) {
111 $flags = ENT_QUOTES | ENT_SUBSTITUTE; 111 $flags = ENT_QUOTES | ENT_SUBSTITUTE;
112 foreach ($attributes as $attribute => $value) { 112 foreach ($attributes as $attribute => $value) {
113 $renderedAttributes .= sprintf( 113 $renderedAttributes .= sprintf(
114 ' %s="%s"', 114 ' %s="%s"',
115 htmlspecialchars($attribute, $flags, $this->charset, false), 115 htmlspecialchars($attribute, $flags, $this->charset, false),
129 private function templateExists($template) 129 private function templateExists($template)
130 { 130 {
131 if ($this->templating instanceof EngineInterface) { 131 if ($this->templating instanceof EngineInterface) {
132 try { 132 try {
133 return $this->templating->exists($template); 133 return $this->templating->exists($template);
134 } catch (\InvalidArgumentException $e) { 134 } catch (\Exception $e) {
135 return false; 135 return false;
136 } 136 }
137 } 137 }
138 138
139 $loader = $this->templating->getLoader(); 139 $loader = $this->templating->getLoader();