Skip to content

Commit

Permalink
Merge pull request #104 from ray-di/log-bindings
Browse files Browse the repository at this point in the history
Log bindings in script directory
  • Loading branch information
koriym authored Aug 22, 2023
2 parents e0406e2 + 516458d commit 122ffc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CompileInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ static function (string $class): void {
public function compile(): void
{
$module = (new InstallBuiltinModule())(($this->lazyModule)());
(new FilePutContents())(sprintf('%s/_bindings.log', $this->scriptDir), (string) $module);
(new Bind($module->getContainer(), ''))->annotatedWith(ScriptDir::class)->toInstance($this->scriptDir);
(new DiCompiler($module, $this->scriptDir))->compileContainer();
}
Expand Down
14 changes: 14 additions & 0 deletions src/DiCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
use ReflectionProperty;

use function assert;
use function fclose;
use function fopen;
use function fwrite;
use function is_resource;
use function is_string;
use function ksort;
use function serialize;
use function sprintf;
use function sys_get_temp_dir;

use const PHP_EOL;

final class DiCompiler implements InjectorInterface
{
/** @var string */
Expand Down Expand Up @@ -82,10 +90,16 @@ public function compileContainer(): void
$scriptDir = $this->container->getInstance('', ScriptDir::class);
$container = $this->container->getContainer();
assert(is_string($scriptDir));
$fp = fopen(sprintf('%s/_compile.log', $this->scriptDir), 'a');
assert(is_resource($fp));
ksort($container);
foreach ($container as $dependencyIndex => $dependency) {
fwrite($fp, $dependencyIndex . PHP_EOL);
$code = $this->dependencyCompiler->getCode($dependency);
($this->dependencySaver)($dependencyIndex, $code);
}

fclose($fp);
}

public function dumpGraph(): void
Expand Down

0 comments on commit 122ffc3

Please sign in to comment.