One Hat Cyber Team
Your IP:
216.73.216.30
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
proc
/
self
/
root
/
proc
/
thread-self
/
cwd
/
View File Name :
Solutions.tar
SolutionTransformer.php 0000644 00000001570 15110366412 0011316 0 ustar 00 <?php namespace Spatie\Ignition\Solutions; use Illuminate\Contracts\Support\Arrayable; use Spatie\Ignition\Contracts\Solution; /** @implements Arrayable<string, array<string,string>|string|false> */ class SolutionTransformer implements Arrayable { protected Solution $solution; public function __construct(Solution $solution) { $this->solution = $solution; } /** @return array<string, array<string,string>|string|false> */ public function toArray(): array { return [ 'class' => get_class($this->solution), 'title' => $this->solution->getSolutionTitle(), 'links' => $this->solution->getDocumentationLinks(), 'description' => $this->solution->getSolutionDescription(), 'is_runnable' => false, 'ai_generated' => $this->solution->aiGenerated ?? false, ]; } } SolutionProviders/BadMethodCallSolutionProvider.php 0000644 00000005233 15110366412 0016664 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\SolutionProviders; use BadMethodCallException; use Illuminate\Support\Collection; use ReflectionClass; use ReflectionMethod; use Spatie\Ignition\Contracts\BaseSolution; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; use Throwable; class BadMethodCallSolutionProvider implements HasSolutionsForThrowable { protected const REGEX = '/([a-zA-Z\\\\]+)::([a-zA-Z]+)/m'; public function canSolve(Throwable $throwable): bool { if (! $throwable instanceof BadMethodCallException) { return false; } if (is_null($this->getClassAndMethodFromExceptionMessage($throwable->getMessage()))) { return false; } return true; } public function getSolutions(Throwable $throwable): array { return [ BaseSolution::create('Bad Method Call') ->setSolutionDescription($this->getSolutionDescription($throwable)), ]; } public function getSolutionDescription(Throwable $throwable): string { if (! $this->canSolve($throwable)) { return ''; } /** @phpstan-ignore-next-line */ extract($this->getClassAndMethodFromExceptionMessage($throwable->getMessage()), EXTR_OVERWRITE); $possibleMethod = $this->findPossibleMethod($class ?? '', $method ?? ''); $class ??= 'UnknownClass'; return "Did you mean {$class}::{$possibleMethod?->name}() ?"; } /** * @param string $message * * @return null|array<string, mixed> */ protected function getClassAndMethodFromExceptionMessage(string $message): ?array { if (! preg_match(self::REGEX, $message, $matches)) { return null; } return [ 'class' => $matches[1], 'method' => $matches[2], ]; } /** * @param class-string $class * @param string $invalidMethodName * * @return \ReflectionMethod|null */ protected function findPossibleMethod(string $class, string $invalidMethodName): ?ReflectionMethod { return $this->getAvailableMethods($class) ->sortByDesc(function (ReflectionMethod $method) use ($invalidMethodName) { similar_text($invalidMethodName, $method->name, $percentage); return $percentage; })->first(); } /** * @param class-string $class * * @return \Illuminate\Support\Collection<int, ReflectionMethod> */ protected function getAvailableMethods(string $class): Collection { $class = new ReflectionClass($class); return Collection::make($class->getMethods()); } } SolutionProviders/MergeConflictSolutionProvider.php 0000644 00000004070 15110366412 0016760 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\SolutionProviders; use Illuminate\Support\Str; use ParseError; use Spatie\Ignition\Contracts\BaseSolution; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; use Throwable; class MergeConflictSolutionProvider implements HasSolutionsForThrowable { public function canSolve(Throwable $throwable): bool { if (! ($throwable instanceof ParseError)) { return false; } if (! $this->hasMergeConflictExceptionMessage($throwable)) { return false; } $file = (string)file_get_contents($throwable->getFile()); if (! str_contains($file, '=======')) { return false; } if (! str_contains($file, '>>>>>>>')) { return false; } return true; } public function getSolutions(Throwable $throwable): array { $file = (string)file_get_contents($throwable->getFile()); preg_match('/\>\>\>\>\>\>\> (.*?)\n/', $file, $matches); $source = $matches[1]; $target = $this->getCurrentBranch(basename($throwable->getFile())); return [ BaseSolution::create("Merge conflict from branch '$source' into $target") ->setSolutionDescription('You have a Git merge conflict. To undo your merge do `git reset --hard HEAD`'), ]; } protected function getCurrentBranch(string $directory): string { $branch = "'".trim((string)shell_exec("cd {$directory}; git branch | grep \\* | cut -d ' ' -f2"))."'"; if ($branch === "''") { $branch = 'current branch'; } return $branch; } protected function hasMergeConflictExceptionMessage(Throwable $throwable): bool { // For PHP 7.x and below if (Str::startsWith($throwable->getMessage(), 'syntax error, unexpected \'<<\'')) { return true; } // For PHP 8+ if (Str::startsWith($throwable->getMessage(), 'syntax error, unexpected token "<<"')) { return true; } return false; } } SolutionProviders/SolutionProviderRepository.php 0000644 00000006547 15110366412 0016431 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\SolutionProviders; use Illuminate\Support\Collection; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; use Spatie\Ignition\Contracts\ProvidesSolution; use Spatie\Ignition\Contracts\Solution; use Spatie\Ignition\Contracts\SolutionProviderRepository as SolutionProviderRepositoryContract; use Throwable; class SolutionProviderRepository implements SolutionProviderRepositoryContract { /** @var Collection<int, class-string<HasSolutionsForThrowable>|HasSolutionsForThrowable> */ protected Collection $solutionProviders; /** @param array<int, class-string<HasSolutionsForThrowable>|HasSolutionsForThrowable> $solutionProviders */ public function __construct(array $solutionProviders = []) { $this->solutionProviders = Collection::make($solutionProviders); } public function registerSolutionProvider(string|HasSolutionsForThrowable $solutionProvider): SolutionProviderRepositoryContract { $this->solutionProviders->push($solutionProvider); return $this; } public function registerSolutionProviders(array $solutionProviderClasses): SolutionProviderRepositoryContract { $this->solutionProviders = $this->solutionProviders->merge($solutionProviderClasses); return $this; } public function getSolutionsForThrowable(Throwable $throwable): array { $solutions = []; if ($throwable instanceof Solution) { $solutions[] = $throwable; } if ($throwable instanceof ProvidesSolution) { $solutions[] = $throwable->getSolution(); } $providedSolutions = $this ->initialiseSolutionProviderRepositories() ->filter(function (HasSolutionsForThrowable $solutionProvider) use ($throwable) { try { return $solutionProvider->canSolve($throwable); } catch (Throwable $exception) { return false; } }) ->map(function (HasSolutionsForThrowable $solutionProvider) use ($throwable) { try { return $solutionProvider->getSolutions($throwable); } catch (Throwable $exception) { return []; } }) ->flatten() ->toArray(); return array_merge($solutions, $providedSolutions); } public function getSolutionForClass(string $solutionClass): ?Solution { if (! class_exists($solutionClass)) { return null; } if (! in_array(Solution::class, class_implements($solutionClass) ?: [])) { return null; } if (! function_exists('app')) { return null; } return app($solutionClass); } /** @return Collection<int, HasSolutionsForThrowable> */ protected function initialiseSolutionProviderRepositories(): Collection { return $this->solutionProviders ->filter(fn (HasSolutionsForThrowable|string $provider) => in_array(HasSolutionsForThrowable::class, class_implements($provider) ?: [])) ->map(function (string|HasSolutionsForThrowable $provider): HasSolutionsForThrowable { if (is_string($provider)) { return new $provider; } return $provider; }); } } SolutionProviders/UndefinedPropertySolutionProvider.php 0000644 00000006726 15110366412 0017717 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\SolutionProviders; use ErrorException; use Illuminate\Support\Collection; use ReflectionClass; use ReflectionProperty; use Spatie\Ignition\Contracts\BaseSolution; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; use Throwable; class UndefinedPropertySolutionProvider implements HasSolutionsForThrowable { protected const REGEX = '/([a-zA-Z\\\\]+)::\$([a-zA-Z]+)/m'; protected const MINIMUM_SIMILARITY = 80; public function canSolve(Throwable $throwable): bool { if (! $throwable instanceof ErrorException) { return false; } if (is_null($this->getClassAndPropertyFromExceptionMessage($throwable->getMessage()))) { return false; } if (! $this->similarPropertyExists($throwable)) { return false; } return true; } public function getSolutions(Throwable $throwable): array { return [ BaseSolution::create('Unknown Property') ->setSolutionDescription($this->getSolutionDescription($throwable)), ]; } public function getSolutionDescription(Throwable $throwable): string { if (! $this->canSolve($throwable) || ! $this->similarPropertyExists($throwable)) { return ''; } extract( /** @phpstan-ignore-next-line */ $this->getClassAndPropertyFromExceptionMessage($throwable->getMessage()), EXTR_OVERWRITE, ); $possibleProperty = $this->findPossibleProperty($class ?? '', $property ?? ''); $class = $class ?? ''; return "Did you mean {$class}::\${$possibleProperty->name} ?"; } protected function similarPropertyExists(Throwable $throwable): bool { /** @phpstan-ignore-next-line */ extract($this->getClassAndPropertyFromExceptionMessage($throwable->getMessage()), EXTR_OVERWRITE); $possibleProperty = $this->findPossibleProperty($class ?? '', $property ?? ''); return $possibleProperty !== null; } /** * @param string $message * * @return null|array<string, string> */ protected function getClassAndPropertyFromExceptionMessage(string $message): ?array { if (! preg_match(self::REGEX, $message, $matches)) { return null; } return [ 'class' => $matches[1], 'property' => $matches[2], ]; } /** * @param class-string $class * @param string $invalidPropertyName * * @return mixed */ protected function findPossibleProperty(string $class, string $invalidPropertyName): mixed { return $this->getAvailableProperties($class) ->sortByDesc(function (ReflectionProperty $property) use ($invalidPropertyName) { similar_text($invalidPropertyName, $property->name, $percentage); return $percentage; }) ->filter(function (ReflectionProperty $property) use ($invalidPropertyName) { similar_text($invalidPropertyName, $property->name, $percentage); return $percentage >= self::MINIMUM_SIMILARITY; })->first(); } /** * @param class-string $class * * @return Collection<int, ReflectionProperty> */ protected function getAvailableProperties(string $class): Collection { $class = new ReflectionClass($class); return Collection::make($class->getProperties()); } } SuggestImportSolution.php 0000644 00000001140 15110366412 0011621 0 ustar 00 <?php namespace Spatie\Ignition\Solutions; use Spatie\Ignition\Contracts\Solution; class SuggestImportSolution implements Solution { protected string $class; public function __construct(string $class) { $this->class = $class; } public function getSolutionTitle(): string { return 'A class import is missing'; } public function getSolutionDescription(): string { return 'You have a missing class import. Try importing this class: `'.$this->class.'`.'; } public function getDocumentationLinks(): array { return []; } } OpenAi/DummyCache.php 0000644 00000001627 15110366412 0010454 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\OpenAi; use Psr\SimpleCache\CacheInterface; class DummyCache implements CacheInterface { public function get(string $key, mixed $default = null): mixed { return null; } public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool { return true; } public function delete(string $key): bool { return true; } public function clear(): bool { return true; } public function getMultiple(iterable $keys, mixed $default = null): iterable { return []; } public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool { return true; } public function deleteMultiple(iterable $keys): bool { return true; } public function has(string $key): bool { return false; } } OpenAi/OpenAiSolutionProvider.php 0000644 00000003011 15110366412 0013045 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\OpenAi; use Psr\SimpleCache\CacheInterface; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; use Throwable; class OpenAiSolutionProvider implements HasSolutionsForThrowable { public function __construct( protected string $openAiKey, protected ?CacheInterface $cache = null, protected int $cacheTtlInSeconds = 60 * 60, protected string|null $applicationType = null, protected string|null $applicationPath = null, ) { $this->cache ??= new DummyCache(); } public function canSolve(Throwable $throwable): bool { return true; } public function getSolutions(Throwable $throwable): array { return [ new OpenAiSolution( $throwable, $this->openAiKey, $this->cache, $this->cacheTtlInSeconds, $this->applicationType, $this->applicationPath, ), ]; } public function applicationType(string $applicationType): self { $this->applicationType = $applicationType; return $this; } public function applicationPath(string $applicationPath): self { $this->applicationPath = $applicationPath; return $this; } public function useCache(CacheInterface $cache, int $cacheTtlInSeconds = 60 * 60): self { $this->cache = $cache; $this->cacheTtlInSeconds = $cacheTtlInSeconds; return $this; } } OpenAi/OpenAiSolutionResponse.php 0000644 00000002635 15110366412 0013064 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\OpenAi; class OpenAiSolutionResponse { protected string $rawText; public function __construct(string $rawText) { $this->rawText = trim($rawText); } public function description(): string { return $this->between('FIX', 'ENDFIX', $this->rawText); } public function links(): array { $textLinks = $this->between('LINKS', 'ENDLINKS', $this->rawText); $textLinks = explode(PHP_EOL, $textLinks); $textLinks = array_map(function ($textLink) { $textLink = str_replace('\\', '\\\\', $textLink); $textLink = str_replace('\\\\\\', '\\\\', $textLink); return json_decode($textLink, true); }, $textLinks); array_filter($textLinks); $links = []; foreach ($textLinks as $textLink) { $links[$textLink['title']] = $textLink['url']; } return $links; } protected function between(string $start, string $end, string $text): string { $startPosition = strpos($text, $start); if ($startPosition === false) { return ""; } $startPosition += strlen($start); $endPosition = strpos($text, $end, $startPosition); if ($endPosition === false) { return ""; } return trim(substr($text, $startPosition, $endPosition - $startPosition)); } } OpenAi/OpenAiSolution.php 0000644 00000006345 15110366412 0011347 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\OpenAi; use OpenAI; use Psr\SimpleCache\CacheInterface; use Spatie\Backtrace\Backtrace; use Spatie\Backtrace\Frame; use Spatie\Ignition\Contracts\Solution; use Spatie\Ignition\ErrorPage\Renderer; use Spatie\Ignition\Ignition; use Throwable; class OpenAiSolution implements Solution { public bool $aiGenerated = true; protected string $prompt; protected OpenAiSolutionResponse $openAiSolutionResponse; public function __construct( protected Throwable $throwable, protected string $openAiKey, protected CacheInterface|null $cache = null, protected int|null $cacheTtlInSeconds = 60, protected string|null $applicationType = null, protected string|null $applicationPath = null, ) { $this->prompt = $this->generatePrompt(); $this->openAiSolutionResponse = $this->getAiSolution(); } public function getSolutionTitle(): string { return 'AI Generated Solution'; } public function getSolutionDescription(): string { return $this->openAiSolutionResponse->description(); } public function getDocumentationLinks(): array { return $this->openAiSolutionResponse->links(); } public function getAiSolution(): ?OpenAiSolutionResponse { $solution = $this->cache->get($this->getCacheKey()); if ($solution) { return new OpenAiSolutionResponse($solution); } $solutionText = OpenAI::client($this->openAiKey) ->chat() ->create([ 'model' => $this->getModel(), 'messages' => [['role' => 'user', 'content' => $this->prompt]], 'max_tokens' => 1000, 'temperature' => 0, ])->choices[0]->message->content; $this->cache->set($this->getCacheKey(), $solutionText, $this->cacheTtlInSeconds); return new OpenAiSolutionResponse($solutionText); } protected function getCacheKey(): string { $hash = sha1($this->prompt); return "ignition-solution-{$hash}"; } protected function generatePrompt(): string { $viewPath = Ignition::viewPath('aiPrompt'); $viewModel = new OpenAiPromptViewModel( file: $this->throwable->getFile(), exceptionMessage: $this->throwable->getMessage(), exceptionClass: get_class($this->throwable), snippet: $this->getApplicationFrame($this->throwable)->getSnippetAsString(15), line: $this->throwable->getLine(), applicationType: $this->applicationType, ); return (new Renderer())->renderAsString( ['viewModel' => $viewModel], $viewPath, ); } protected function getModel(): string { return 'gpt-3.5-turbo'; } protected function getApplicationFrame(Throwable $throwable): ?Frame { $backtrace = Backtrace::createForThrowable($throwable); if ($this->applicationPath) { $backtrace->applicationPath($this->applicationPath); } $frames = $backtrace->frames(); return $frames[$backtrace->firstApplicationFrameIndex()] ?? null; } } OpenAi/OpenAiPromptViewModel.php 0000644 00000001610 15110366412 0012616 0 ustar 00 <?php namespace Spatie\Ignition\Solutions\OpenAi; class OpenAiPromptViewModel { public function __construct( protected string $file, protected string $exceptionMessage, protected string $exceptionClass, protected string $snippet, protected string $line, protected string|null $applicationType = null, ) { } public function file(): string { return $this->file; } public function line(): string { return $this->line; } public function snippet(): string { return $this->snippet; } public function exceptionMessage(): string { return $this->exceptionMessage; } public function exceptionClass(): string { return $this->exceptionClass; } public function applicationType(): string|null { return $this->applicationType; } } SuggestCorrectVariableNameSolution.php 0000644 00000001576 15110366412 0014234 0 ustar 00 <?php namespace Spatie\Ignition\Solutions; use Spatie\Ignition\Contracts\Solution; class SuggestCorrectVariableNameSolution implements Solution { protected ?string $variableName; protected ?string $viewFile; protected ?string $suggested; public function __construct(string $variableName = null, string $viewFile = null, string $suggested = null) { $this->variableName = $variableName; $this->viewFile = $viewFile; $this->suggested = $suggested; } public function getSolutionTitle(): string { return 'Possible typo $'.$this->variableName; } public function getDocumentationLinks(): array { return []; } public function getSolutionDescription(): string { return "Did you mean `$$this->suggested`?"; } public function isRunnable(): bool { return false; } }