[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\HttpKernel\Debug; 13 14 use Symfony\Component\HttpFoundation\Request; 15 use Symfony\Component\HttpFoundation\RequestStack; 16 use Symfony\Component\Routing\Exception\ExceptionInterface; 17 use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 18 19 /** 20 * Formats debug file links. 21 * 22 * @author Jérémy Romey <jeremy@free-agent.fr> 23 */ 24 class FileLinkFormatter implements \Serializable 25 { 26 private $fileLinkFormat; 27 private $requestStack; 28 private $baseDir; 29 private $urlFormat; 30 31 /** 32 * @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand 33 */ 34 public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $urlFormat = null) 35 { 36 $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); 37 if ($fileLinkFormat && !\is_array($fileLinkFormat)) { 38 $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f); 39 $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE); 40 } 41 42 $this->fileLinkFormat = $fileLinkFormat; 43 $this->requestStack = $requestStack; 44 $this->baseDir = $baseDir; 45 $this->urlFormat = $urlFormat; 46 } 47 48 public function format($file, $line) 49 { 50 if ($fmt = $this->getFileLinkFormat()) { 51 for ($i = 1; isset($fmt[$i]); ++$i) { 52 if (0 === strpos($file, $k = $fmt[$i++])) { 53 $file = substr_replace($file, $fmt[$i], 0, \strlen($k)); 54 break; 55 } 56 } 57 58 return strtr($fmt[0], ['%f' => $file, '%l' => $line]); 59 } 60 61 return false; 62 } 63 64 /** 65 * @internal 66 */ 67 public function serialize() 68 { 69 return serialize($this->getFileLinkFormat()); 70 } 71 72 /** 73 * @internal 74 */ 75 public function unserialize($serialized) 76 { 77 if (\PHP_VERSION_ID >= 70000) { 78 $this->fileLinkFormat = unserialize($serialized, ['allowed_classes' => false]); 79 } else { 80 $this->fileLinkFormat = unserialize($serialized); 81 } 82 } 83 84 /** 85 * @internal 86 */ 87 public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString) 88 { 89 try { 90 return $router->generate($routeName).$queryString; 91 } catch (ExceptionInterface $e) { 92 return null; 93 } 94 } 95 96 private function getFileLinkFormat() 97 { 98 if ($this->fileLinkFormat) { 99 return $this->fileLinkFormat; 100 } 101 if ($this->requestStack && $this->baseDir && $this->urlFormat) { 102 $request = $this->requestStack->getMasterRequest(); 103 if ($request instanceof Request) { 104 if ($this->urlFormat instanceof \Closure && !$this->urlFormat = \call_user_func($this->urlFormat)) { 105 return null; 106 } 107 108 return [ 109 $request->getSchemeAndHttpHost().$this->urlFormat, 110 $this->baseDir.\DIRECTORY_SEPARATOR, '', 111 ]; 112 } 113 } 114 115 return null; 116 } 117 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |