Skip to content

Commit

Permalink
Add livewire component discovery solution. (#319)
Browse files Browse the repository at this point in the history
* Create LivewireDiscoverSolution.php

* Create MissingLivewireComponentSolutionProvider.php

* Update IgnitionServiceProvider.php

* Update MissingLivewireComponentSolutionProvider.php

* Update LivewireDiscoverSolution.php

* fixes
  • Loading branch information
ArnaudLier committed Oct 14, 2020
1 parent 97bfeb5 commit 614bc70
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/IgnitionServiceProvider.php
Expand Up @@ -39,6 +39,7 @@
use Facade\Ignition\SolutionProviders\MissingAppKeySolutionProvider;
use Facade\Ignition\SolutionProviders\MissingColumnSolutionProvider;
use Facade\Ignition\SolutionProviders\MissingImportSolutionProvider;
use Facade\Ignition\SolutionProviders\MissingLivewireComponentSolutionProvider;
use Facade\Ignition\SolutionProviders\MissingMixManifestSolutionProvider;
use Facade\Ignition\SolutionProviders\MissingPackageSolutionProvider;
use Facade\Ignition\SolutionProviders\RunningLaravelDuskInProductionProvider;
Expand Down Expand Up @@ -373,6 +374,7 @@ protected function getDefaultSolutions(): array
UnknownValidationSolutionProvider::class,
UndefinedPropertySolutionProvider::class,
MissingMixManifestSolutionProvider::class,
MissingLivewireComponentSolutionProvider::class,
];
}

Expand Down
33 changes: 33 additions & 0 deletions src/SolutionProviders/MissingLivewireComponentSolutionProvider.php
@@ -0,0 +1,33 @@
<?php

namespace Facade\Ignition\SolutionProviders;

use Facade\Ignition\Solutions\LivewireDiscoverSolution;
use Facade\IgnitionContracts\HasSolutionsForThrowable;
use Illuminate\Database\QueryException;
use Livewire\Exceptions\ComponentNotFoundException;
use Livewire\LivewireComponentsFinder;
use Throwable;

class MissingLivewireComponentSolutionProvider implements HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool
{
if (! class_exists(ComponentNotFoundException::class)) {
return false;
}
if (! class_exists(LivewireComponentsFinder::class)) {
return false;
}
if (! $throwable instanceof ComponentNotFoundException) {
return false;
}

return true;
}

public function getSolutions(Throwable $throwable): array
{
return [new LivewireDiscoverSolution('A livewire component was not found')];
}
}
53 changes: 53 additions & 0 deletions src/Solutions/LivewireDiscoverSolution.php
@@ -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 components.';
}

public function getRunButtonText(): string
{
return 'Run livewire components discover';
}

public function run(array $parameters = [])
{
app(LivewireComponentsFinder::class)->build();
}
}

0 comments on commit 614bc70

Please sign in to comment.