Skip to content

Commit

Permalink
Optimize and harden EncoreHelper a bit (pimcore#15239)
Browse files Browse the repository at this point in the history
* Optimize and harden EncoreHelper a bit

* Fix typo

Co-authored-by: Matthias Schuhmayer <[email protected]>

---------

Co-authored-by: Matthias Schuhmayer <[email protected]>
  • Loading branch information
jdreesen and mattamon authored Jul 19, 2023
1 parent c21bbf4 commit 988f120
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/Helper/EncoreHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ final class EncoreHelper
{
public static function getBuildPathsFromEntrypoints(string $entrypointsFile, string $type = 'js'): array
{
if (!file_exists($entrypointsFile)) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $entrypointsFile));
}

$entrypointsContent = file_get_contents($entrypointsFile);
$entrypointsJson = json_decode($entrypointsContent, true)['entrypoints'];
$entrypoints = array_keys($entrypointsJson);
$entrypoints = json_decode($entrypointsContent, true, flags: JSON_THROW_ON_ERROR)['entrypoints'];

$paths = [];
foreach ($entrypoints as $entrypoint) {
$paths = array_merge($paths, $entrypointsJson[$entrypoint][$type] ?? []);
$paths[] = $entrypoint[$type] ?? [];
}

return $paths;
return array_merge(...$paths);
}
}

0 comments on commit 988f120

Please sign in to comment.