Skip to content

Commit

Permalink
feat: More robust loading against various invalid resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Jan 23, 2024
1 parent 7a6a391 commit 4cbef47
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Loader/SiteKitLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ private function loadRaw(string $location): array

try {
error_reporting(E_ERROR | E_PARSE);
return require $file;
ob_start();
$data = require $file;
if (!is_array($data)) {
throw new InvalidResourceException(
$location,
'The resource should return an array'
);

Check warning on line 84 in src/Loader/SiteKitLoader.php

View check run for this annotation

Codecov / codecov/patch

src/Loader/SiteKitLoader.php#L81-L84

Added lines #L81 - L84 were not covered by tests
}
return $data;
} catch (\ParseError $e) {
throw new InvalidResourceException(
$location,
Expand All @@ -99,6 +107,7 @@ private function loadRaw(string $location): array
$e
);
} finally {
ob_end_clean();
error_reporting($saveErrorReporting);
}
}
Expand Down

0 comments on commit 4cbef47

Please sign in to comment.