Primo Committ
This commit is contained in:
46
vendor/facade/ignition/src/Solutions/GenerateAppKeySolution.php
vendored
Normal file
46
vendor/facade/ignition/src/Solutions/GenerateAppKeySolution.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class GenerateAppKeySolution implements RunnableSolution
|
||||
{
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return 'Your app key is missing';
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [
|
||||
'Laravel installation' => 'https://laravel.com/docs/master/installation#configuration',
|
||||
];
|
||||
}
|
||||
|
||||
public function getSolutionActionDescription(): string
|
||||
{
|
||||
return 'Generate your application encryption key using `php artisan key:generate`.';
|
||||
}
|
||||
|
||||
public function getRunButtonText(): string
|
||||
{
|
||||
return 'Generate app key';
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getRunParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function run(array $parameters = [])
|
||||
{
|
||||
Artisan::call('key:generate');
|
||||
}
|
||||
}
|
||||
53
vendor/facade/ignition/src/Solutions/LivewireDiscoverSolution.php
vendored
Normal file
53
vendor/facade/ignition/src/Solutions/LivewireDiscoverSolution.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Livewire\LivewireComponentsFinder;
|
||||
|
||||
class LivewireDiscoverSolution implements RunnableSolution
|
||||
{
|
||||
private $customTitle;
|
||||
|
||||
public function __construct($customTitle = '')
|
||||
{
|
||||
$this->customTitle = $customTitle;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return $this->customTitle;
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return 'You might have forgotten to discover your Livewire components. You can discover your Livewire components using `php artisan livewire:discover`.';
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [
|
||||
'Livewire: Artisan Commands' => 'https://laravel-livewire.com/docs/2.x/artisan-commands',
|
||||
];
|
||||
}
|
||||
|
||||
public function getRunParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSolutionActionDescription(): string
|
||||
{
|
||||
return 'Pressing the button below will try to discover your Livewire components.';
|
||||
}
|
||||
|
||||
public function getRunButtonText(): string
|
||||
{
|
||||
return 'Run livewire:discover';
|
||||
}
|
||||
|
||||
public function run(array $parameters = [])
|
||||
{
|
||||
app(LivewireComponentsFinder::class)->build();
|
||||
}
|
||||
}
|
||||
122
vendor/facade/ignition/src/Solutions/MakeViewVariableOptionalSolution.php
vendored
Normal file
122
vendor/facade/ignition/src/Solutions/MakeViewVariableOptionalSolution.php
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MakeViewVariableOptionalSolution implements RunnableSolution
|
||||
{
|
||||
/** @var string */
|
||||
private $variableName;
|
||||
|
||||
/** @var string */
|
||||
private $viewFile;
|
||||
|
||||
public function __construct($variableName = null, $viewFile = null)
|
||||
{
|
||||
$this->variableName = $variableName;
|
||||
$this->viewFile = $viewFile;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return "$$this->variableName is undefined";
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSolutionActionDescription(): string
|
||||
{
|
||||
$output = [
|
||||
'Make the variable optional in the blade template.',
|
||||
"Replace `{{ $$this->variableName }}` with `{{ $$this->variableName ?? '' }}`",
|
||||
];
|
||||
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function getRunButtonText(): string
|
||||
{
|
||||
return 'Make variable optional';
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getRunParameters(): array
|
||||
{
|
||||
return [
|
||||
'variableName' => $this->variableName,
|
||||
'viewFile' => $this->viewFile,
|
||||
];
|
||||
}
|
||||
|
||||
public function isRunnable(array $parameters = [])
|
||||
{
|
||||
return $this->makeOptional($this->getRunParameters()) !== false;
|
||||
}
|
||||
|
||||
public function run(array $parameters = [])
|
||||
{
|
||||
$output = $this->makeOptional($parameters);
|
||||
if ($output !== false) {
|
||||
file_put_contents($parameters['viewFile'], $output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function isSafePath(string $path): bool
|
||||
{
|
||||
if (! Str::startsWith($path, ['/', './'])) {
|
||||
return false;
|
||||
}
|
||||
if (! Str::endsWith($path, '.blade.php')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function makeOptional(array $parameters = [])
|
||||
{
|
||||
if (! $this->isSafePath($parameters['viewFile'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$originalContents = file_get_contents($parameters['viewFile']);
|
||||
$newContents = str_replace('$'.$parameters['variableName'], '$'.$parameters['variableName']." ?? ''", $originalContents);
|
||||
|
||||
$originalTokens = token_get_all(Blade::compileString($originalContents));
|
||||
$newTokens = token_get_all(Blade::compileString($newContents));
|
||||
|
||||
$expectedTokens = $this->generateExpectedTokens($originalTokens, $parameters['variableName']);
|
||||
|
||||
if ($expectedTokens !== $newTokens) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $newContents;
|
||||
}
|
||||
|
||||
protected function generateExpectedTokens(array $originalTokens, string $variableName): array
|
||||
{
|
||||
$expectedTokens = [];
|
||||
foreach ($originalTokens as $token) {
|
||||
$expectedTokens[] = $token;
|
||||
if ($token[0] === T_VARIABLE && $token[1] === '$'.$variableName) {
|
||||
$expectedTokens[] = [T_WHITESPACE, ' ', $token[2]];
|
||||
$expectedTokens[] = [T_COALESCE, '??', $token[2]];
|
||||
$expectedTokens[] = [T_WHITESPACE, ' ', $token[2]];
|
||||
$expectedTokens[] = [T_CONSTANT_ENCAPSED_STRING, "''", $token[2]];
|
||||
}
|
||||
}
|
||||
|
||||
return $expectedTokens;
|
||||
}
|
||||
}
|
||||
42
vendor/facade/ignition/src/Solutions/MissingPackageSolution.php
vendored
Normal file
42
vendor/facade/ignition/src/Solutions/MissingPackageSolution.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\Ignition\Support\Packagist\Package;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class MissingPackageSolution implements Solution
|
||||
{
|
||||
/** @var Package */
|
||||
protected $possiblePackage;
|
||||
|
||||
public function __construct(Package $possiblePackage)
|
||||
{
|
||||
$this->possiblePackage = $possiblePackage;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return 'A composer dependency is missing';
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
$output = [
|
||||
'You might be missing a composer dependency.',
|
||||
'A possible package that was found is `'.$this->possiblePackage->name.'`.',
|
||||
'',
|
||||
'See if this is the package that you need and install it via `composer require '.$this->possiblePackage->name.'`.',
|
||||
];
|
||||
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [
|
||||
'Git repository' => $this->possiblePackage->repository,
|
||||
'Package on Packagist' => $this->possiblePackage->url,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
vendor/facade/ignition/src/Solutions/RunMigrationsSolution.php
vendored
Normal file
53
vendor/facade/ignition/src/Solutions/RunMigrationsSolution.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class RunMigrationsSolution implements RunnableSolution
|
||||
{
|
||||
private $customTitle;
|
||||
|
||||
public function __construct($customTitle = '')
|
||||
{
|
||||
$this->customTitle = $customTitle;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return $this->customTitle;
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return 'You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.';
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [
|
||||
'Database: Running Migrations docs' => 'https://laravel.com/docs/master/migrations#running-migrations',
|
||||
];
|
||||
}
|
||||
|
||||
public function getRunParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSolutionActionDescription(): string
|
||||
{
|
||||
return 'Pressing the button below will try to run your migrations.';
|
||||
}
|
||||
|
||||
public function getRunButtonText(): string
|
||||
{
|
||||
return 'Run migrations';
|
||||
}
|
||||
|
||||
public function run(array $parameters = [])
|
||||
{
|
||||
Artisan::call('migrate');
|
||||
}
|
||||
}
|
||||
45
vendor/facade/ignition/src/Solutions/SolutionTransformer.php
vendored
Normal file
45
vendor/facade/ignition/src/Solutions/SolutionTransformer.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Throwable;
|
||||
|
||||
class SolutionTransformer implements Arrayable
|
||||
{
|
||||
/** @var \Facade\IgnitionContracts\Solution */
|
||||
protected $solution;
|
||||
|
||||
public function __construct(Solution $solution)
|
||||
{
|
||||
$this->solution = $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(),
|
||||
'is_runnable' => $isRunnable,
|
||||
'run_button_text' => $isRunnable ? $this->solution->getRunButtonText() : '',
|
||||
'run_parameters' => $isRunnable ? $this->solution->getRunParameters() : [],
|
||||
'action_description' => $isRunnable ? $this->solution->getSolutionActionDescription() : '',
|
||||
'execute_endpoint' => $this->executeEndpoint(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function executeEndpoint(): string
|
||||
{
|
||||
try {
|
||||
return action('\Facade\Ignition\Http\Controllers\ExecuteSolutionController');
|
||||
} catch (Throwable $exception) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/facade/ignition/src/Solutions/SuggestCorrectVariableNameSolution.php
vendored
Normal file
44
vendor/facade/ignition/src/Solutions/SuggestCorrectVariableNameSolution.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class SuggestCorrectVariableNameSolution implements Solution
|
||||
{
|
||||
/** @var string */
|
||||
private $variableName;
|
||||
|
||||
/** @var string */
|
||||
private $viewFile;
|
||||
|
||||
/** @var string|null */
|
||||
private $suggested;
|
||||
|
||||
public function __construct($variableName = null, $viewFile = null, $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;
|
||||
}
|
||||
}
|
||||
31
vendor/facade/ignition/src/Solutions/SuggestImportSolution.php
vendored
Normal file
31
vendor/facade/ignition/src/Solutions/SuggestImportSolution.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class SuggestImportSolution implements Solution
|
||||
{
|
||||
/** @var string */
|
||||
protected $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 [];
|
||||
}
|
||||
}
|
||||
44
vendor/facade/ignition/src/Solutions/SuggestLivewireMethodNameSolution.php
vendored
Normal file
44
vendor/facade/ignition/src/Solutions/SuggestLivewireMethodNameSolution.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class SuggestLivewireMethodNameSolution implements Solution
|
||||
{
|
||||
/** @var string */
|
||||
private $methodName;
|
||||
|
||||
/** @var string */
|
||||
private $componentClass;
|
||||
|
||||
/** @var string|null */
|
||||
private $suggested;
|
||||
|
||||
public function __construct($methodName = null, $componentClass = null, $suggested = null)
|
||||
{
|
||||
$this->methodName = $methodName;
|
||||
$this->componentClass = $componentClass;
|
||||
$this->suggested = $suggested;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return "Possible typo `{$this->componentClass}::{$this->methodName}()`";
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return "Did you mean `{$this->suggested}()`?";
|
||||
}
|
||||
|
||||
public function isRunnable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
44
vendor/facade/ignition/src/Solutions/SuggestLivewirePropertyNameSolution.php
vendored
Normal file
44
vendor/facade/ignition/src/Solutions/SuggestLivewirePropertyNameSolution.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class SuggestLivewirePropertyNameSolution implements Solution
|
||||
{
|
||||
/** @var string */
|
||||
private $variableName;
|
||||
|
||||
/** @var string */
|
||||
private $componentClass;
|
||||
|
||||
/** @var string|null */
|
||||
private $suggested;
|
||||
|
||||
public function __construct($variableName = null, $componentClass = null, $suggested = null)
|
||||
{
|
||||
$this->variableName = $variableName;
|
||||
$this->componentClass = $componentClass;
|
||||
$this->suggested = $suggested;
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return "Possible typo {$this->componentClass}::{$this->variableName}";
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return "Did you mean `$this->suggested`?";
|
||||
}
|
||||
|
||||
public function isRunnable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
27
vendor/facade/ignition/src/Solutions/SuggestUsingCorrectDbNameSolution.php
vendored
Normal file
27
vendor/facade/ignition/src/Solutions/SuggestUsingCorrectDbNameSolution.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
|
||||
class SuggestUsingCorrectDbNameSolution implements Solution
|
||||
{
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return 'Database name seems incorrect';
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
$defaultDatabaseName = env('DB_DATABASE');
|
||||
|
||||
return "You're using the default database name `$defaultDatabaseName`. This database does not exist.\n\nEdit the `.env` file and use the correct database name in the `DB_DATABASE` key.";
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [
|
||||
'Database: Getting Started docs' => 'https://laravel.com/docs/master/database#configuration',
|
||||
];
|
||||
}
|
||||
}
|
||||
64
vendor/facade/ignition/src/Solutions/UseDefaultValetDbCredentialsSolution.php
vendored
Normal file
64
vendor/facade/ignition/src/Solutions/UseDefaultValetDbCredentialsSolution.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Facade\Ignition\Solutions;
|
||||
|
||||
use Facade\IgnitionContracts\RunnableSolution;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UseDefaultValetDbCredentialsSolution implements RunnableSolution
|
||||
{
|
||||
public function getSolutionActionDescription(): string
|
||||
{
|
||||
return 'Pressing the button below will change `DB_USER` and `DB_PASSWORD` in your `.env` file.';
|
||||
}
|
||||
|
||||
public function getRunButtonText(): string
|
||||
{
|
||||
return 'Use default Valet credentials';
|
||||
}
|
||||
|
||||
public function getSolutionTitle(): string
|
||||
{
|
||||
return 'Could not connect to database';
|
||||
}
|
||||
|
||||
public function run(array $parameters = [])
|
||||
{
|
||||
if (! file_exists(base_path('.env'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ensureLineExists('DB_USERNAME', 'root');
|
||||
$this->ensureLineExists('DB_PASSWORD', '');
|
||||
}
|
||||
|
||||
protected function ensureLineExists(string $key, string $value)
|
||||
{
|
||||
$envPath = base_path('.env');
|
||||
|
||||
$envLines = array_map(function (string $envLine) use ($value, $key) {
|
||||
return Str::startsWith($envLine, $key)
|
||||
? "{$key}={$value}".PHP_EOL
|
||||
: $envLine;
|
||||
}, file($envPath));
|
||||
|
||||
file_put_contents($envPath, implode('', $envLines));
|
||||
}
|
||||
|
||||
public function getDocumentationLinks(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getRunParameters(): array
|
||||
{
|
||||
return [
|
||||
'Valet documentation' => 'https://laravel.com/docs/master/valet',
|
||||
];
|
||||
}
|
||||
|
||||
public function getSolutionDescription(): string
|
||||
{
|
||||
return 'You seem to be using Valet, but the .env file does not contain the right default database credentials.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user