package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -23,9 +23,6 @@ class_exists(CliDumper::class);
*/
class CliErrorRenderer implements ErrorRendererInterface
{
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$cloner = new VarCloner();

View File

@@ -20,6 +20,16 @@ use Symfony\Component\ErrorHandler\Exception\FlattenException;
*/
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.
*/

View File

@@ -33,41 +33,32 @@ class HtmlErrorRenderer implements ErrorRendererInterface
private const GHOST_HEART = 'M125.91386369681868,8.305165958366445 C128.95033202169043,-0.40540639102854037 140.8469835342744,8.305165958366445 125.91386369681868,19.504526138305664 C110.98208663272044,8.305165958366445 122.87795231771452,-0.40540639102854037 125.91386369681868,8.305165958366445 z';
private const GHOST_PLUS = 'M111.36824226379395,8.969108581542969 L118.69175148010254,8.969108581542969 L118.69175148010254,1.6455793380737305 L126.20429420471191,1.6455793380737305 L126.20429420471191,8.969108581542969 L133.52781105041504,8.969108581542969 L133.52781105041504,16.481630325317383 L126.20429420471191,16.481630325317383 L126.20429420471191,23.805158615112305 L118.69175148010254,23.805158615112305 L118.69175148010254,16.481630325317383 L111.36824226379395,16.481630325317383 z';
private $debug;
private $charset;
private $fileLinkFormat;
private $projectDir;
private $outputBuffer;
private $logger;
private bool|\Closure $debug;
private string $charset;
private string|array|FileLinkFormatter|false $fileLinkFormat;
private ?string $projectDir;
private string|\Closure $outputBuffer;
private ?LoggerInterface $logger;
private static $template = 'views/error.html.php';
private static string $template = 'views/error.html.php';
/**
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
* @param string|FileLinkFormatter|null $fileLinkFormat
* @param bool|callable $outputBuffer The output buffer as a string or a callable that should return it
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
* @param string|callable $outputBuffer The output buffer as a string or a callable that should return it
*/
public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null)
public function __construct(bool|callable $debug = false, string $charset = null, string|FileLinkFormatter $fileLinkFormat = null, string $projectDir = null, string|callable $outputBuffer = '', LoggerInterface $logger = null)
{
if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
}
if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) {
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($outputBuffer)));
}
$this->debug = $debug;
$this->debug = \is_bool($debug) ? $debug : $debug(...);
$this->charset = $charset ?: (\ini_get('default_charset') ?: 'UTF-8');
$this->fileLinkFormat = $fileLinkFormat ?: (\ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'));
$fileLinkFormat ??= $_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? null;
$this->fileLinkFormat = \is_string($fileLinkFormat)
? (ErrorRendererInterface::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: false)
: ($fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false);
$this->projectDir = $projectDir;
$this->outputBuffer = $outputBuffer;
$this->outputBuffer = \is_string($outputBuffer) ? $outputBuffer : $outputBuffer(...);
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$headers = ['Content-Type' => 'text/html; charset='.$this->charset];
@@ -156,9 +147,6 @@ class HtmlErrorRenderer implements ErrorRendererInterface
]);
}
/**
* Formats an array as a string.
*/
private function formatArgs(array $args): string
{
$result = [];
@@ -205,19 +193,14 @@ class HtmlErrorRenderer implements ErrorRendererInterface
{
$file = str_replace('\\', '/', $file);
if (null !== $this->projectDir && 0 === strpos($file, $this->projectDir)) {
if (null !== $this->projectDir && str_starts_with($file, $this->projectDir)) {
return ltrim(substr($file, \strlen($this->projectDir)), '/');
}
return null;
}
/**
* Returns the link for a given file/line pair.
*
* @return string|false
*/
private function getFileLink(string $file, int $line)
private function getFileLink(string $file, int $line): string|false
{
if ($fmt = $this->fileLinkFormat) {
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
@@ -320,7 +303,7 @@ class HtmlErrorRenderer implements ErrorRendererInterface
private function formatLogMessage(string $message, array $context)
{
if ($context && false !== strpos($message, '{')) {
if ($context && str_contains($message, '{')) {
$replacements = [];
foreach ($context as $key => $val) {
if (\is_scalar($val)) {

View File

@@ -24,35 +24,24 @@ use Symfony\Component\Serializer\SerializerInterface;
*/
class SerializerErrorRenderer implements ErrorRendererInterface
{
private $serializer;
private $format;
private $fallbackErrorRenderer;
private $debug;
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, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
public function __construct(SerializerInterface $serializer, string|callable $format, ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false)
{
if (!\is_string($format) && !\is_callable($format)) {
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($format)));
}
if (!\is_bool($debug) && !\is_callable($debug)) {
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
}
$this->serializer = $serializer;
$this->format = $format;
$this->format = \is_string($format) ? $format : $format(...);
$this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
$this->debug = $debug;
$this->debug = \is_bool($debug) ? $debug : $debug(...);
}
/**
* {@inheritdoc}
*/
public function render(\Throwable $exception): FlattenException
{
$headers = [];
@@ -76,7 +65,7 @@ class SerializerErrorRenderer implements ErrorRendererInterface
'debug' => $debug,
]))
->setHeaders($flattenException->getHeaders() + $headers);
} catch (NotEncodableValueException $e) {
} catch (NotEncodableValueException) {
return $this->fallbackErrorRenderer->render($exception);
}
}