-
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.
Merge pull request #5 from kawanamiyuu/injector-factory
Injector factory
- Loading branch information
Showing
6 changed files
with
76 additions
and
12 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build/ | ||
/vendor/ | ||
/composer.lock | ||
/.phpunit.result.cache |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K9u\Framework; | ||
|
||
use Ray\Compiler\ScriptInjector; | ||
use Ray\Di\AbstractModule; | ||
use Ray\Di\Bind; | ||
use Ray\Di\InjectorInterface; | ||
|
||
class CachedInjectorFactory implements InjectorFactoryInterface | ||
{ | ||
private string $cacheDir; | ||
|
||
public function __construct(string $cacheDir) | ||
{ | ||
$this->cacheDir = $cacheDir; | ||
} | ||
|
||
public function __invoke(AbstractModule $module): InjectorInterface | ||
{ | ||
$injector = new ScriptInjector($this->cacheDir, function () use (&$injector, $module) { | ||
(new Bind($module->getContainer(), InjectorInterface::class))->toInstance($injector); | ||
return $module; | ||
}); | ||
|
||
return $injector; | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K9u\Framework; | ||
|
||
use Ray\Di\AbstractModule; | ||
use Ray\Di\InjectorInterface; | ||
|
||
interface InjectorFactoryInterface | ||
{ | ||
public function __invoke(AbstractModule $module): InjectorInterface; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K9u\Framework; | ||
|
||
use Ray\Di\AbstractModule; | ||
use Ray\Di\Injector; | ||
use Ray\Di\InjectorInterface; | ||
|
||
class OnDemandInjectorFactory implements InjectorFactoryInterface | ||
{ | ||
public function __invoke(AbstractModule $module): InjectorInterface | ||
{ | ||
return new Injector($module); | ||
} | ||
} |
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