PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / Debug / FileLinkFormatter.php
matomo / app / vendor / prefixed / symfony / http-kernel / Debug Last commit date
FileLinkFormatter.php 1 year ago TraceableEventDispatcher.php 1 year ago
FileLinkFormatter.php
91 lines
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 namespace Matomo\Dependencies\Symfony\Component\HttpKernel\Debug;
12
13 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request;
14 use Matomo\Dependencies\Symfony\Component\HttpFoundation\RequestStack;
15 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
16 /**
17 * Formats debug file links.
18 *
19 * @author Jérémy Romey <jeremy@free-agent.fr>
20 *
21 * @final
22 */
23 class FileLinkFormatter
24 {
25 private const FORMATS = ['textmate' => 'txmt://open?url=file://%f&line=%l', 'macvim' => 'mvim://open?url=file://%f&line=%l', 'emacs' => 'emacs://open?url=file://%f&line=%l', 'sublime' => 'subl://open?url=file://%f&line=%l', 'phpstorm' => 'phpstorm://open?file=%f&line=%l', 'atom' => 'atom://core/open/file?filename=%f&line=%l', 'vscode' => 'vscode://file/%f:%l'];
26 private $fileLinkFormat;
27 private $requestStack;
28 private $baseDir;
29 private $urlFormat;
30 /**
31 * @param string|array|null $fileLinkFormat
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, ?string $baseDir = null, $urlFormat = null)
35 {
36 if (!\is_array($fileLinkFormat) && ($fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: \ini_get('xdebug.file_link_format')) ?: get_cfg_var('xdebug.file_link_format'))) {
37 $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
38 $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
39 }
40 $this->fileLinkFormat = $fileLinkFormat;
41 $this->requestStack = $requestStack;
42 $this->baseDir = $baseDir;
43 $this->urlFormat = $urlFormat;
44 }
45 public function format(string $file, int $line)
46 {
47 if ($fmt = $this->getFileLinkFormat()) {
48 for ($i = 1; isset($fmt[$i]); ++$i) {
49 if (str_starts_with($file, $k = $fmt[$i++])) {
50 $file = substr_replace($file, $fmt[$i], 0, \strlen($k));
51 break;
52 }
53 }
54 return strtr($fmt[0], ['%f' => $file, '%l' => $line]);
55 }
56 return \false;
57 }
58 /**
59 * @internal
60 */
61 public function __sleep() : array
62 {
63 $this->fileLinkFormat = $this->getFileLinkFormat();
64 return ['fileLinkFormat'];
65 }
66 /**
67 * @internal
68 */
69 public static function generateUrlFormat(UrlGeneratorInterface $router, string $routeName, string $queryString) : ?string
70 {
71 try {
72 return $router->generate($routeName) . $queryString;
73 } catch (\Throwable $e) {
74 return null;
75 }
76 }
77 private function getFileLinkFormat()
78 {
79 if ($this->fileLinkFormat) {
80 return $this->fileLinkFormat;
81 }
82 if ($this->requestStack && $this->baseDir && $this->urlFormat) {
83 $request = $this->requestStack->getMainRequest();
84 if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || ($this->urlFormat = ($this->urlFormat)()))) {
85 return [$request->getSchemeAndHttpHost() . $this->urlFormat, $this->baseDir . \DIRECTORY_SEPARATOR, ''];
86 }
87 }
88 return null;
89 }
90 }
91