laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,44 @@
<?php
$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->notName('GitConflictController.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);

View File

@@ -0,0 +1,114 @@
# Changelog
All notable changes to `flare-client-php` will be documented in this file
## 1.9.1 - 2021-09-13
- let `report` return the created report
## 1.9.0 - 2021-09-13
- add report tracking uuid
## 1.8.1 - 2021-05-31
- improve compatibility with Symfony 5.3
## 1.8.0 - 2021-04-30
- add ability to ignore errors and exceptions (#23)
- fix curl parameters
## 1.7.0 - 2021-04-12
- use new Flare endpoint and allow 1 redirect to it
## 1.6.1 - 2021-04-08
- make `censorRequestBodyFields` chainable
## 1.6.0 - 2021-04-08
- add ability to censor request body fields (#18)
## 1.5.0 - 2021-03-31
- add `determineVersionUsing`
## 1.4.0 - 2021-02-16
- remove custom grouping
## 1.3.7 - 2020-10-21
- allow PHP 8
## 1.3.6 - 2020-09-18
- remove `larapack/dd` (#15)
## 1.3.5 - 2020-08-26
- allow Laravel 8 (#13)
## 1.3.4 - 2020-07-14
- use directory separator constant
## 1.3.3 - 2020-07-14
- fix tests by requiring symfony/mime
- display real exception class for view errors (see https://github.com/facade/ignition/discussions/237)
## 1.3.2 - 2020-03-02
- allow L7
## 1.3.1 - 2019-12-15
- allow var-dumper v5.0
## 1.3.0 - 2019-11-27
- Allow custom grouping types
## 1.2.1 - 2019-11-19
- Let `registerFlareHandlers` return $this
## 1.2.0 - 2019-11-19
- Add `registerFlareHandlers` method to register error and exception handlers in non-Laravel applications
- Fix get requests with query parameters (#4)
## 1.1.2 - 2019-11-08
- Ignore invalid mime type detection issues
## 1.1.1 - 2019-10-07
- Wrap filesize detection in try-catch block
## 1.1.0 - 2019-09-27
- Add ability to log messages
## 1.0.4 - 2019-09-11
- Fixes an issue when sending exceptions inside a queue worker
## 1.0.3 - 2019-09-05
- Ensure valid session data
## 1.0.2 - 2019-09-05
- Fix error when uploading multiple files using an array name
## 1.0.1 - 2019-09-02
- Fix issue with uploaded files in request context
## 1.0.0 - 2019-08-30
- initial release

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Facade <info@facade.company>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,36 @@
# Send PHP errors to Flare
[![Latest Version on Packagist](https://img.shields.io/packagist/v/facade/flare-client-php.svg?style=flat-square)](https://packagist.org/packages/facade/flare-client-php)
![Tests](https://github.com/facade/flare-client-php/workflows/Run%20tests/badge.svg)
[![Total Downloads](https://img.shields.io/packagist/dt/facade/flare-client-php.svg?style=flat-square)](https://packagist.org/packages/facade/flare-client-php)
This repository contains a PHP client to send PHP errors to [Flare](https://flareapp.io).
![Screenshot of error in Flare](https://facade.github.io/flare-client-php/screenshot.png)
## Documentation
You can find the documentation of this package at [the docs of Flare](https://flareapp.io/docs/general/projects).
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Testing
``` bash
composer test
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email support@flareapp.io instead of using the issue tracker.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

View File

@@ -0,0 +1,52 @@
{
"name": "facade/flare-client-php",
"description": "Send PHP errors to Flare",
"keywords": [
"facade",
"flare",
"exception",
"reporting"
],
"homepage": "https://github.com/facade/flare-client-php",
"license": "MIT",
"require": {
"php": "^7.1|^8.0",
"facade/ignition-contracts": "~1.0",
"illuminate/pipeline": "^5.5|^6.0|^7.0|^8.0",
"symfony/http-foundation": "^3.3|^4.1|^5.0",
"symfony/mime": "^3.4|^4.0|^5.1",
"symfony/var-dumper": "^3.4|^4.0|^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"spatie/phpunit-snapshot-assertions": "^2.0",
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4": {
"Facade\\FlareClient\\": "src"
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Facade\\FlareClient\\Tests\\": "tests"
}
},
"scripts": {
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Facade\FlareClient;
use Exception;
use Facade\FlareClient\Http\Client;
use Facade\FlareClient\Truncation\ReportTrimmer;
class Api
{
/** @var \Facade\FlareClient\Http\Client */
protected $client;
/** @var bool */
public static $sendInBatches = true;
/** @var array */
protected $queue = [];
public function __construct(Client $client)
{
$this->client = $client;
register_shutdown_function([$this, 'sendQueuedReports']);
}
public static function sendReportsInBatches(bool $batchSending = true)
{
static::$sendInBatches = $batchSending;
}
public function report(Report $report)
{
try {
if (static::$sendInBatches) {
$this->addReportToQueue($report);
} else {
$this->sendReportToApi($report);
}
} catch (Exception $e) {
//
}
}
public function sendTestReport(Report $report)
{
$this->sendReportToApi($report);
}
protected function addReportToQueue(Report $report)
{
$this->queue[] = $report;
}
public function sendQueuedReports()
{
try {
foreach ($this->queue as $report) {
$this->sendReportToApi($report);
}
} catch (Exception $e) {
//
} finally {
$this->queue = [];
}
}
protected function sendReportToApi(Report $report)
{
$this->client->post('reports', $this->truncateReport($report->toArray()));
}
protected function truncateReport(array $payload): array
{
return (new ReportTrimmer())->trim($payload);
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Facade\FlareClient\Concerns;
trait HasContext
{
/** @var string|null */
private $messageLevel;
/** @var string|null */
private $stage;
/** @var array */
private $userProvidedContext = [];
public function stage(?string $stage)
{
$this->stage = $stage;
return $this;
}
public function messageLevel(?string $messageLevel)
{
$this->messageLevel = $messageLevel;
return $this;
}
public function getGroup(string $groupName = 'context', $default = []): array
{
return $this->userProvidedContext[$groupName] ?? $default;
}
public function context($key, $value)
{
return $this->group('context', [$key => $value]);
}
public function group(string $groupName, array $properties)
{
$group = $this->userProvidedContext[$groupName] ?? [];
$this->userProvidedContext[$groupName] = array_merge_recursive_distinct(
$group,
$properties
);
return $this;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Facade\FlareClient\Concerns;
use Facade\FlareClient\Time\SystemTime;
use Facade\FlareClient\Time\Time;
trait UsesTime
{
/** @var \Facade\FlareClient\Time\Time */
public static $time;
public static function useTime(Time $time)
{
self::$time = $time;
}
public function getCurrentTime(): int
{
$time = self::$time ?? new SystemTime();
return $time->getCurrentTime();
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Facade\FlareClient\Context;
class ConsoleContext implements ContextInterface
{
/** @var array */
private $arguments = [];
public function __construct(array $arguments = [])
{
$this->arguments = $arguments;
}
public function toArray(): array
{
return [
'arguments' => $this->arguments,
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Facade\FlareClient\Context;
class ContextContextDetector implements ContextDetectorInterface
{
public function detectCurrentContext(): ContextInterface
{
if ($this->runningInConsole()) {
return new ConsoleContext($_SERVER['argv'] ?? []);
}
return new RequestContext();
}
private function runningInConsole(): bool
{
if (isset($_ENV['APP_RUNNING_IN_CONSOLE'])) {
return $_ENV['APP_RUNNING_IN_CONSOLE'] === 'true';
}
if (isset($_ENV['FLARE_FAKE_WEB_REQUEST'])) {
return false;
}
return in_array(php_sapi_name(), ['cli', 'phpdb']);
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\FlareClient\Context;
interface ContextDetectorInterface
{
public function detectCurrentContext(): ContextInterface;
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\FlareClient\Context;
interface ContextInterface
{
public function toArray(): array;
}

View File

@@ -0,0 +1,126 @@
<?php
namespace Facade\FlareClient\Context;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Throwable;
class RequestContext implements ContextInterface
{
/** @var \Symfony\Component\HttpFoundation\Request|null */
protected $request;
public function __construct(Request $request = null)
{
$this->request = $request ?? Request::createFromGlobals();
}
public function getRequest(): array
{
return [
'url' => $this->request->getUri(),
'ip' => $this->request->getClientIp(),
'method' => $this->request->getMethod(),
'useragent' => $this->request->headers->get('User-Agent'),
];
}
private function getFiles(): array
{
if (is_null($this->request->files)) {
return [];
}
return $this->mapFiles($this->request->files->all());
}
protected function mapFiles(array $files)
{
return array_map(function ($file) {
if (is_array($file)) {
return $this->mapFiles($file);
}
if (! $file instanceof UploadedFile) {
return;
}
try {
$fileSize = $file->getSize();
} catch (\RuntimeException $e) {
$fileSize = 0;
}
try {
$mimeType = $file->getMimeType();
} catch (InvalidArgumentException $e) {
$mimeType = 'undefined';
}
return [
'pathname' => $file->getPathname(),
'size' => $fileSize,
'mimeType' => $mimeType,
];
}, $files);
}
public function getSession(): array
{
try {
$session = $this->request->getSession();
} catch (\Exception $exception) {
$session = [];
}
return $session ? $this->getValidSessionData($session) : [];
}
/**
* @param SessionInterface $session
* @return array
*/
protected function getValidSessionData($session): array
{
try {
json_encode($session->all());
} catch (Throwable $e) {
return [];
}
return $session->all();
}
public function getCookies(): array
{
return $this->request->cookies->all();
}
public function getHeaders(): array
{
return $this->request->headers->all();
}
public function getRequestData(): array
{
return [
'queryString' => $this->request->query->all(),
'body' => $this->request->request->all(),
'files' => $this->getFiles(),
];
}
public function toArray(): array
{
return [
'request' => $this->getRequest(),
'request_data' => $this->getRequestData(),
'headers' => $this->getHeaders(),
'cookies' => $this->getCookies(),
'session' => $this->getSession(),
];
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\FlareClient\Contracts;
interface ProvidesFlareContext
{
public function context(): array;
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Facade\FlareClient\Enums;
/** @deprecated */
class GroupingTypes
{
public const TOP_FRAME = 'topFrame';
public const EXCEPTION = 'exceptionClass';
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Facade\FlareClient\Enums;
class MessageLevels
{
public const INFO = 'info';
public const DEBUG = 'debug';
public const WARNING = 'warning';
public const ERROR = 'error';
public const CRITICAL = 'critical';
}

333
vendor/facade/flare-client-php/src/Flare.php vendored Executable file
View File

@@ -0,0 +1,333 @@
<?php
namespace Facade\FlareClient;
use Error;
use ErrorException;
use Exception;
use Facade\FlareClient\Concerns\HasContext;
use Facade\FlareClient\Context\ContextContextDetector;
use Facade\FlareClient\Context\ContextDetectorInterface;
use Facade\FlareClient\Enums\MessageLevels;
use Facade\FlareClient\Glows\Glow;
use Facade\FlareClient\Glows\Recorder;
use Facade\FlareClient\Http\Client;
use Facade\FlareClient\Middleware\AddGlows;
use Facade\FlareClient\Middleware\AnonymizeIp;
use Facade\FlareClient\Middleware\CensorRequestBodyFields;
use Illuminate\Contracts\Container\Container;
use Illuminate\Pipeline\Pipeline;
use Throwable;
class Flare
{
use HasContext;
/** @var \Facade\FlareClient\Http\Client */
protected $client;
/** @var \Facade\FlareClient\Api */
protected $api;
/** @var array */
protected $middleware = [];
/** @var \Facade\FlareClient\Glows\Recorder */
protected $recorder;
/** @var string */
protected $applicationPath;
/** @var \Illuminate\Contracts\Container\Container|null */
protected $container;
/** @var ContextDetectorInterface */
protected $contextDetector;
/** @var callable|null */
protected $previousExceptionHandler;
/** @var callable|null */
protected $previousErrorHandler;
/** @var callable|null */
protected $determineVersionCallable;
/** @var int|null */
protected $reportErrorLevels;
/** @var callable|null */
protected $filterExceptionsCallable;
/** @var callable|null */
protected $filterReportsCallable;
public static function register(string $apiKey, string $apiSecret = null, ContextDetectorInterface $contextDetector = null, Container $container = null)
{
$client = new Client($apiKey, $apiSecret);
return new static($client, $contextDetector, $container);
}
public function determineVersionUsing($determineVersionCallable)
{
$this->determineVersionCallable = $determineVersionCallable;
}
public function reportErrorLevels(int $reportErrorLevels)
{
$this->reportErrorLevels = $reportErrorLevels;
}
public function filterExceptionsUsing(callable $filterExceptionsCallable)
{
$this->filterExceptionsCallable = $filterExceptionsCallable;
}
public function filterReportsUsing(callable $filterReportsCallable)
{
$this->filterReportsCallable = $filterReportsCallable;
}
/**
* @return null|string
*/
public function version()
{
if (! $this->determineVersionCallable) {
return null;
}
return ($this->determineVersionCallable)();
}
public function __construct(Client $client, ContextDetectorInterface $contextDetector = null, Container $container = null, array $middleware = [])
{
$this->client = $client;
$this->recorder = new Recorder();
$this->contextDetector = $contextDetector ?? new ContextContextDetector();
$this->container = $container;
$this->middleware = $middleware;
$this->api = new Api($this->client);
$this->registerDefaultMiddleware();
}
public function getMiddleware(): array
{
return $this->middleware;
}
public function registerFlareHandlers()
{
$this->registerExceptionHandler();
$this->registerErrorHandler();
return $this;
}
public function registerExceptionHandler()
{
$this->previousExceptionHandler = set_exception_handler([$this, 'handleException']);
return $this;
}
public function registerErrorHandler()
{
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
return $this;
}
private function registerDefaultMiddleware()
{
return $this->registerMiddleware(new AddGlows($this->recorder));
}
public function registerMiddleware($callable)
{
$this->middleware[] = $callable;
return $this;
}
public function getMiddlewares(): array
{
return $this->middleware;
}
public function glow(
string $name,
string $messageLevel = MessageLevels::INFO,
array $metaData = []
) {
$this->recorder->record(new Glow($name, $messageLevel, $metaData));
}
public function handleException(Throwable $throwable)
{
$this->report($throwable);
if ($this->previousExceptionHandler) {
call_user_func($this->previousExceptionHandler, $throwable);
}
}
public function handleError($code, $message, $file = '', $line = 0)
{
$exception = new ErrorException($message, 0, $code, $file, $line);
$this->report($exception);
if ($this->previousErrorHandler) {
return call_user_func(
$this->previousErrorHandler,
$message,
$code,
$file,
$line
);
}
}
public function applicationPath(string $applicationPath)
{
$this->applicationPath = $applicationPath;
return $this;
}
public function report(Throwable $throwable, callable $callback = null): ?Report
{
if (! $this->shouldSendReport($throwable)) {
return null;
}
$report = $this->createReport($throwable);
if (! is_null($callback)) {
call_user_func($callback, $report);
}
$this->sendReportToApi($report);
return $report;
}
protected function shouldSendReport(Throwable $throwable): bool
{
if ($this->reportErrorLevels && $throwable instanceof Error) {
return $this->reportErrorLevels & $throwable->getCode();
}
if ($this->reportErrorLevels && $throwable instanceof ErrorException) {
return $this->reportErrorLevels & $throwable->getSeverity();
}
if ($this->filterExceptionsCallable && $throwable instanceof Exception) {
return call_user_func($this->filterExceptionsCallable, $throwable);
}
return true;
}
public function reportMessage(string $message, string $logLevel, callable $callback = null)
{
$report = $this->createReportFromMessage($message, $logLevel);
if (! is_null($callback)) {
call_user_func($callback, $report);
}
$this->sendReportToApi($report);
}
public function sendTestReport(Throwable $throwable)
{
$this->api->sendTestReport($this->createReport($throwable));
}
private function sendReportToApi(Report $report)
{
if ($this->filterReportsCallable) {
if (! call_user_func($this->filterReportsCallable, $report)) {
return;
}
}
try {
$this->api->report($report);
} catch (Exception $exception) {
}
}
public function reset()
{
$this->api->sendQueuedReports();
$this->userProvidedContext = [];
$this->recorder->reset();
}
private function applyAdditionalParameters(Report $report)
{
$report
->stage($this->stage)
->messageLevel($this->messageLevel)
->setApplicationPath($this->applicationPath)
->userProvidedContext($this->userProvidedContext);
}
public function anonymizeIp()
{
$this->registerMiddleware(new AnonymizeIp());
return $this;
}
public function censorRequestBodyFields(array $fieldNames)
{
$this->registerMiddleware(new CensorRequestBodyFields($fieldNames));
return $this;
}
public function createReport(Throwable $throwable): Report
{
$report = Report::createForThrowable(
$throwable,
$this->contextDetector->detectCurrentContext(),
$this->applicationPath,
$this->version()
);
return $this->applyMiddlewareToReport($report);
}
public function createReportFromMessage(string $message, string $logLevel): Report
{
$report = Report::createForMessage(
$message,
$logLevel,
$this->contextDetector->detectCurrentContext(),
$this->applicationPath
);
return $this->applyMiddlewareToReport($report);
}
protected function applyMiddlewareToReport(Report $report): Report
{
$this->applyAdditionalParameters($report);
$report = (new Pipeline($this->container))
->send($report)
->through($this->middleware)
->then(function ($report) {
return $report;
});
return $report;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Facade\FlareClient;
use Facade\FlareClient\Stacktrace\Codesnippet;
class Frame
{
/** @var string */
protected $file;
/** @var int */
protected $lineNumber;
/** @var string */
protected $method;
/** @var string */
protected $class;
public function __construct(
string $file,
int $lineNumber,
string $method = null,
string $class = null
) {
$this->file = $file;
$this->lineNumber = $lineNumber;
$this->method = $method;
$this->class = $class;
}
public function toArray(): array
{
$codeSnippet = (new Codesnippet())
->snippetLineCount(9)
->surroundingLine($this->lineNumber)
->get($this->file);
return [
'line_number' => $this->lineNumber,
'method' => $this->getFullMethod(),
'code_snippet' => $codeSnippet,
'file' => $this->file,
];
}
private function getFullMethod(): string
{
$method = $this->method;
if ($class = $this->class ?? false) {
$method = "{$class}::{$method}";
}
return $method;
}
public function getFile(): string
{
return $this->file;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Facade\FlareClient\Glows;
use Facade\FlareClient\Concerns\UsesTime;
use Facade\FlareClient\Enums\MessageLevels;
class Glow
{
use UsesTime;
/** @var string */
private $name;
/** @var array */
private $metaData;
/** @var string */
private $messageLevel;
/** @var float */
private $microtime;
public function __construct(string $name, string $messageLevel = MessageLevels::INFO, array $metaData = [], ?float $microtime = null)
{
$this->name = $name;
$this->messageLevel = $messageLevel;
$this->metaData = $metaData;
$this->microtime = $microtime ?? microtime(true);
}
public function toArray()
{
return [
'time' => $this->getCurrentTime(),
'name' => $this->name,
'message_level' => $this->messageLevel,
'meta_data' => $this->metaData,
'microtime' => $this->microtime,
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Facade\FlareClient\Glows;
class Recorder
{
public const GLOW_LIMIT = 30;
private $glows = [];
public function record(Glow $glow)
{
$this->glows[] = $glow;
$this->glows = array_slice($this->glows, static::GLOW_LIMIT * -1, static::GLOW_LIMIT);
}
public function glows(): array
{
return $this->glows;
}
public function reset()
{
$this->glows = [];
}
}

View File

@@ -0,0 +1,217 @@
<?php
namespace Facade\FlareClient\Http;
use Facade\FlareClient\Http\Exceptions\BadResponseCode;
use Facade\FlareClient\Http\Exceptions\InvalidData;
use Facade\FlareClient\Http\Exceptions\MissingParameter;
use Facade\FlareClient\Http\Exceptions\NotFound;
class Client
{
/** @var null|string */
private $apiToken;
/** @var null|string */
private $apiSecret;
/** @var string */
private $baseUrl;
/** @var int */
private $timeout;
public function __construct(
?string $apiToken,
?string $apiSecret,
string $baseUrl = 'https://reporting.flareapp.io/api',
int $timeout = 10
) {
$this->apiToken = $apiToken;
$this->apiSecret = $apiSecret;
if (! $baseUrl) {
throw MissingParameter::create('baseUrl');
}
$this->baseUrl = $baseUrl;
if (! $timeout) {
throw MissingParameter::create('timeout');
}
$this->timeout = $timeout;
}
/**
* @param string $url
* @param array $arguments
*
* @return array|false
*/
public function get(string $url, array $arguments = [])
{
return $this->makeRequest('get', $url, $arguments);
}
/**
* @param string $url
* @param array $arguments
*
* @return array|false
*/
public function post(string $url, array $arguments = [])
{
return $this->makeRequest('post', $url, $arguments);
}
/**
* @param string $url
* @param array $arguments
*
* @return array|false
*/
public function patch(string $url, array $arguments = [])
{
return $this->makeRequest('patch', $url, $arguments);
}
/**
* @param string $url
* @param array $arguments
*
* @return array|false
*/
public function put(string $url, array $arguments = [])
{
return $this->makeRequest('put', $url, $arguments);
}
/**
* @param string $method
* @param array $arguments
*
* @return array|false
*/
public function delete(string $method, array $arguments = [])
{
return $this->makeRequest('delete', $method, $arguments);
}
/**
* @param string $httpVerb
* @param string $url
* @param array $arguments
*
* @return array
*/
private function makeRequest(string $httpVerb, string $url, array $arguments = [])
{
$queryString = http_build_query([
'key' => $this->apiToken,
'secret' => $this->apiSecret,
]);
$fullUrl = "{$this->baseUrl}/{$url}?{$queryString}";
$headers = [
'x-api-token: '.$this->apiToken,
];
$response = $this->makeCurlRequest($httpVerb, $fullUrl, $headers, $arguments);
if ($response->getHttpResponseCode() === 422) {
throw InvalidData::createForResponse($response);
}
if ($response->getHttpResponseCode() === 404) {
throw NotFound::createForResponse($response);
}
if ($response->getHttpResponseCode() !== 200 && $response->getHttpResponseCode() !== 204) {
throw BadResponseCode::createForResponse($response);
}
return $response->getBody();
}
public function makeCurlRequest(string $httpVerb, string $fullUrl, array $headers = [], array $arguments = []): Response
{
$curlHandle = $this->getCurlHandle($fullUrl, $headers);
switch ($httpVerb) {
case 'post':
curl_setopt($curlHandle, CURLOPT_POST, true);
$this->attachRequestPayload($curlHandle, $arguments);
break;
case 'get':
curl_setopt($curlHandle, CURLOPT_URL, $fullUrl.'&'.http_build_query($arguments));
break;
case 'delete':
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
case 'patch':
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->attachRequestPayload($curlHandle, $arguments);
break;
case 'put':
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
$this->attachRequestPayload($curlHandle, $arguments);
break;
}
$body = json_decode(curl_exec($curlHandle), true);
$headers = curl_getinfo($curlHandle);
$error = curl_error($curlHandle);
return new Response($headers, $body, $error);
}
private function attachRequestPayload(&$curlHandle, array $data)
{
$encoded = json_encode($data);
$this->lastRequest['body'] = $encoded;
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $encoded);
}
/**
* @param string $fullUrl
* @param array $headers
*
* @return resource
*/
private function getCurlHandle(string $fullUrl, array $headers = [])
{
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $fullUrl);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array_merge([
'Accept: application/json',
'Content-Type: application/json',
], $headers));
curl_setopt($curlHandle, CURLOPT_USERAGENT, 'Laravel/Flare API 1.0');
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curlHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curlHandle, CURLOPT_ENCODING, '');
curl_setopt($curlHandle, CURLINFO_HEADER_OUT, true);
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curlHandle, CURLOPT_MAXREDIRS, 1);
return $curlHandle;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Facade\FlareClient\Http\Exceptions;
use Exception;
use Facade\FlareClient\Http\Response;
class BadResponse extends Exception
{
/** @var \Facade\FlareClient\Http\Response */
public $response;
public static function createForResponse(Response $response)
{
$exception = new static("Could not perform request because: {$response->getError()}");
$exception->response = $response;
return $exception;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Facade\FlareClient\Http\Exceptions;
use Exception;
use Facade\FlareClient\Http\Response;
class BadResponseCode extends Exception
{
/** @var \Facade\FlareClient\Http\Response */
public $response;
/** @var array */
public $errors;
public static function createForResponse(Response $response)
{
$exception = new static(static::getMessageForResponse($response));
$exception->response = $response;
$bodyErrors = isset($response->getBody()['errors']) ? $response->getBody()['errors'] : [];
$exception->errors = $bodyErrors;
return $exception;
}
public static function getMessageForResponse(Response $response)
{
return "Response code {$response->getHttpResponseCode()} returned";
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Facade\FlareClient\Http\Exceptions;
use Facade\FlareClient\Http\Response;
class InvalidData extends BadResponseCode
{
public static function getMessageForResponse(Response $response)
{
return 'Invalid data found';
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Facade\FlareClient\Http\Exceptions;
use Exception;
class MissingParameter extends Exception
{
public static function create(string $parameterName)
{
return new static("`$parameterName` is a required parameter");
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Facade\FlareClient\Http\Exceptions;
use Facade\FlareClient\Http\Response;
class NotFound extends BadResponseCode
{
public static function getMessageForResponse(Response $response)
{
return 'Not found';
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Facade\FlareClient\Http;
class Response
{
private $headers;
private $body;
private $error;
public function __construct($headers, $body, $error)
{
$this->headers = $headers;
$this->body = $body;
$this->error = $error;
}
/**
* @return mixed
*/
public function getHeaders()
{
return $this->headers;
}
/**
* @return mixed
*/
public function getBody()
{
return $this->body;
}
/**
* @return bool
*/
public function hasBody()
{
return $this->body != false;
}
/**
* @return mixed
*/
public function getError()
{
return $this->error;
}
/**
* @return null|int
*/
public function getHttpResponseCode()
{
if (! isset($this->headers['http_code'])) {
return;
}
return (int) $this->headers['http_code'];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Facade\FlareClient\Middleware;
use Facade\FlareClient\Glows\Recorder;
use Facade\FlareClient\Report;
class AddGlows
{
/** @var Recorder */
private $recorder;
public function __construct(Recorder $recorder)
{
$this->recorder = $recorder;
}
public function handle(Report $report, $next)
{
foreach ($this->recorder->glows() as $glow) {
$report->addGlow($glow);
}
return $next($report);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Facade\FlareClient\Middleware;
use Facade\FlareClient\Report;
class AnonymizeIp
{
public function handle(Report $report, $next)
{
$context = $report->allContext();
$context['request']['ip'] = null;
$report->userProvidedContext($context);
return $next($report);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Facade\FlareClient\Middleware;
use Facade\FlareClient\Report;
class CensorRequestBodyFields
{
protected $fieldNames = [];
public function __construct(array $fieldNames)
{
$this->fieldNames = $fieldNames;
}
public function handle(Report $report, $next)
{
$context = $report->allContext();
foreach ($this->fieldNames as $fieldName) {
if (isset($context['request_data']['body'][$fieldName])) {
$context['request_data']['body'][$fieldName] = '<CENSORED>';
}
}
$report->userProvidedContext($context);
return $next($report);
}
}

View File

@@ -0,0 +1,334 @@
<?php
namespace Facade\FlareClient;
use Facade\FlareClient\Concerns\HasContext;
use Facade\FlareClient\Concerns\UsesTime;
use Facade\FlareClient\Context\ContextInterface;
use Facade\FlareClient\Contracts\ProvidesFlareContext;
use Facade\FlareClient\Enums\GroupingTypes;
use Facade\FlareClient\Glows\Glow;
use Facade\FlareClient\Solutions\ReportSolution;
use Facade\FlareClient\Stacktrace\Stacktrace;
use Facade\IgnitionContracts\Solution;
use Throwable;
class Report
{
use UsesTime;
use HasContext;
/** @var \Facade\FlareClient\Stacktrace\Stacktrace */
private $stacktrace;
/** @var string */
private $exceptionClass;
/** @var string */
private $message;
/** @var array */
private $glows = [];
/** @var array */
private $solutions = [];
/** @var ContextInterface */
private $context;
/** @var string */
private $applicationPath;
/** @var ?string */
private $applicationVersion;
/** @var array */
private $userProvidedContext = [];
/** @var array */
private $exceptionContext = [];
/** @var Throwable */
private $throwable;
/** @var string */
private $notifierName;
/** @var string */
private $languageVersion;
/** @var string */
private $frameworkVersion;
/** @var int */
private $openFrameIndex;
/** @var string */
private $groupBy ;
/** @var string */
private $trackingUuid;
/** @var null string|null */
public static $fakeTrackingUuid = null;
public static function createForThrowable(
Throwable $throwable,
ContextInterface $context,
?string $applicationPath = null,
?string $version = null
): self {
return (new static())
->setApplicationPath($applicationPath)
->throwable($throwable)
->useContext($context)
->exceptionClass(self::getClassForThrowable($throwable))
->message($throwable->getMessage())
->stackTrace(Stacktrace::createForThrowable($throwable, $applicationPath))
->exceptionContext($throwable)
->setApplicationVersion($version);
}
protected static function getClassForThrowable(Throwable $throwable): string
{
if ($throwable instanceof \Facade\Ignition\Exceptions\ViewException) {
if ($previous = $throwable->getPrevious()) {
return get_class($previous);
}
}
return get_class($throwable);
}
public static function createForMessage(string $message, string $logLevel, ContextInterface $context, ?string $applicationPath = null): self
{
$stacktrace = Stacktrace::create($applicationPath);
return (new static())
->setApplicationPath($applicationPath)
->message($message)
->useContext($context)
->exceptionClass($logLevel)
->stacktrace($stacktrace)
->openFrameIndex($stacktrace->firstApplicationFrameIndex());
}
public function __construct()
{
$this->trackingUuid = self::$fakeTrackingUuid ?? $this->generateUuid();
}
public function trackingUuid(): string
{
return $this->trackingUuid;
}
public function exceptionClass(string $exceptionClass)
{
$this->exceptionClass = $exceptionClass;
return $this;
}
public function getExceptionClass(): string
{
return $this->exceptionClass;
}
public function throwable(Throwable $throwable)
{
$this->throwable = $throwable;
return $this;
}
public function getThrowable(): ?Throwable
{
return $this->throwable;
}
public function message(string $message)
{
$this->message = $message;
return $this;
}
public function getMessage(): string
{
return $this->message;
}
public function stacktrace(Stacktrace $stacktrace)
{
$this->stacktrace = $stacktrace;
return $this;
}
public function getStacktrace(): Stacktrace
{
return $this->stacktrace;
}
public function notifierName(string $notifierName)
{
$this->notifierName = $notifierName;
return $this;
}
public function languageVersion(string $languageVersion)
{
$this->languageVersion = $languageVersion;
return $this;
}
public function frameworkVersion(string $frameworkVersion)
{
$this->frameworkVersion = $frameworkVersion;
return $this;
}
public function useContext(ContextInterface $request)
{
$this->context = $request;
return $this;
}
public function openFrameIndex(?int $index)
{
$this->openFrameIndex = $index;
return $this;
}
public function setApplicationPath(?string $applicationPath)
{
$this->applicationPath = $applicationPath;
return $this;
}
public function getApplicationPath(): ?string
{
return $this->applicationPath;
}
public function setApplicationVersion(?string $applicationVersion)
{
$this->applicationVersion = $applicationVersion;
return $this;
}
public function getApplicationVersion(): ?string
{
return $this->applicationVersion;
}
public function view(?View $view)
{
$this->view = $view;
return $this;
}
public function addGlow(Glow $glow)
{
$this->glows[] = $glow->toArray();
return $this;
}
public function addSolution(Solution $solution)
{
$this->solutions[] = ReportSolution::fromSolution($solution)->toArray();
return $this;
}
public function userProvidedContext(array $userProvidedContext)
{
$this->userProvidedContext = $userProvidedContext;
return $this;
}
/** @deprecated */
public function groupByTopFrame()
{
$this->groupBy = GroupingTypes::TOP_FRAME;
return $this;
}
/** @deprecated */
public function groupByException()
{
$this->groupBy = GroupingTypes::EXCEPTION;
return $this;
}
public function allContext(): array
{
$context = $this->context->toArray();
$context = array_merge_recursive_distinct($context, $this->exceptionContext);
return array_merge_recursive_distinct($context, $this->userProvidedContext);
}
private function exceptionContext(Throwable $throwable)
{
if ($throwable instanceof ProvidesFlareContext) {
$this->exceptionContext = $throwable->context();
}
return $this;
}
public function toArray()
{
return [
'notifier' => $this->notifierName ?? 'Flare Client',
'language' => 'PHP',
'framework_version' => $this->frameworkVersion,
'language_version' => $this->languageVersion ?? phpversion(),
'exception_class' => $this->exceptionClass,
'seen_at' => $this->getCurrentTime(),
'message' => $this->message,
'glows' => $this->glows,
'solutions' => $this->solutions,
'stacktrace' => $this->stacktrace->toArray(),
'context' => $this->allContext(),
'stage' => $this->stage,
'message_level' => $this->messageLevel,
'open_frame_index' => $this->openFrameIndex,
'application_path' => $this->applicationPath,
'application_version' => $this->applicationVersion,
'tracking_uuid' => $this->trackingUuid,
];
}
/*
* Found on https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid/15875555#15875555
*/
private function generateUuid(): string
{
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
$data = $data ?? random_bytes(16);
// Set version to 0100
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
// Set bits 6-7 to 10
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
// Output the 36 character UUID.
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Facade\FlareClient\Solutions;
use Facade\IgnitionContracts\RunnableSolution;
use Facade\IgnitionContracts\Solution as SolutionContract;
class ReportSolution
{
/** @var SolutionContract */
protected $solution;
public function __construct(SolutionContract $solution)
{
$this->solution = $solution;
}
public static function fromSolution(SolutionContract $solution)
{
return new static($solution);
}
public function toArray(): array
{
$isRunnable = ($this->solution instanceof RunnableSolution);
return [
'class' => get_class($this->solution),
'title' => $this->solution->getSolutionTitle(),
'description' => $this->solution->getSolutionDescription(),
'links' => $this->solution->getDocumentationLinks(),
'action_description' => $isRunnable ? $this->solution->getSolutionActionDescription() : null,
'is_runnable' => $isRunnable,
];
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Facade\FlareClient\Stacktrace;
use RuntimeException;
class Codesnippet
{
/** @var int */
private $surroundingLine = 1;
/** @var int */
private $snippetLineCount = 9;
public function surroundingLine(int $surroundingLine): self
{
$this->surroundingLine = $surroundingLine;
return $this;
}
public function snippetLineCount(int $snippetLineCount): self
{
$this->snippetLineCount = $snippetLineCount;
return $this;
}
public function get(string $fileName): array
{
if (! file_exists($fileName)) {
return [];
}
try {
$file = new File($fileName);
[$startLineNumber, $endLineNumber] = $this->getBounds($file->numberOfLines());
$code = [];
$line = $file->getLine($startLineNumber);
$currentLineNumber = $startLineNumber;
while ($currentLineNumber <= $endLineNumber) {
$code[$currentLineNumber] = rtrim(substr($line, 0, 250));
$line = $file->getNextLine();
$currentLineNumber++;
}
return $code;
} catch (RuntimeException $exception) {
return [];
}
}
private function getBounds($totalNumberOfLineInFile): array
{
$startLine = max($this->surroundingLine - floor($this->snippetLineCount / 2), 1);
$endLine = $startLine + ($this->snippetLineCount - 1);
if ($endLine > $totalNumberOfLineInFile) {
$endLine = $totalNumberOfLineInFile;
$startLine = max($endLine - ($this->snippetLineCount - 1), 1);
}
return [$startLine, $endLine];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Facade\FlareClient\Stacktrace;
use SplFileObject;
class File
{
/** @var \SplFileObject */
private $file;
public function __construct(string $path)
{
$this->file = new SplFileObject($path);
}
public function numberOfLines(): int
{
$this->file->seek(PHP_INT_MAX);
return $this->file->key() + 1;
}
public function getLine(int $lineNumber = null): string
{
if (is_null($lineNumber)) {
return $this->getNextLine();
}
$this->file->seek($lineNumber - 1);
return $this->file->current();
}
public function getNextLine(): string
{
$this->file->next();
return $this->file->current();
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Facade\FlareClient\Stacktrace;
class Frame
{
/** @var string */
private $file;
/** @var int */
private $lineNumber;
/** @var string */
private $method;
/** @var string */
private $class;
/** @var bool */
private $isApplicationFrame;
public function __construct(
string $file,
int $lineNumber,
string $method = null,
string $class = null,
bool $isApplicationFrame = false
) {
$this->file = $file;
$this->lineNumber = $lineNumber;
$this->method = $method;
$this->class = $class;
$this->isApplicationFrame = $isApplicationFrame;
}
public function toArray(): array
{
$codeSnippet = (new Codesnippet())
->snippetLineCount(31)
->surroundingLine($this->lineNumber)
->get($this->file);
return [
'line_number' => $this->lineNumber,
'method' => $this->method,
'class' => $this->class,
'code_snippet' => $codeSnippet,
'file' => $this->file,
'is_application_frame' => $this->isApplicationFrame,
];
}
public function getFile(): string
{
return $this->file;
}
public function getLinenumber(): int
{
return $this->lineNumber;
}
public function isApplicationFrame()
{
return $this->isApplicationFrame;
}
}

View File

@@ -0,0 +1,126 @@
<?php
namespace Facade\FlareClient\Stacktrace;
use Throwable;
class Stacktrace
{
/** @var \Facade\FlareClient\Stacktrace\Frame[] */
private $frames;
/** @var string */
private $applicationPath;
public static function createForThrowable(Throwable $throwable, ?string $applicationPath = null): self
{
return new static($throwable->getTrace(), $applicationPath, $throwable->getFile(), $throwable->getLine());
}
public static function create(?string $applicationPath = null): self
{
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS & ~DEBUG_BACKTRACE_PROVIDE_OBJECT);
return new static($backtrace, $applicationPath);
}
public function __construct(array $backtrace, ?string $applicationPath = null, string $topmostFile = null, string $topmostLine = null)
{
$this->applicationPath = $applicationPath;
$currentFile = $topmostFile;
$currentLine = $topmostLine;
foreach ($backtrace as $rawFrame) {
if (! $this->frameFromFlare($rawFrame) && ! $this->fileIgnored($currentFile)) {
$this->frames[] = new Frame(
$currentFile,
$currentLine,
$rawFrame['function'] ?? null,
$rawFrame['class'] ?? null,
$this->frameFileFromApplication($currentFile)
);
}
$currentFile = $rawFrame['file'] ?? 'unknown';
$currentLine = $rawFrame['line'] ?? 0;
}
$this->frames[] = new Frame(
$currentFile,
$currentLine,
'[top]'
);
}
protected function frameFromFlare(array $rawFrame): bool
{
return isset($rawFrame['class']) && strpos($rawFrame['class'], 'Facade\\FlareClient\\') === 0;
}
protected function frameFileFromApplication(string $frameFilename): bool
{
$relativeFile = str_replace('\\', DIRECTORY_SEPARATOR, $frameFilename);
if (! empty($this->applicationPath)) {
$relativeFile = array_reverse(explode($this->applicationPath ?? '', $frameFilename, 2))[0];
}
if (strpos($relativeFile, DIRECTORY_SEPARATOR . 'vendor') === 0) {
return false;
}
return true;
}
protected function fileIgnored(string $currentFile): bool
{
$currentFile = str_replace('\\', DIRECTORY_SEPARATOR, $currentFile);
$ignoredFiles = [
'/ignition/src/helpers.php',
];
foreach ($ignoredFiles as $ignoredFile) {
if (strstr($currentFile, $ignoredFile) !== false) {
return true;
}
}
return false;
}
public function firstFrame(): Frame
{
return $this->frames[0];
}
public function toArray(): array
{
return array_map(function (Frame $frame) {
return $frame->toArray();
}, $this->frames);
}
public function firstApplicationFrame(): ?Frame
{
foreach ($this->frames as $index => $frame) {
if ($frame->isApplicationFrame()) {
return $frame;
}
}
return null;
}
public function firstApplicationFrameIndex(): ?int
{
foreach ($this->frames as $index => $frame) {
if ($frame->isApplicationFrame()) {
return $index;
}
}
return null;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Facade\FlareClient\Time;
use DateTimeImmutable;
class SystemTime implements Time
{
public function getCurrentTime(): int
{
return (new DateTimeImmutable())->getTimestamp();
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\FlareClient\Time;
interface Time
{
public function getCurrentTime(): int;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Facade\FlareClient\Truncation;
abstract class AbstractTruncationStrategy implements TruncationStrategy
{
/** @var ReportTrimmer */
protected $reportTrimmer;
public function __construct(ReportTrimmer $reportTrimmer)
{
$this->reportTrimmer = $reportTrimmer;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Facade\FlareClient\Truncation;
class ReportTrimmer
{
protected static $maxPayloadSize = 524288;
protected $strategies = [
TrimStringsStrategy::class,
TrimContextItemsStrategy::class,
];
public function trim(array $payload): array
{
foreach ($this->strategies as $strategy) {
if (! $this->needsToBeTrimmed($payload)) {
break;
}
$payload = (new $strategy($this))->execute($payload);
}
return $payload;
}
public function needsToBeTrimmed(array $payload): bool
{
return strlen(json_encode($payload)) > self::getMaxPayloadSize();
}
public static function getMaxPayloadSize(): int
{
return self::$maxPayloadSize;
}
public static function setMaxPayloadSize(int $maxPayloadSize): void
{
self::$maxPayloadSize = $maxPayloadSize;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Facade\FlareClient\Truncation;
class TrimContextItemsStrategy extends AbstractTruncationStrategy
{
public static function thresholds()
{
return [100, 50, 25, 10];
}
public function execute(array $payload): array
{
foreach (static::thresholds() as $threshold) {
if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
break;
}
$payload['context'] = $this->iterateContextItems($payload['context'], $threshold);
}
return $payload;
}
protected function iterateContextItems(array $contextItems, int $threshold): array
{
array_walk($contextItems, [$this, 'trimContextItems'], $threshold);
return $contextItems;
}
protected function trimContextItems(&$value, $key, int $threshold)
{
if (is_array($value)) {
if (count($value) > $threshold) {
$value = array_slice($value, $threshold * -1, $threshold);
}
array_walk($value, [$this, 'trimContextItems'], $threshold);
}
return $value;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Facade\FlareClient\Truncation;
class TrimStringsStrategy extends AbstractTruncationStrategy
{
public static function thresholds()
{
return [1024, 512, 256];
}
public function execute(array $payload): array
{
foreach (static::thresholds() as $threshold) {
if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
break;
}
$payload = $this->trimPayloadString($payload, $threshold);
}
return $payload;
}
protected function trimPayloadString(array $payload, int $threshold): array
{
array_walk_recursive($payload, function (&$value) use ($threshold) {
if (is_string($value) && strlen($value) > $threshold) {
$value = substr($value, 0, $threshold);
}
});
return $payload;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\FlareClient\Truncation;
interface TruncationStrategy
{
public function execute(array $payload): array;
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Facade\FlareClient;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
class View
{
/** @var string */
private $file;
/** @var array */
private $data = [];
public function __construct(string $file, array $data = [])
{
$this->file = $file;
$this->data = $data;
}
public static function create(string $file, array $data = []): self
{
return new static($file, $data);
}
private function dumpViewData($variable): string
{
$cloner = new VarCloner();
$dumper = new HtmlDumper();
$dumper->setDumpHeader('');
$output = fopen('php://memory', 'r+b');
$dumper->dump($cloner->cloneVar($variable)->withMaxDepth(1), $output, [
'maxDepth' => 1,
'maxStringLength' => 160,
]);
return stream_get_contents($output, -1, 0);
}
public function toArray()
{
return [
'file' => $this->file,
'data' => array_map([$this, 'dumpViewData'], $this->data),
];
}
}

View File

@@ -0,0 +1,17 @@
<?php
if (! function_exists('array_merge_recursive_distinct')) {
function array_merge_recursive_distinct(array &$array1, array &$array2)
{
$merged = $array1;
foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = array_merge_recursive_distinct($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
return $merged;
}
}

View File

@@ -0,0 +1,29 @@
name: Check & fix styling
on: [push]
jobs:
style:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --allow-risky=yes
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v2.3.0
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -0,0 +1,33 @@
name: Psalm
on:
push:
paths:
- '**.php'
- 'psalm.xml'
jobs:
psalm:
name: psalm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Run composer require
run: composer require -n --prefer-dist
- name: Run psalm
run: ./vendor/bin/psalm -c psalm.xml

View File

@@ -0,0 +1,43 @@
name: Run tests
on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
jobs:
php-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [ 8.0, 7.4, 7.3 ]
dependency-version: [ prefer-lowest, prefer-stable ]
os: [ ubuntu-latest, windows-latest ]
allow_failures:
- php: 8.0
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2
- name: Install PHP 7 dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress
if: "matrix.php < 8"
- name: Install PHP 8 dependencies
run: composer update --prefer-stable --ignore-platform-req=php --no-interaction --no-progress
if: "matrix.php >= 8"
- name: Execute tests
run: vendor/bin/phpunit

View File

@@ -0,0 +1,38 @@
<?php
$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->notName('GitConflictController.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
])
->setFinder($finder);

View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) Facade <info@facade.company>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,46 @@
{
"name": "facade/ignition-contracts",
"description": "Solution contracts for Ignition",
"keywords": [
"flare",
"contracts",
"ignition"
],
"homepage": "https://github.com/facade/ignition-contracts",
"license": "MIT",
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://flareapp.io",
"role": "Developer"
}
],
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v2.15.8",
"phpunit/phpunit": "^9.3.11",
"vimeo/psalm": "^3.17.1"
},
"autoload": {
"psr-4": {
"Facade\\IgnitionContracts\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Facade\\IgnitionContracts\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
useDocblockPropertyTypes="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
</issueHandlers>
</psalm>

View File

@@ -0,0 +1,56 @@
<?php
namespace Facade\IgnitionContracts;
class BaseSolution implements Solution
{
protected $title;
protected $description;
protected $links = [];
public static function create(string $title)
{
return new static($title);
}
public function __construct(string $title)
{
$this->title = $title;
}
public function getSolutionTitle(): string
{
return $this->title;
}
public function setSolutionTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSolutionDescription(): string
{
return $this->description;
}
public function setSolutionDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDocumentationLinks(): array
{
return $this->links;
}
public function setDocumentationLinks(array $links): self
{
$this->links = $links;
return $this;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Facade\IgnitionContracts;
use Throwable;
interface HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool;
/** \Facade\IgnitionContracts\Solution[] */
public function getSolutions(Throwable $throwable): array;
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Facade\IgnitionContracts;
interface ProvidesSolution
{
public function getSolution(): Solution;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Facade\IgnitionContracts;
interface RunnableSolution extends Solution
{
public function getSolutionActionDescription(): string;
public function getRunButtonText(): string;
public function run(array $parameters = []);
public function getRunParameters(): array;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Facade\IgnitionContracts;
interface Solution
{
public function getSolutionTitle(): string;
public function getSolutionDescription(): string;
public function getDocumentationLinks(): array;
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Facade\IgnitionContracts;
use Throwable;
interface SolutionProviderRepository
{
public function registerSolutionProvider(string $solutionProviderClass): self;
public function registerSolutionProviders(array $solutionProviderClasses): self;
/**
* @param Throwable $throwable
* @return \Facade\IgnitionContracts\Solution[]
*/
public function getSolutionsForThrowable(Throwable $throwable): array;
public function getSolutionForClass(string $solutionClass): ?Solution;
}

4
vendor/facade/ignition/.babelrc vendored Normal file
View File

@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"plugins": ["@babel/transform-runtime", "@babel/plugin-syntax-dynamic-import"]
}

View File

@@ -0,0 +1,100 @@
name: Run tests
on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
jobs:
php-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [8.0, 7.4, 7.3, 7.2]
laravel: [6.*, 5.8.*, 5.7.*, 5.6.*, 5.5.*]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]
include:
- laravel: 6.*
testbench: 4.*
- laravel: 5.8.*
testbench: 3.8.*
- laravel: 5.7.*
testbench: 3.7.*
- laravel: 5.6.*
testbench: 3.6.*
- laravel: 5.5.*
testbench: 3.5.*
exclude:
- laravel: 5.8.*
php: 8.0
- laravel: 5.7.*
php: 8.0
- laravel: 5.6.*
php: 8.0
- laravel: 5.5.*
php: 8.0
- laravel: 5.7.*
php: 7.4
- laravel: 5.6.*
php: 7.4
- laravel: 5.5.*
php: 7.4
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, fileinfo
coverage: none
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
- name: Send Slack notification
uses: 8398a7/action-slack@v2
if: ${{ failure() && !! env.SLACK_WEBHOOK }}
with:
status: ${{ job.status }}
author_name: ${{ github.actor }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
js-tests:
runs-on: ubuntu-latest
name: JavaScript tests
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Install dependencies
run: yarn install --non-interactive
- name: Execute tests
run: yarn run jest
- name: Send Slack notification
uses: 8398a7/action-slack@v2
if: ${{ failure() && !! env.SLACK_WEBHOOK }}
with:
status: ${{ job.status }}
author_name: ${{ github.actor }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -0,0 +1 @@
resources/compiled

6
vendor/facade/ignition/.prettierrc vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"tabWidth": 4
}

8
vendor/facade/ignition/.styleci.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
preset: laravel
disabled:
- single_class_element_per_statement
finder:
not-name:
- "GitConflictController.php"

282
vendor/facade/ignition/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,282 @@
# Changelog
All notable changes to `ignition` will be documented in this file
## 1.18.0 - 2021-08-02
- disable executing solutions on non-local environments or from non-local IP addresses on version 1.x (#404)
## 1.17.0
- add extra editors (#389)
## 1.16.5 - 2021-02-14
- fix CVE-2021-3129 for facade/ignition 1.16.x (Laravel 6) (#351)
## 1.16.4 - 2021-02-13
do not use, tagged on the wrong branch
## 1.16.3 - 2020-07-13
- do not use missing package solution provider by default (closes #179)
## 1.16.2 - 2020-07-12
- remove ability to fix variable names
## 1.16.0 - 2020-01-21
- add named routes (#197)
## 1.15.0 - 2020-01-21
- add exception to the bottom of the html (#230)
## 1.14.0 - 2020-01-06
- add indicator that solution is running (#212)
## 1.13.1 - 2020-01-02
- Remove external reference for icons (#134)
## 1.13.0 - 2019-11-27
- Allow custom grouping types
## 1.12.1 - 2019-11-25
- Detect multibyte position offsets when adding linenumbers to the blade view - Fixes #193
## 1.12.0 - 2019-11-14
- Add exception to html (#206)
- Add a clear exception when passing no parameters to ddd (#205)
- Ignore JS tests (#215)
- Fix share report route bug
## 1.11.2 - 2019-10-13
- simplify default Laravel installation (#198)
## 1.11.1 - 2019-10-08
- add conditional line number (#182)
## 1.11.0 - 2019-10-08
- add better error messages for missing validation rules (#125)
## 1.10.0 - 2019-10-07
- Add `ignition:make-solution` command
- Add default for query binding option (Fixes #183)
## 1.9.2 - 2019-10-04
- Fix service provider registration (Fixes #177)
## 1.9.1 - 2019-10-01
- collapse vendor frames on windows fix (#176)
## 1.9.0 - 2019-09-27
- add ability to send logs to flare
- add `ddd` function
## 1.8.4 - 2019-09-27
- Resolve configuration from the injected app instead of the helper ([#168](https://github.com/facade/ignition/pull/168))
## 1.8.3 - 2019-09-25
- Remove `select-none` from error message
- Change line clamp behaviour for longer error messages
## 1.8.2 - 2019-09-20
- fix for `TypeError: Cannot set property 'highlightState' of undefined`
## 1.8.1 - 2019-09-20
- Revert javascript assets via URL - Fixes #161
## 1.8.0 - 2019-09-18
- added solution for running Laravel Dusk in production ([#121](https://github.com/facade/ignition/pull/121))
- Automatically fix blade variable typos and optional variables ([#38](https://github.com/facade/ignition/pull/38))
## 1.7.1 - 2019-09-18
- Use url helper to generate housekeeping endpoints
## 1.7.0 - 2019-09-18
- Add the ability to define a query collector max value ([#153](https://github.com/facade/ignition/pull/153))
## 1.6.10 - 2019-09-18
- fix `__invoke` method name in solution ([#151](https://github.com/facade/ignition/pull/151))
## 1.6.9 - 2019-09-18
- Add noscript trace information - fixes [#146](https://github.com/facade/ignition/issues/146)
## 1.6.8 - 2019-09-18
- Use javascript content type for asset response - fixes [#149](https://github.com/facade/ignition/issues/149)
## 1.6.7 - 2019-09-18
- Load javascript assets via URL. Fixes [#16](https://github.com/facade/ignition/issues/16)
## 1.6.6 - 2019-09-16
- Prevent undefined index exception in `TestCommand`
## 1.6.5 - 2019-09-13
- Ignore invalid characters in JSON encoding. Fixes [#138](https://github.com/facade/ignition/issues/138)
## 1.6.4 - 2019-09-13
- add no-index on error page
## 1.6.3 - 2019-09-12
- Fix `RouteNotDefinedSolutionProvider` in Laravel 5
## 1.6.2 - 2019-09-12
- updated publishing tag from default config
## 1.6.1 - 2019-09-12
- Resolve configuration from the injected application instead of the helper - Fixes [#131](https://github.com/facade/ignition/issues/131)
## 1.6.0 - 2019-09-09
- add `RouteNotDefined` solution provider ([#113](https://github.com/facade/ignition/pull/113))
## 1.5.0 - 2019-09-09
- suggest running migrations when a column is missing ([#83](https://github.com/facade/ignition/pull/83))
## 1.4.19 - 2019-09-09
- Remove quotation from git commit url ([#89](https://github.com/facade/ignition/pull/89))
## 1.4.18 - 2019-09-09
- Fix open_basedir restriction when looking up config file. Fixes ([#120](https://github.com/facade/ignition/pull/120))
## 1.4.17 - 2019-09-06
- Remove Inter, Operator from font stack. Fixes [#74](https://github.com/facade/ignition/issues/74)
## 1.4.15 - 2019-09-05
- Use previous exception trace for view exceptions. Fixes [#107](https://github.com/facade/ignition/issues/107)
## 1.4.14 - 2019-09-05
- Use DIRECTORY_SEPARATOR to fix an issue with blade view lookups in Windows
## 1.4.13 - 2019-09-05
- Use Laravel style comments
## 1.4.12 - 2019-09-04
- Use a middleware to protect ignition routes ([#93](https://github.com/facade/ignition/pull/93))
## 1.4.11 - 2019-09-04
- Use exception line number as fallbacks for view errors
## 1.4.10 - 2019-09-04
- Wrap solution provider lookup in a try-catch block
## 1.4.9 - 2019-09-04
- Lookup the first exception when linking to Telescope
## 1.4.8 - 2019-09-04
- pass an empty string to query if no connection name is available - fixes [#86](https://github.com/facade/ignition/issues/86)
## 1.4.7 - 2019-09-04
- Match whoops minimum version constraint with Laravel 6
## 1.4.6 - 2019-09-04
- Use empty array for default ignored solution providers
## 1.4.5 - 2019-09-03
- fix for new Laravel 6 installs
## 1.4.4 - 2019-09-03
- Suggest default database name in Laravel 6
- Add void return type to FlareHandler::write()
## 1.4.3 - 2019-09-03
- allow monolog v2
## 1.4.2 - 2019-09-03
- style fixes
## 1.4.1 - 2019-09-03
- Change `remote-sites-path` and `local-sites-path` config keys to us snake case
## 1.4.0 - 2019-09-03
- add `enable_runnable_solutions` key to config file
## 1.3.0 - 2019-09-02
- add `MergeConflictSolutionProvider`
## 1.2.0 - 2019-09-02
- add `ignored_solution_providers` key to config file
## 1.1.1 - 2019-09-02
- Fixed context tab crash when not using git ([#24](https://github.com/facade/ignition/issues/24))
## 1.1.0 - 2019-09-02
- Fixed an error that removed the ability to register custom blade directives.
- Fixed an error that prevented solution execution in Laravel 5.5 and 5.6
- The "Share" button can now be disabled in the configuration file
- Fixes an error when trying to log `null` values
## 1.0.4 - 2019-09-02
- Check if the authenticated user has a `toArray` method available, before collecting user data
## 1.0.3 - 2019-09-02
- Corrected invalid link in config file
## 1.0.2 - 2019-09-02
- Fixed an error in the `DefaultDbNameSolutionProvider` that could cause an infinite loop in Laravel < 5.6.28
## 1.0.1 - 2019-08-31
- add support for L5.5 & 5.6 ([#21](https://github.com/facade/ignition/pull/21))
## 1.0.0 - 2019-08-30
- initial release

21
vendor/facade/ignition/LICENSE.md vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Facade <info@facade.company>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

27
vendor/facade/ignition/README.md vendored Normal file
View File

@@ -0,0 +1,27 @@
# Ignition: a beautiful error page for Laravel apps
[![Latest Version on Packagist](https://img.shields.io/packagist/v/facade/ignition.svg?style=flat-square)](https://packagist.org/packages/facade/ignition)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/facade/ignition/run-php-tests?label=Tests)
[![Quality Score](https://img.shields.io/scrutinizer/g/facade/ignition.svg?style=flat-square)](https://scrutinizer-ci.com/g/facade/ignition)
[![StyleCI](https://github.styleci.io/repos/204472210/shield?branch=master)](https://github.styleci.io/repos/204472210)
[![Total Downloads](https://img.shields.io/packagist/dt/facade/ignition.svg?style=flat-square)](https://packagist.org/packages/facade/ignition)
[Ignition](https://flareapp.io/docs/ignition-for-laravel/introduction) is a beautiful and customizable error page for Laravel applications running on Laravel 5.5 and newer. It is the default error page for all Laravel 6 applications. It also allows to publicly share your errors on [Flare](https://flareapp.io). If configured with a valid Flare API key, your errors in production applications will be tracked, and you'll get notified when they happen.
![Screenshot of ignition](https://facade.github.io/ignition/screenshot.png)
## Official Documentation
The official documentation for Ignition can be found on the [Flare website](https://flareapp.io/docs/ignition-for-laravel/installation).
### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

76
vendor/facade/ignition/composer.json vendored Normal file
View File

@@ -0,0 +1,76 @@
{
"name": "facade/ignition",
"description": "A beautiful error page for Laravel applications.",
"keywords": [
"error",
"page",
"laravel",
"flare"
],
"homepage": "https://github.com/facade/ignition",
"license": "MIT",
"require": {
"php": "^7.1|^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"facade/flare-client-php": "^1.3",
"facade/ignition-contracts": "^1.0",
"filp/whoops": "^2.4",
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0",
"monolog/monolog": "^1.12 || ^2.0",
"scrivo/highlight.php": "^9.15",
"symfony/console": "^3.4 || ^4.0",
"symfony/var-dumper": "^3.4 || ^4.0"
},
"require-dev": {
"mockery/mockery": "~1.3.3|^1.4.2",
"orchestra/testbench": "^3.5 || ^3.6 || ^3.7 || ^3.8 || ^4.0"
},
"suggest": {
"laravel/telescope": "^2.0"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"laravel": {
"providers": [
"Facade\\Ignition\\IgnitionServiceProvider"
],
"aliases": {
"Flare": "Facade\\Ignition\\Facades\\Flare"
}
}
},
"autoload": {
"psr-4": {
"Facade\\Ignition\\": "src"
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Facade\\Ignition\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"format": [
"vendor/bin/php-cs-fixer fix"
],
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"support": {
"issues": "https://github.com/facade/ignition/issues",
"forum": "https://twitter.com/flareappio",
"source": "https://github.com/facade/ignition",
"docs": "https://flareapp.io/docs/ignition-for-laravel/introduction"
}
}

48
vendor/facade/ignition/config/flare.php vendored Normal file
View File

@@ -0,0 +1,48 @@
<?php
return [
/*
|
|--------------------------------------------------------------------------
| Flare API key
|--------------------------------------------------------------------------
|
| Specify Flare's API key below to enable error reporting to the service.
|
| More info: https://flareapp.io/docs/general/projects
|
*/
'key' => env('FLARE_KEY'),
/*
|--------------------------------------------------------------------------
| Reporting Options
|--------------------------------------------------------------------------
|
| These options determine which information will be transmitted to Flare.
|
*/
'reporting' => [
'anonymize_ips' => true,
'collect_git_information' => true,
'report_queries' => true,
'maximum_number_of_collected_queries' => 200,
'report_query_bindings' => true,
'report_view_data' => true,
'grouping_type' => null,
],
/*
|--------------------------------------------------------------------------
| Reporting Log statements
|--------------------------------------------------------------------------
|
| If this setting is `false` log statements won't be send as events to Flare,
| no matter which error level you specified in the Flare log channel.
|
*/
'send_logs_as_events' => true,
];

View File

@@ -0,0 +1,126 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Editor
|--------------------------------------------------------------------------
|
| Choose your preferred editor to use when clicking any edit button.
|
| Supported: "phpstorm", "vscode", "vscode-insiders", "textmate", "emacs",
| "sublime", "atom", "nova", "macvim", "idea", "netbeans",
| "xdebug"
|
*/
'editor' => env('IGNITION_EDITOR', 'phpstorm'),
/*
|--------------------------------------------------------------------------
| Theme
|--------------------------------------------------------------------------
|
| Here you may specify which theme Ignition should use.
|
| Supported: "light", "dark", "auto"
|
*/
'theme' => env('IGNITION_THEME', 'light'),
/*
|--------------------------------------------------------------------------
| Sharing
|--------------------------------------------------------------------------
|
| You can share local errors with colleagues or others around the world.
| Sharing is completely free and doesn't require an account on Flare.
|
| If necessary, you can completely disable sharing below.
|
*/
'enable_share_button' => env('IGNITION_SHARING_ENABLED', true),
/*
|--------------------------------------------------------------------------
| Register Ignition commands
|--------------------------------------------------------------------------
|
| Ignition comes with an additional make command that lets you create
| new solution classes more easily. To keep your default Laravel
| installation clean, this command is not registered by default.
|
| You can enable the command registration below.
|
*/
'register_commands' => env('REGISTER_IGNITION_COMMANDS', false),
/*
|--------------------------------------------------------------------------
| Ignored Solution Providers
|--------------------------------------------------------------------------
|
| You may specify a list of solution providers (as fully qualified class
| names) that shouldn't be loaded. Ignition will ignore these classes
| and possible solutions provided by them will never be displayed.
|
*/
'ignored_solution_providers' => [
Facade\Ignition\SolutionProviders\MissingPackageSolutionProvider::class,
],
/*
|--------------------------------------------------------------------------
| Runnable Solutions
|--------------------------------------------------------------------------
|
| Some solutions that Ignition displays are runnable and can perform
| various tasks. Runnable solutions are enabled when your app has
| debug mode enabled. You may also fully disable this feature.
|
*/
'enable_runnable_solutions' => env('IGNITION_ENABLE_RUNNABLE_SOLUTIONS', null),
/*
|--------------------------------------------------------------------------
| Remote Path Mapping
|--------------------------------------------------------------------------
|
| If you are using a remote dev server, like Laravel Homestead, Docker, or
| even a remote VPS, it will be necessary to specify your path mapping.
|
| Leaving one, or both of these, empty or null will not trigger the remote
| URL changes and Ignition will treat your editor links as local files.
|
| "remote_sites_path" is an absolute base path for your sites or projects
| in Homestead, Vagrant, Docker, or another remote development server.
|
| Example value: "/home/vagrant/Code"
|
| "local_sites_path" is an absolute base path for your sites or projects
| on your local computer where your IDE or code editor is running on.
|
| Example values: "/Users/<name>/Code", "C:\Users\<name>\Documents\Code"
|
*/
'remote_sites_path' => env('IGNITION_REMOTE_SITES_PATH', ''),
'local_sites_path' => env('IGNITION_LOCAL_SITES_PATH', ''),
/*
|--------------------------------------------------------------------------
| Housekeeping Endpoint Prefix
|--------------------------------------------------------------------------
|
| Ignition registers a couple of routes when it is enabled. Below you may
| specify a route prefix that will be used to host all internal links.
|
*/
'housekeeping_endpoint_prefix' => '_ignition',
];

65
vendor/facade/ignition/package.json vendored Normal file
View File

@@ -0,0 +1,65 @@
{
"private": true,
"scripts": {
"dev": "webpack --mode development --watch",
"build": "NODE_ENV=production webpack --mode production",
"format": "prettier --write 'resources/**/*.{css,js,ts,vue}'"
},
"dependencies": {
"git-url-parse": "^11.1.2",
"highlight.js": "^9.15.6",
"lodash": "^4.17.4",
"markdown-it": "^9.0.1",
"md5": "^2.2.1",
"sql-formatter": "^2.3.3"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/preset-typescript": "^7.3.3",
"@fullhuman/postcss-purgecss": "^1.1.0",
"@types/jest": "^24.0.15",
"@types/lodash": "^4.14.133",
"babel-loader": "^8.0.6",
"css-loader": "^3.0.0",
"husky": "^1.3.1",
"jest": "^24.8.0",
"lint-staged": "^8.1.5",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.6.0",
"prettier": "^1.16.4",
"style-loader": "^0.23.1",
"tailwindcss": "^1.0.4",
"typescript": "^3.5.2",
"vue": "^2.6.10",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && yarn build && git add resources/compiled/ignition.js"
}
},
"lint-staged": {
"linters": {
"*.{css,js,ts,vue}": [
"yarn format",
"git add"
]
},
"ignore": [
"resources/compiled/**/*"
]
},
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"/__helpers__/"
]
}
}

View File

@@ -0,0 +1,29 @@
const purgecss = require('@fullhuman/postcss-purgecss');
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss')('./tailwind.config.js'),
require('postcss-preset-env')(),
process.env.NODE_ENV === 'production'
? purgecss({
content: [
'./resources/js/**/*.js',
'./resources/js/**/*.vue',
'./resources/views/errorPage.php',
],
extractors: [
{
extractor: class {
static extract(content) {
return content.match(/[a-zA-Z0-9-:_/]+/g) || [];
}
},
extensions: ['js', 'php', 'vue'],
},
],
whitelistPatterns: [/hljs/, /sf-dump/, /theme-dark/, /theme-auto/],
})
: '',
],
};

View File

@@ -0,0 +1,3 @@
compiled/*
!compiled/index.html
!compiled/ignition.js

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Vue App</title>
<link href="/flare.js" rel="preload" as="script"></head>
<body>
<div id="app"></div>
<script type="text/javascript" src="/flare.js"></script></body>
</html>

View File

@@ -0,0 +1,63 @@
<!doctype html>
<html class="theme-<?=$config['theme']?>">
<!--
<?=$throwableString?>
-->
<head>
<!-- Hide dumps asap -->
<style>
pre.sf-dump {
display: none !important;
}
</style>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="robots" content="noindex, nofollow">
<title><?= $title ?></title>
<?php foreach ($styles as $script): ?>
<link rel="stylesheet" href="<?=$housekeepingEndpoint?>/styles/<?=$script?>">
<?php endforeach; ?>
</head>
<body class="scrollbar-lg">
<script>
window.data = <?=
$jsonEncode([
'report' => $report,
'config' => $config,
'solutions' => $solutions,
'telescopeUrl' => $telescopeUrl,
'shareEndpoint' => $shareEndpoint,
'defaultTab' => $defaultTab,
'defaultTabProps' => $defaultTabProps,
])
?>
window.tabs = <?=$tabs?>;
</script>
<noscript><pre><?=$throwableString?></pre></noscript>
<div id="app"></div>
<script><?= $getAssetContents('ignition.js') ?></script>
<script>
window.Ignition = window.ignite(window.data);
</script>
<?php foreach ($scripts as $script): ?>
<script src="<?=$housekeepingEndpoint?>/scripts/<?=$script?>"></script>
<?php endforeach; ?>
<script>
Ignition.start();
</script>
<!--
<?=$throwableString?>
-->
</body>
</html>

View File

@@ -0,0 +1,167 @@
<?php
namespace Facade\Ignition\Actions;
use Exception;
use Facade\FlareClient\Http\Client;
use Facade\FlareClient\Truncation\ReportTrimmer;
use Facade\Ignition\Exceptions\UnableToShareErrorException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
class ShareReportAction
{
/** @var array */
protected $tabs;
/** @var \Facade\FlareClient\Http\Client */
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function handle(array $report, array $tabs, ?string $lineSelection = null)
{
$this->tabs = $tabs;
$report = $this->filterReport($report);
try {
return $this->client->post('public-reports', [
'report' => $this->trimReport($report),
'tabs' => $tabs,
'lineSelection' => $lineSelection,
]);
} catch (Exception $exception) {
throw new UnableToShareErrorException($exception->getMessage());
}
}
public function filterReport(array $report): array
{
if (! $this->hasTab('stackTraceTab')) {
$report['stacktrace'] = array_slice($report['stacktrace'], 0, 1);
}
if (! $this->hasTab('debugTab')) {
$report['glows'] = [];
}
$report['context'] = $this->filterContextItems($report['context']);
return $report;
}
protected function hasTab(string $tab): bool
{
return in_array($tab, $this->tabs);
}
protected function filterContextItems(array $contextItems): array
{
if (! $this->hasTab('requestTab')) {
$contextItems = $this->removeRequestInformation($contextItems);
}
if (! $this->hasTab('appTab')) {
$contextItems = $this->removeAppInformation($contextItems);
}
if (! $this->hasTab('userTab')) {
$contextItems = $this->removeUserInformation($contextItems);
}
if (! $this->hasTab('contextTab')) {
$contextItems = $this->removeContextInformation($contextItems);
}
if (! $this->hasTab('debugTab')) {
$contextItems = $this->removeDebugInformation($contextItems);
}
return $contextItems;
}
protected function removeRequestInformation(array $contextItems): array
{
Arr::forget($contextItems, 'request');
Arr::forget($contextItems, 'request_data');
Arr::forget($contextItems, 'headers');
Arr::forget($contextItems, 'session');
Arr::forget($contextItems, 'cookies');
return $contextItems;
}
protected function removeAppInformation(array $contextItems): array
{
Arr::forget($contextItems, 'view');
Arr::forget($contextItems, 'route');
return $contextItems;
}
protected function removeUserInformation(array $contextItems): array
{
Arr::forget($contextItems, 'user');
Arr::forget($contextItems, 'request.ip');
Arr::forget($contextItems, 'request.useragent');
return $contextItems;
}
protected function removeContextInformation(array $contextItems): array
{
Arr::forget($contextItems, 'env');
Arr::forget($contextItems, 'git');
Arr::forget($contextItems, 'context');
Arr::forget($contextItems, $this->getCustomContextGroups($contextItems));
return $contextItems;
}
protected function removeDebugInformation(array $contextItems): array
{
Arr::forget($contextItems, 'dumps');
Arr::forget($contextItems, 'glows');
Arr::forget($contextItems, 'logs');
Arr::forget($contextItems, 'queries');
return $contextItems;
}
protected function getCustomContextGroups(array $contextItems): array
{
$predefinedContextItemGroups = [
'request',
'request_data',
'headers',
'session',
'cookies',
'view',
'queries',
'route',
'user',
'env',
'git',
'context',
'logs',
'dumps',
];
return Collection::make($contextItems)
->reject(function ($value, $group) use ($predefinedContextItemGroups) {
return in_array($group, $predefinedContextItemGroups);
})
->keys()
->toArray();
}
protected function trimReport(array $report): array
{
return (new ReportTrimmer())->trim($report);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Facade\Ignition\Commands;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
class SolutionMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'ignition:make-solution';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new custom Ignition solution class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Solution';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->option('runnable')
? __DIR__.'/stubs/runnable-solution.stub'
: __DIR__.'/stubs/solution.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Solutions';
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['runnable', null, InputOption::VALUE_NONE, 'Create runnable solution'],
];
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Facade\Ignition\Commands;
use Exception;
use Illuminate\Config\Repository;
use Illuminate\Console\Command;
use Illuminate\Log\LogManager;
class TestCommand extends Command
{
protected $signature = 'flare:test';
protected $description = 'Send a test notification to Flare';
/** @var \Illuminate\Config\Repository */
protected $config;
public function handle(Repository $config)
{
$this->config = $config;
$this->checkFlareKey();
if (app()->make('log') instanceof LogManager) {
$this->checkFlareLogger();
}
$this->sendTestException();
}
protected function checkFlareKey()
{
$message = empty($this->config->get('flare.key'))
? '❌ Flare key not specified. Make sure you specify a value in the `key` key of the `flare` config file.'
: '✅ Flare key specified';
$this->info($message);
return $this;
}
public function checkFlareLogger()
{
$defaultLogChannel = $this->config->get('logging.default');
$activeStack = $this->config->get("logging.channels.{$defaultLogChannel}");
if (is_null($activeStack)) {
$this->info("❌ The default logging channel `{$defaultLogChannel}` is not configured in the `logging` config file");
}
if (! isset($activeStack['channels']) || ! in_array('flare', $activeStack['channels'])) {
$this->info("❌ The logging channel `{$defaultLogChannel}` does not contain the 'flare' channel");
}
if (is_null($this->config->get('logging.channels.flare'))) {
$this->info('❌ There is no logging channel named `flare` in the `logging` config file');
}
if ($this->config->get('logging.channels.flare.driver') !== 'flare') {
$this->info('❌ The `flare` logging channel defined in the `logging` config file is not set to `flare`.');
}
$this->info('✅ The Flare logging driver was configured correctly.');
return $this;
}
protected function sendTestException()
{
$testException = new Exception('This is an exception to test if the integration with Flare works.');
try {
app('flare.client')->sendTestReport($testException);
$this->info(PHP_EOL);
} catch (Exception $exception) {
$this->warn('❌ We were unable to send an exception to Flare. Make sure that your key is correct and that you have a valid subscription. '.PHP_EOL.PHP_EOL.'For more info visit the docs on installing Flare in a Laravel project: https://flareapp.io/docs/ignition-for-laravel/introduction');
return;
}
$this->info('We tried to send an exception to Flare. Please check if it arrived!');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace DummyNamespace;
use Facade\IgnitionContracts\RunnableSolution;
class DummyClass implements RunnableSolution
{
public function getSolutionTitle(): string
{
return '';
}
public function getDocumentationLinks(): array
{
return [];
}
public function getSolutionActionDescription(): string
{
return '';
}
public function getRunButtonText(): string
{
return '';
}
public function getSolutionDescription(): string
{
return '';
}
public function getRunParameters(): array
{
return [];
}
public function run(array $parameters = [])
{
//
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace DummyNamespace;
use Facade\IgnitionContracts\Solution;
class DummyClass implements Solution
{
public function getSolutionTitle(): string
{
return '';
}
public function getSolutionDescription(): string
{
return '';
}
public function getDocumentationLinks(): array
{
return [];
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Facade\Ignition\Context;
use Facade\FlareClient\Context\ConsoleContext;
class LaravelConsoleContext extends ConsoleContext
{
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Facade\Ignition\Context;
use Facade\FlareClient\Context\ContextDetectorInterface;
use Facade\FlareClient\Context\ContextInterface;
use Illuminate\Http\Request;
class LaravelContextDetector implements ContextDetectorInterface
{
public function detectCurrentContext(): ContextInterface
{
if (app()->runningInConsole()) {
return new LaravelConsoleContext($_SERVER['argv'] ?? []);
}
return new LaravelRequestContext(app(Request::class));
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Facade\Ignition\Context;
use Facade\FlareClient\Context\RequestContext;
use Illuminate\Http\Request;
class LaravelRequestContext extends RequestContext
{
/** @var \Illuminate\Http\Request */
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function getUser(): array
{
$user = $this->request->user();
if (! $user) {
return [];
}
try {
if (method_exists($user, 'toFlare')) {
return $user->toFlare();
}
if (method_exists($user, 'toArray')) {
return $user->toArray();
}
} catch (\Throwable $e) {
return [];
}
return [];
}
public function getRoute(): array
{
$route = $this->request->route();
return [
'route' => optional($route)->getName(),
'routeParameters' => $this->getRouteParameters(),
'controllerAction' => optional($route)->getActionName(),
'middleware' => array_values(optional($route)->gatherMiddleware() ?? []),
];
}
protected function getRouteParameters(): array
{
try {
return collect(optional($this->request->route())->parameters ?? [])->toArray();
} catch (\Throwable $e) {
return [];
}
}
public function toArray(): array
{
$properties = parent::toArray();
$properties['route'] = $this->getRoute();
$properties['user'] = $this->getUser();
return $properties;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Facade\Ignition\DumpRecorder;
class Dump
{
/** @var string */
protected $htmlDump;
/** @var ?string */
protected $file;
/** @var ?int */
protected $lineNumber;
/** @var float */
protected $microtime;
public function __construct(string $htmlDump, ?string $file, ?int $lineNumber, ?float $microtime = null)
{
$this->htmlDump = $htmlDump;
$this->file = $file;
$this->lineNumber = $lineNumber;
$this->microtime = $microtime ?? microtime(true);
}
public function toArray(): array
{
return [
'html_dump' => $this->htmlDump,
'file' => $this->file,
'line_number' => $this->lineNumber,
'microtime' => $this->microtime,
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Facade\Ignition\DumpRecorder;
use Symfony\Component\VarDumper\Cloner\VarCloner;
class DumpHandler
{
/** @var \Facade\Flare\DumpRecorder\DumpRecorder */
protected $dumpRecorder;
public function __construct(DumpRecorder $dumpRecorder)
{
$this->dumpRecorder = $dumpRecorder;
}
public function dump($value)
{
$data = (new VarCloner)->cloneVar($value);
$this->dumpRecorder->record($data);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Facade\Ignition\DumpRecorder;
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper as BaseHtmlDumper;
use Symfony\Component\VarDumper\VarDumper;
class DumpRecorder
{
protected $dumps = [];
/** @var \Illuminate\Foundation\Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function register(): self
{
$multiDumpHandler = new MultiDumpHandler();
$this->app->singleton(MultiDumpHandler::class, $multiDumpHandler);
$previousHandler = VarDumper::setHandler(function ($var) use ($multiDumpHandler) {
$multiDumpHandler->dump($var);
});
if ($previousHandler) {
$multiDumpHandler->addHandler($previousHandler);
} else {
$multiDumpHandler->addHandler($this->getDefaultHandler());
}
$multiDumpHandler->addHandler(function ($var) {
$this->app->make(DumpHandler::class)->dump($var);
});
return $this;
}
public function record(Data $data)
{
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7);
$file = Arr::get($backtrace, '6.file');
$lineNumber = Arr::get($backtrace, '6.line');
$htmlDump = (new HtmlDumper())->dump($data);
$this->dumps[] = new Dump($htmlDump, $file, $lineNumber);
}
public function getDumps(): array
{
return $this->toArray();
}
public function reset()
{
$this->dumps = [];
}
public function toArray(): array
{
$dumps = [];
foreach ($this->dumps as $dump) {
$dumps[] = $dump->toArray();
}
return $dumps;
}
protected function getDefaultHandler()
{
return function ($value) {
$data = (new VarCloner)->cloneVar($value);
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new BaseHtmlDumper;
$dumper->dump($data);
};
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Facade\Ignition\DumpRecorder;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper as BaseHtmlDumper;
class HtmlDumper extends BaseHtmlDumper
{
protected $dumpHeader = '';
public function dumpVariable($variable): string
{
$cloner = new VarCloner();
$clonedData = $cloner->cloneVar($variable)->withMaxDepth(3);
return $this->dump($clonedData);
}
public function dump(Data $data, $output = null, array $extraDisplayOptions = []): string
{
return parent::dump($data, true, [
'maxDepth' => 3,
'maxStringLength' => 160,
]);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Facade\Ignition\DumpRecorder;
class MultiDumpHandler
{
/** @var array */
protected $handlers = [];
public function dump($value)
{
foreach ($this->handlers as $handler) {
$handler($value);
}
}
public function addHandler(callable $callable = null): self
{
$this->handlers[] = $callable;
return $this;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Facade\Ignition\ErrorPage;
use Facade\FlareClient\Report;
use Facade\Ignition\IgnitionConfig;
use Facade\IgnitionContracts\SolutionProviderRepository;
use Illuminate\Foundation\Application;
use Throwable;
class ErrorPageHandler
{
/** @var \Facade\Ignition\IgnitionConfig */
protected $ignitionConfig;
/** @var \Facade\Ignition\Facades\Flare */
protected $flareClient;
/** @var \Facade\Ignition\ErrorPage\Renderer */
protected $renderer;
/** @var \Facade\IgnitionContracts\SolutionProviderRepository */
protected $solutionProviderRepository;
public function __construct(
Application $app,
IgnitionConfig $ignitionConfig,
Renderer $renderer,
SolutionProviderRepository $solutionProviderRepository
) {
$this->flareClient = $app->make('flare.client');
$this->ignitionConfig = $ignitionConfig;
$this->renderer = $renderer;
$this->solutionProviderRepository = $solutionProviderRepository;
}
public function handle(Throwable $throwable, $defaultTab = null, $defaultTabProps = [])
{
$report = $this->flareClient->createReport($throwable);
$solutions = $this->solutionProviderRepository->getSolutionsForThrowable($throwable);
$viewModel = new ErrorPageViewModel(
$throwable,
$this->ignitionConfig,
$report,
$solutions
);
$viewModel->defaultTab($defaultTab, $defaultTabProps);
$this->renderException($viewModel);
}
public function handleReport(Report $report, $defaultTab = null, $defaultTabProps = [])
{
$viewModel = new ErrorPageViewModel(
$report->getThrowable(),
$this->ignitionConfig,
$report,
[]
);
$viewModel->defaultTab($defaultTab, $defaultTabProps);
$this->renderException($viewModel);
}
protected function renderException(ErrorPageViewModel $exceptionViewModel)
{
echo $this->renderer->render(
'errorPage',
$exceptionViewModel->toArray()
);
}
}

View File

@@ -0,0 +1,189 @@
<?php
namespace Facade\Ignition\ErrorPage;
use Closure;
use Exception;
use Facade\FlareClient\Report;
use Facade\Ignition\Ignition;
use Facade\Ignition\IgnitionConfig;
use Facade\Ignition\Solutions\SolutionTransformer;
use Illuminate\Contracts\Support\Arrayable;
use Laravel\Telescope\Http\Controllers\HomeController;
use Laravel\Telescope\IncomingExceptionEntry;
use Laravel\Telescope\Telescope;
use Throwable;
class ErrorPageViewModel implements Arrayable
{
/** @var \Throwable|null */
protected $throwable;
/** @var array */
protected $solutions;
/** @var \Facade\Ignition\IgnitionConfig */
protected $ignitionConfig;
/** @var \Facade\FlareClient\Report */
protected $report;
/** @var string */
protected $defaultTab;
/** @var array */
protected $defaultTabProps = [];
public function __construct(?Throwable $throwable, IgnitionConfig $ignitionConfig, Report $report, array $solutions)
{
$this->throwable = $throwable;
$this->ignitionConfig = $ignitionConfig;
$this->report = $report;
$this->solutions = $solutions;
}
public function throwableString(): string
{
if (! $this->throwable) {
return '';
}
return sprintf(
"%s: %s in file %s on line %d\n\n%s\n",
get_class($this->throwable),
$this->throwable->getMessage(),
$this->throwable->getFile(),
$this->throwable->getLine(),
$this->report->getThrowable()->getTraceAsString()
);
}
public function telescopeUrl(): ?string
{
try {
if (! class_exists(Telescope::class)) {
return null;
}
if (! count(Telescope::$entriesQueue)) {
return null;
}
$telescopeEntry = collect(Telescope::$entriesQueue)->first(function ($entry) {
return $entry instanceof IncomingExceptionEntry;
});
if (is_null($telescopeEntry)) {
return null;
}
$telescopeEntryId = (string) $telescopeEntry->uuid;
return url(action([HomeController::class, 'index'])."/exceptions/{$telescopeEntryId}");
} catch (Exception $exception) {
return null;
}
}
public function title(): string
{
return "🧨 {$this->report->getMessage()}";
}
public function config(): array
{
return $this->ignitionConfig->toArray();
}
public function solutions(): array
{
$solutions = [];
foreach ($this->solutions as $solution) {
$solutions[] = (new SolutionTransformer($solution))->toArray();
}
return $solutions;
}
protected function shareEndpoint(): string
{
try {
// use string notation as L5.5 and L5.6 don't support array notation yet
return action('\Facade\Ignition\Http\Controllers\ShareReportController');
} catch (Exception $exception) {
return '';
}
}
public function report(): array
{
return $this->report->toArray();
}
public function jsonEncode($data): string
{
$jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
if (version_compare(phpversion(), '7.2', '>=')) {
return json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | $jsonOptions);
}
return json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | $jsonOptions);
}
public function getAssetContents(string $asset): string
{
$assetPath = __DIR__."/../../resources/compiled/{$asset}";
return file_get_contents($assetPath);
}
public function styles(): array
{
return array_keys(Ignition::styles());
}
public function scripts(): array
{
return array_keys(Ignition::scripts());
}
public function tabs(): string
{
return json_encode(Ignition::$tabs);
}
public function defaultTab(?string $defaultTab, ?array $defaultTabProps)
{
$this->defaultTab = $defaultTab ?? 'StackTab';
if ($defaultTabProps) {
$this->defaultTabProps = $defaultTabProps;
}
}
public function toArray(): array
{
return [
'throwableString' => $this->throwableString(),
'telescopeUrl' => $this->telescopeUrl(),
'shareEndpoint' => $this->shareEndpoint(),
'title' => $this->title(),
'config' => $this->config(),
'solutions' => $this->solutions(),
'report' => $this->report(),
'housekeepingEndpoint' => url(config('ignition.housekeeping_endpoint_prefix', '_ignition')),
'styles' => $this->styles(),
'scripts' => $this->scripts(),
'tabs' => $this->tabs(),
'jsonEncode' => Closure::fromCallable([$this, 'jsonEncode']),
'getAssetContents' => Closure::fromCallable([$this, 'getAssetContents']),
'defaultTab' => $this->defaultTab,
'defaultTabProps' => $this->defaultTabProps,
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Facade\Ignition\ErrorPage;
use Error;
use ErrorException;
use Whoops\Handler\Handler;
class IgnitionWhoopsHandler extends Handler
{
/** @var \Facade\Ignition\ErrorPage\ErrorPageHandler */
protected $errorPageHandler;
/** @var \Throwable */
protected $exception;
public function __construct(ErrorPageHandler $errorPageHandler)
{
$this->errorPageHandler = $errorPageHandler;
}
public function handle(): ?int
{
try {
$this->errorPageHandler->handle($this->exception);
} catch (Error $error) {
// Errors aren't caught by Whoops.
// Convert the error to an exception and throw again.
throw new ErrorException(
$error->getMessage(),
$error->getCode(),
1,
$error->getFile(),
$error->getLine(),
$error
);
}
return Handler::QUIT;
}
/** @param \Throwable $exception */
public function setException($exception): void
{
$this->exception = $exception;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Facade\Ignition\ErrorPage;
use Exception;
use Facade\Ignition\Exceptions\ViewException;
class Renderer
{
/** @var string */
protected $viewPath;
public function __construct(string $viewPath)
{
$this->viewPath = $this->formatPath($viewPath);
}
public function render(string $viewName, array $_data): string
{
ob_start();
$viewFile = "{$this->viewPath}/{$viewName}.php";
try {
extract((array) $_data, EXTR_OVERWRITE);
include $viewFile;
} catch (Exception $exception) {
$viewException = new ViewException($exception->getMessage());
$viewException->setView($viewFile);
$viewException->setViewData($_data);
throw $viewException;
}
return ob_get_clean();
}
protected function formatPath(string $path): string
{
return preg_replace('/(?:\/)+$/u', '', $path).'/';
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Facade\Ignition\Exceptions;
use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Monolog\Logger;
class InvalidConfig extends Exception implements ProvidesSolution
{
public static function invalidLogLevel(string $logLevel)
{
return new static("Invalid log level `{$logLevel}` specified.");
}
public function getSolution(): Solution
{
$validLogLevels = array_map(function (string $level) {
return strtolower($level);
}, array_keys(Logger::getLevels()));
$validLogLevelsString = implode(',', $validLogLevels);
return BaseSolution::create('You provided an invalid log level')
->setSolutionDescription("Please change the log level in your `config/logging.php` file. Valid log levels are {$validLogLevelsString}.");
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Facade\Ignition\Exceptions;
use Exception;
class UnableToShareErrorException extends Exception
{
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Facade\Ignition\Exceptions;
use ErrorException;
use Facade\FlareClient\Contracts\ProvidesFlareContext;
use Facade\Ignition\DumpRecorder\HtmlDumper;
class ViewException extends ErrorException implements ProvidesFlareContext
{
/** @var array */
protected $viewData = [];
/** @var string */
protected $view = '';
public function setViewData(array $data)
{
$this->viewData = $data;
}
public function getViewData(): array
{
return $this->viewData;
}
public function setView(string $path)
{
$this->view = $path;
}
protected function dumpViewData($variable): string
{
return (new HtmlDumper())->dumpVariable($variable);
}
public function context(): array
{
$context = [
'view' => [
'view' => $this->view,
],
];
if (config('flare.reporting.report_view_data')) {
$context['view']['data'] = array_map([$this, 'dumpViewData'], $this->viewData);
}
return $context;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Facade\Ignition\Exceptions;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
class ViewExceptionWithSolution extends ViewException implements ProvidesSolution
{
/** @var Solution */
protected $solution;
public function setSolution(Solution $solution)
{
$this->solution = $solution;
}
public function getSolution(): Solution
{
return $this->solution;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Facade\Ignition\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class Flare.
*
* @method static void glow(string $name, string $messageLevel = \Facade\FlareClient\Enums\MessageLevels::INFO, array $metaData = [])
* @method static void context($key, $value)
* @method static void group(string $groupName, array $properties)
*
* @see \Facade\FlareClient\Flare
*/
class Flare extends Facade
{
protected static function getFacadeAccessor()
{
return 'flare.client';
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Facade\Ignition\Http\Controllers;
use Facade\Ignition\Http\Requests\ExecuteSolutionRequest;
use Facade\IgnitionContracts\SolutionProviderRepository;
use Illuminate\Foundation\Validation\ValidatesRequests;
class ExecuteSolutionController
{
use ValidatesRequests;
public function __invoke(
ExecuteSolutionRequest $request,
SolutionProviderRepository $solutionProviderRepository
) {
$this->ensureLocalEnvironment();
$this->ensureLocalRequest();
$solution = $request->getRunnableSolution();
$solution->run($request->get('parameters', []));
return response('');
}
public function ensureLocalEnvironment()
{
if (! app()->environment('local')) {
abort(403, "Runnable solutions are disabled in non-local environments. Please make sure `APP_ENV` is set correctly. Additionally please make sure `APP_DEBUG` is set to false on ANY production environment!");
}
}
public function ensureLocalRequest()
{
$ipIsPublic = filter_var(
request()->ip(),
FILTER_VALIDATE_IP,
FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
);
if ($ipIsPublic) {
abort(403, "Solutions can only be executed by requests from a local IP address. Please also make sure `APP_DEBUG` is set to false on ANY production environment.");
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Facade\Ignition\Http\Controllers;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
class HealthCheckController
{
public function __invoke()
{
return [
'can_execute_commands' => $this->canExecuteCommands(),
];
}
protected function canExecuteCommands(): bool
{
Artisan::call('help', ['--version']);
$output = Artisan::output();
return Str::contains($output, app()->version());
}
}

Some files were not shown because too many files have changed in this diff Show More