-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implementation of the 'singleton' functionality for storing cla…
…sses and prefixes.
- Loading branch information
Showing
6 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Joserick\LaravelLivewireDiscover\Exceptions; | ||
|
||
use Livewire\Exceptions\ComponentNotFoundException as LivewireComponentNotFoundException; | ||
|
||
class ComponentNotFoundException extends LivewireComponentNotFoundException | ||
{ | ||
public function __construct(array $prefixes, LivewireComponentNotFoundException $previous = null) { | ||
parent::__construct('(Also in the prefixes paths: '.implode(', ', array_keys($prefixes)).') ' | ||
. $previous->getMessage(), 0, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Joserick\LaravelLivewireDiscover; | ||
|
||
use Illuminate\Support\Collection; | ||
use Livewire\Mechanisms\ComponentRegistry; | ||
|
||
class LaravelLivewireDiscover extends ComponentRegistry | ||
{ | ||
private string $class_namespace; | ||
private Collection $class_namespaces; | ||
|
||
/** | ||
* Create a new component resolver instance. | ||
*/ | ||
public function __construct() { | ||
$this->class_namespace = config('livewire.class_namespace'); | ||
$this->class_namespaces = collect(config('laravel-livewire-discover.class_namespaces')); | ||
} | ||
|
||
/** | ||
* Add a class / namespace prefix to the resolver. | ||
* | ||
* @param string $prefix | ||
* @param string $namespace | ||
* @return void | ||
*/ | ||
public function add(string $prefix, string $namespace) : void | ||
{ | ||
$this->class_namespaces->put($prefix, $namespace); | ||
} | ||
|
||
/** | ||
* Get the livewire class namespace. | ||
* | ||
* @return string | ||
*/ | ||
public function getClassNamespace() : string | ||
{ | ||
return $this->class_namespace; | ||
} | ||
|
||
/** | ||
* Get the collection of class namespaces to discover. | ||
* | ||
* @return string | ||
*/ | ||
public function getClassNamespaces() : Collection | ||
{ | ||
return $this->class_namespaces; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters