Skip to content

Commit 5185204

Browse files
[7.x] Fix Ignition Runnable Solutions (#529)
* Fix Runnable Ignition Solutions * Fix styling * Rename solution provider class --------- Co-authored-by: duncanmcclean <duncanmcclean@users.noreply.github.com>
1 parent 0b1803c commit 5185204

File tree

7 files changed

+41
-20
lines changed

7 files changed

+41
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"laravel/framework": "^10.25.0 || ^11.0",
4444
"laravel/prompts": "^0.1.17",
4545
"pixelfear/composer-dist-plugin": "^0.1.5",
46-
"spatie/ignition": "^1.14",
46+
"spatie/ignition": "^1.15",
4747
"statamic/cms": "^5.7.0"
4848
},
4949
"require-dev": {

src/Exceptions/TraitMissingException.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
22

33
namespace StatamicRadPack\Runway\Exceptions;
44

5-
use Spatie\Ignition\Contracts\ProvidesSolution;
6-
use Spatie\Ignition\Contracts\Solution;
7-
use StatamicRadPack\Runway\Ignition\Solutions\AddTraitToModel;
8-
9-
class TraitMissingException extends \Exception implements ProvidesSolution
5+
class TraitMissingException extends \Exception
106
{
11-
public function __construct(protected string $model)
7+
public function __construct(public string $model)
128
{
139
parent::__construct("The HasRunwayResource trait is missing from the [{$model}] model");
1410
}
15-
16-
public function getSolution(): Solution
17-
{
18-
return new AddTraitToModel($this->model);
19-
}
2011
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace StatamicRadPack\Runway\Ignition\SolutionProviders;
4+
5+
use Spatie\Ignition\Contracts\HasSolutionsForThrowable;
6+
use StatamicRadPack\Runway\Ignition\Solutions\AddTraitToModel;
7+
use Throwable;
8+
9+
class TraitMissing implements HasSolutionsForThrowable
10+
{
11+
public function canSolve(Throwable $throwable): bool
12+
{
13+
return $throwable instanceof \StatamicRadPack\Runway\Exceptions\TraitMissingException;
14+
}
15+
16+
public function getSolutions(Throwable $throwable): array
17+
{
18+
return [new AddTraitToModel($throwable->model)];
19+
}
20+
}

src/Ignition/Solutions/AddTraitToModel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
class AddTraitToModel implements RunnableSolution
1111
{
12-
public function __construct(protected $model = null)
13-
{
14-
}
12+
public function __construct(protected $model = null) {}
1513

1614
public function getSolutionTitle(): string
1715
{

src/Resource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function __construct(
2020
protected Model $model,
2121
protected string $name,
2222
protected Collection $config
23-
) {
24-
}
23+
) {}
2524

2625
public function handle(): string
2726
{

src/Routing/ResourceResponse.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class ResourceResponse implements Responsable
1414

1515
protected $with = [];
1616

17-
public function __construct(protected $data)
18-
{
19-
}
17+
public function __construct(protected $data) {}
2018

2119
public function toResponse($request)
2220
{

src/ServiceProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace StatamicRadPack\Runway;
44

5+
use Illuminate\Contracts\Container\BindingResolutionException;
56
use Illuminate\Database\QueryException;
67
use Illuminate\Support\Facades\Event;
78
use Illuminate\Support\Facades\Gate;
89
use Illuminate\Support\Facades\Log;
910
use Illuminate\Support\Facades\Route;
1011
use Illuminate\Support\Str;
1112
use Illuminate\Support\Traits\Conditionable;
13+
use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository;
1214
use Statamic\API\Middleware\Cache;
1315
use Statamic\Facades\Blueprint;
1416
use Statamic\Facades\CP\Nav;
@@ -19,6 +21,7 @@
1921
use Statamic\Providers\AddonServiceProvider;
2022
use Statamic\Statamic;
2123
use StatamicRadPack\Runway\Http\Controllers\ApiController;
24+
use StatamicRadPack\Runway\Ignition\SolutionProviders\TraitMissing;
2225
use StatamicRadPack\Runway\Policies\ResourcePolicy;
2326
use StatamicRadPack\Runway\Search\Provider as SearchProvider;
2427
use StatamicRadPack\Runway\Search\Searchable;
@@ -88,6 +91,8 @@ public function boot()
8891
__DIR__.'/../config/runway.php' => config_path('runway.php'),
8992
], 'runway-config');
9093

94+
$this->registerIgnitionSolutionProviders();
95+
9196
Statamic::booted(function () {
9297
if ($this->shouldDiscoverResources()) {
9398
Runway::discoverResources();
@@ -107,6 +112,16 @@ public function boot()
107112
});
108113
}
109114

115+
protected function registerIgnitionSolutionProviders(): void
116+
{
117+
try {
118+
$this->app->make(SolutionProviderRepository::class)
119+
->registerSolutionProvider(TraitMissing::class);
120+
} catch (BindingResolutionException $e) {
121+
//
122+
}
123+
}
124+
110125
protected function registerRouteBindings(): self
111126
{
112127
Route::bind('resource', function ($value) {

0 commit comments

Comments
 (0)