-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make anonymous providers serialisable
Replaced anonymous class with ProviderProvider in ProviderSetProvider. This makes it serialisable.This improves code reuse and readability by consolidating instance retrieval logic into a dedicated class.
- Loading branch information
Showing
2 changed files
with
31 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\Di; | ||
|
||
use Ray\Di\Di\Set; | ||
|
||
final class ProviderProvider implements ProviderInterface | ||
{ | ||
/** @var InjectorInterface */ | ||
private $injector; | ||
|
||
/** @var InjectorInterface */ | ||
private $interface; | ||
Check failure on line 15 in src/di/ProviderProvider.php GitHub Actions / sa / PHPStan
Check failure on line 15 in src/di/ProviderProvider.php GitHub Actions / sa / Psalm
|
||
|
||
/** @var Set */ | ||
private $set; | ||
|
||
public function __construct(InjectorInterface $injector, Set $set) | ||
{ | ||
$this->injector = $injector; | ||
$this->set = $set; | ||
} | ||
|
||
public function get() | ||
Check failure on line 26 in src/di/ProviderProvider.php GitHub Actions / cs / Coding Standards
|
||
{ | ||
return $this->injector->getInstance($this->set->interface, $this->set->name); | ||
} | ||
} |
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