Skip to content

Commit

Permalink
Merge events only in the file adater for cacheDirectory (#26)
Browse files Browse the repository at this point in the history
* Merge events only in the file adater for cacheDirectory
* Shorten code
  • Loading branch information
kylekatarnls committed Jul 5, 2018
1 parent 54a0238 commit e8fbc18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
12 changes: 5 additions & 7 deletions src/Phug/Renderer/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,23 @@ public function cacheDirectory($directory)
$errorDetails = [];

$renderer = $this->getRenderer();
$events = $renderer->getCompiler()->getEventListeners();

foreach ($renderer->scanDirectory($directory) as $inputFile) {
$renderer->initCompiler();
$compiler = $renderer->getCompiler();
$compiler->mergeEventListeners($events);
$path = $inputFile;
$this->isCacheUpToDate($path);
$sandBox = $this->getRenderer()->getNewSandBox(function () use (&$success, $compiler, $path, $inputFile) {
$this->cacheFileContents($path, $compiler->compileFile($inputFile), $compiler->getCurrentImportPaths());
$success++;
});
$error = $sandBox->getThrowable();

if ($sandBox->getThrowable()) {
if ($error) {
$errors++;
$errorDetails[] = [
'directory' => $directory,
'inputFile' => $inputFile,
'path' => $path,
'error' => $sandBox->getThrowable(),
];
$errorDetails[] = compact(['directory', 'inputFile', 'path', 'error']);
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/Phug/Renderer/Partial/RendererOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ public function initCompiler()
);
}

if (isset($this->compiler)) {
$events = $this->compiler->getEventListeners();
}

$this->compiler = new $compilerClassName($this->getOptions());

if (isset($events)) {
$this->compiler->mergeEventListeners($events);
}
}
}

0 comments on commit e8fbc18

Please sign in to comment.