primo commit
This commit is contained in:
		
							
								
								
									
										46
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/CliErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/CliErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * This file is part of the Symfony package. | ||||
|  * | ||||
|  * (c) Fabien Potencier <fabien@symfony.com> | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Symfony\Component\ErrorHandler\ErrorRenderer; | ||||
|  | ||||
| use Symfony\Component\ErrorHandler\Exception\FlattenException; | ||||
| use Symfony\Component\VarDumper\Cloner\VarCloner; | ||||
| use Symfony\Component\VarDumper\Dumper\CliDumper; | ||||
|  | ||||
| // Help opcache.preload discover always-needed symbols | ||||
| class_exists(CliDumper::class); | ||||
|  | ||||
| /** | ||||
|  * @author Nicolas Grekas <p@tchwork.com> | ||||
|  */ | ||||
| class CliErrorRenderer implements ErrorRendererInterface | ||||
| { | ||||
|     public function render(\Throwable $exception): FlattenException | ||||
|     { | ||||
|         $cloner = new VarCloner(); | ||||
|         $dumper = new class() extends CliDumper { | ||||
|             protected function supportsColors(): bool | ||||
|             { | ||||
|                 $outputStream = $this->outputStream; | ||||
|                 $this->outputStream = fopen('php://stdout', 'w'); | ||||
|  | ||||
|                 try { | ||||
|                     return parent::supportsColors(); | ||||
|                 } finally { | ||||
|                     $this->outputStream = $outputStream; | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         return FlattenException::createFromThrowable($exception) | ||||
|             ->setAsString($dumper->dump($cloner->cloneVar($exception), true)); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										37
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/ErrorRendererInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/ErrorRendererInterface.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * This file is part of the Symfony package. | ||||
|  * | ||||
|  * (c) Fabien Potencier <fabien@symfony.com> | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Symfony\Component\ErrorHandler\ErrorRenderer; | ||||
|  | ||||
| use Symfony\Component\ErrorHandler\Exception\FlattenException; | ||||
|  | ||||
| /** | ||||
|  * Formats an exception to be used as response content. | ||||
|  * | ||||
|  * @author Yonel Ceruto <yonelceruto@gmail.com> | ||||
|  */ | ||||
| interface ErrorRendererInterface | ||||
| { | ||||
|     public const IDE_LINK_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', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * Renders a Throwable as a FlattenException. | ||||
|      */ | ||||
|     public function render(\Throwable $exception): FlattenException; | ||||
| } | ||||
							
								
								
									
										115
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/FileLinkFormatter.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/FileLinkFormatter.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,115 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * This file is part of the Symfony package. | ||||
|  * | ||||
|  * (c) Fabien Potencier <fabien@symfony.com> | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Symfony\Component\ErrorHandler\ErrorRenderer; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||||
|  | ||||
| /** | ||||
|  * Formats debug file links. | ||||
|  * | ||||
|  * @author Jérémy Romey <jeremy@free-agent.fr> | ||||
|  * | ||||
|  * @final | ||||
|  */ | ||||
| class FileLinkFormatter | ||||
| { | ||||
|     private array|false $fileLinkFormat; | ||||
|     private ?RequestStack $requestStack = null; | ||||
|     private ?string $baseDir = null; | ||||
|     private \Closure|string|null $urlFormat; | ||||
|  | ||||
|     /** | ||||
|      * @param string|\Closure $urlFormat The URL format, or a closure that returns it on-demand | ||||
|      */ | ||||
|     public function __construct(string|array|null $fileLinkFormat = null, ?RequestStack $requestStack = null, ?string $baseDir = null, string|\Closure|null $urlFormat = null) | ||||
|     { | ||||
|         $fileLinkFormat ??= $_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? ''; | ||||
|  | ||||
|         if (!\is_array($f = $fileLinkFormat)) { | ||||
|             $f = (ErrorRendererInterface::IDE_LINK_FORMATS[$f] ?? $f) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l'; | ||||
|             $i = strpos($f, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f); | ||||
|             $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE); | ||||
|         } | ||||
|  | ||||
|         $this->fileLinkFormat = $fileLinkFormat; | ||||
|         $this->requestStack = $requestStack; | ||||
|         $this->baseDir = $baseDir; | ||||
|         $this->urlFormat = $urlFormat; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string|false | ||||
|      */ | ||||
|     public function format(string $file, int $line): string|bool | ||||
|     { | ||||
|         if ($fmt = $this->getFileLinkFormat()) { | ||||
|             for ($i = 1; isset($fmt[$i]); ++$i) { | ||||
|                 if (str_starts_with($file, $k = $fmt[$i++])) { | ||||
|                     $file = substr_replace($file, $fmt[$i], 0, \strlen($k)); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return strtr($fmt[0], ['%f' => $file, '%l' => $line]); | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @internal | ||||
|      */ | ||||
|     public function __sleep(): array | ||||
|     { | ||||
|         $this->fileLinkFormat = $this->getFileLinkFormat(); | ||||
|  | ||||
|         return ['fileLinkFormat']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @internal | ||||
|      */ | ||||
|     public static function generateUrlFormat(UrlGeneratorInterface $router, string $routeName, string $queryString): ?string | ||||
|     { | ||||
|         try { | ||||
|             return $router->generate($routeName).$queryString; | ||||
|         } catch (\Throwable) { | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function getFileLinkFormat(): array|false | ||||
|     { | ||||
|         if ($this->fileLinkFormat) { | ||||
|             return $this->fileLinkFormat; | ||||
|         } | ||||
|  | ||||
|         if ($this->requestStack && $this->baseDir && $this->urlFormat) { | ||||
|             $request = $this->requestStack->getMainRequest(); | ||||
|  | ||||
|             if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) { | ||||
|                 return [ | ||||
|                     $request->getSchemeAndHttpHost().$this->urlFormat, | ||||
|                     $this->baseDir.\DIRECTORY_SEPARATOR, '', | ||||
|                 ]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|  | ||||
| if (!class_exists(\Symfony\Component\HttpKernel\Debug\FileLinkFormatter::class, false)) { | ||||
|     class_alias(FileLinkFormatter::class, \Symfony\Component\HttpKernel\Debug\FileLinkFormatter::class); | ||||
| } | ||||
							
								
								
									
										353
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/HtmlErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										353
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/HtmlErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										81
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/SerializerErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								libraries/vendor/symfony/error-handler/ErrorRenderer/SerializerErrorRenderer.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,81 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * This file is part of the Symfony package. | ||||
|  * | ||||
|  * (c) Fabien Potencier <fabien@symfony.com> | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Symfony\Component\ErrorHandler\ErrorRenderer; | ||||
|  | ||||
| use Symfony\Component\ErrorHandler\Exception\FlattenException; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Component\Serializer\Exception\NotEncodableValueException; | ||||
| use Symfony\Component\Serializer\SerializerInterface; | ||||
|  | ||||
| /** | ||||
|  * Formats an exception using Serializer for rendering. | ||||
|  * | ||||
|  * @author Nicolas Grekas <p@tchwork.com> | ||||
|  */ | ||||
| class SerializerErrorRenderer implements ErrorRendererInterface | ||||
| { | ||||
|     private SerializerInterface $serializer; | ||||
|     private string|\Closure $format; | ||||
|     private ErrorRendererInterface $fallbackErrorRenderer; | ||||
|     private bool|\Closure $debug; | ||||
|  | ||||
|     /** | ||||
|      * @param string|callable(FlattenException) $format The format as a string or a callable that should return it | ||||
|      *                                                  formats not supported by Request::getMimeTypes() should be given as mime types | ||||
|      * @param bool|callable                     $debug  The debugging mode as a boolean or a callable that should return it | ||||
|      */ | ||||
|     public function __construct(SerializerInterface $serializer, string|callable $format, ?ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false) | ||||
|     { | ||||
|         $this->serializer = $serializer; | ||||
|         $this->format = \is_string($format) ? $format : $format(...); | ||||
|         $this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer(); | ||||
|         $this->debug = \is_bool($debug) ? $debug : $debug(...); | ||||
|     } | ||||
|  | ||||
|     public function render(\Throwable $exception): FlattenException | ||||
|     { | ||||
|         $headers = ['Vary' => 'Accept']; | ||||
|         $debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception); | ||||
|         if ($debug) { | ||||
|             $headers['X-Debug-Exception'] = rawurlencode(substr($exception->getMessage(), 0, 2000)); | ||||
|             $headers['X-Debug-Exception-File'] = rawurlencode($exception->getFile()).':'.$exception->getLine(); | ||||
|         } | ||||
|  | ||||
|         $flattenException = FlattenException::createFromThrowable($exception, null, $headers); | ||||
|  | ||||
|         try { | ||||
|             $format = \is_string($this->format) ? $this->format : ($this->format)($flattenException); | ||||
|             $headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format; | ||||
|  | ||||
|             $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [ | ||||
|                 'exception' => $exception, | ||||
|                 'debug' => $debug, | ||||
|             ])); | ||||
|         } catch (NotEncodableValueException) { | ||||
|             $flattenException = $this->fallbackErrorRenderer->render($exception); | ||||
|         } | ||||
|  | ||||
|         return $flattenException->setHeaders($flattenException->getHeaders() + $headers); | ||||
|     } | ||||
|  | ||||
|     public static function getPreferredFormat(RequestStack $requestStack): \Closure | ||||
|     { | ||||
|         return static function () use ($requestStack) { | ||||
|             if (!$request = $requestStack->getCurrentRequest()) { | ||||
|                 throw new NotEncodableValueException(); | ||||
|             } | ||||
|  | ||||
|             return $request->getPreferredFormat(); | ||||
|         }; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user