-
Notifications
You must be signed in to change notification settings - Fork 26
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 #402 from bearsunday/compile_injector
Compile Injector
- Loading branch information
Showing
7 changed files
with
84 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\Package; | ||
|
||
use BEAR\AppMeta\AbstractAppMeta; | ||
use BEAR\Package\Module\ResourceObjectModule; | ||
use BEAR\Package\Module\ScriptinjectorModule; | ||
use Ray\Compiler\LazyModuleInterface; | ||
use Ray\Di\AbstractModule; | ||
|
||
class LazyModule implements LazyModuleInterface | ||
{ | ||
/** @var AbstractAppMeta */ | ||
private $appMeta; | ||
|
||
/** @var string */ | ||
private $context; | ||
|
||
/** @var string */ | ||
private $scriptDir; | ||
|
||
public function __construct(AbstractAppMeta $appMeta, string $context, string $scriptDir) | ||
{ | ||
$this->appMeta = $appMeta; | ||
$this->context = $context; | ||
$this->scriptDir = $scriptDir; | ||
} | ||
|
||
public function __invoke(): AbstractModule | ||
{ | ||
$module = new ScriptinjectorModule($this->scriptDir, (new Module())($this->appMeta, $this->context)); | ||
$module->install(new ResourceObjectModule($this->appMeta->getResourceListGenerator())); | ||
|
||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\Package\Module; | ||
|
||
use BEAR\Package\Provide\Error\NullPage; | ||
use Generator; | ||
use Ray\Di\AbstractModule; | ||
|
||
/** | ||
* Bind all resource object | ||
*/ | ||
class ResourceObjectModule extends AbstractModule | ||
{ | ||
/** @var Generator<array{0: class-string, 1: string}> */ | ||
private $resourceObjects; | ||
|
||
/** | ||
* @param Generator<array{0: class-string, 1: string}> $resourceObjects | ||
*/ | ||
public function __construct(Generator $resourceObjects) | ||
{ | ||
$this->resourceObjects = $resourceObjects; | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
foreach ($this->resourceObjects as [$class]) { | ||
$this->bind($class); | ||
} | ||
|
||
$this->bind(NullPage::class); | ||
} | ||
} |
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