Skip to content

Commit

Permalink
Merge pull request #50 from koriym/save-once
Browse files Browse the repository at this point in the history
Do not save module.txt when unserialized
  • Loading branch information
koriym authored May 15, 2018
2 parents 0edc783 + a0fae23 commit d8268a8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ScriptInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ final class ScriptInjector implements InjectorInterface
*/
private static $saved = [];

/**
* @var bool
*/
private $wakeup = false;

/**
* @param string $scriptDir generated instance script folder path
* @param callable $lazyModule callable variable which return AbstractModule instance
Expand Down Expand Up @@ -221,7 +226,8 @@ private function getInstanceFile(string $dependencyIndex) : string

private function saveModule()
{
if (! \in_array($this->scriptDir, self::$saved, true)) {
$isNotUnserializedAndWriteOnce = ! \in_array($this->scriptDir, self::$saved, true) && ! $this->wakeup;
if ($isNotUnserializedAndWriteOnce) {
self::$saved[] = $this->scriptDir;
$module = $this->module instanceof AbstractModule ? $this->module : ($this->lazyModule)();
\file_put_contents($this->scriptDir . self::MODULE, \serialize($module));
Expand Down

0 comments on commit d8268a8

Please sign in to comment.