-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
CollectionNotFoundException.php
44 lines (36 loc) · 1.25 KB
/
CollectionNotFoundException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Statamic\Exceptions;
use Exception;
use Facade\Ignition\Support\StringComparator;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Statamic\Facades\Collection;
use Statamic\Statamic;
class CollectionNotFoundException extends Exception implements ProvidesSolution
{
protected $collection;
public function __construct($collection)
{
parent::__construct("Collection [{$collection}] not found");
$this->collection = $collection;
}
public function getSolution(): Solution
{
$description = ($suggestedCollection = $this->getSuggestedCollection())
? "Did you mean `$suggestedCollection`?"
: 'Are you sure the collection exists?';
return BaseSolution::create("The {$this->collection} collection was not found.")
->setSolutionDescription($description)
->setDocumentationLinks([
'Read the collections guide' => Statamic::docsUrl('/collections'),
]);
}
protected function getSuggestedCollection()
{
return StringComparator::findClosestMatch(
Collection::handles()->all(),
$this->collection
);
}
}