Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / http-kernel / Debug / FileLinkFormatter.php
index 03e3cf89549bacf84cb617e8da57cd36ae79c045..b3c2595b0d072a8040218a2d23f3e0d3f5ed357c 100644 (file)
@@ -13,6 +13,8 @@ namespace Symfony\Component\HttpKernel\Debug;
 
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Routing\Exception\ExceptionInterface;
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 
 /**
  * Formats debug file links.
@@ -26,11 +28,14 @@ class FileLinkFormatter implements \Serializable
     private $baseDir;
     private $urlFormat;
 
+    /**
+     * @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
+     */
     public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $urlFormat = null)
     {
         $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
-        if ($fileLinkFormat && !is_array($fileLinkFormat)) {
-            $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
+        if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
+            $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
             $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
         }
 
@@ -45,7 +50,7 @@ class FileLinkFormatter implements \Serializable
         if ($fmt = $this->getFileLinkFormat()) {
             for ($i = 1; isset($fmt[$i]); ++$i) {
                 if (0 === strpos($file, $k = $fmt[$i++])) {
-                    $file = substr_replace($file, $fmt[$i], 0, strlen($k));
+                    $file = substr_replace($file, $fmt[$i], 0, \strlen($k));
                     break;
                 }
             }
@@ -63,7 +68,23 @@ class FileLinkFormatter implements \Serializable
 
     public function unserialize($serialized)
     {
-        $this->fileLinkFormat = unserialize($serialized);
+        if (\PHP_VERSION_ID >= 70000) {
+            $this->fileLinkFormat = unserialize($serialized, array('allowed_classes' => false));
+        } else {
+            $this->fileLinkFormat = unserialize($serialized);
+        }
+    }
+
+    /**
+     * @internal
+     */
+    public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString)
+    {
+        try {
+            return $router->generate($routeName).$queryString;
+        } catch (ExceptionInterface $e) {
+            return null;
+        }
     }
 
     private function getFileLinkFormat()
@@ -74,9 +95,13 @@ class FileLinkFormatter implements \Serializable
         if ($this->requestStack && $this->baseDir && $this->urlFormat) {
             $request = $this->requestStack->getMasterRequest();
             if ($request instanceof Request) {
+                if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) {
+                    return;
+                }
+
                 return array(
-                    $request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
-                    $this->baseDir.DIRECTORY_SEPARATOR, '',
+                    $request->getSchemeAndHttpHost().$request->getBasePath().$this->urlFormat,
+                    $this->baseDir.\DIRECTORY_SEPARATOR, '',
                 );
             }
         }