Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/StaticPHP/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function initialize(InputInterface $input, OutputInterface $output): void
}

set_error_handler(static function ($error_no, $error_msg, $error_file, $error_line) {
// Respect the @ suppression operator (error_reporting() returns 0 when @ is used)
if (error_reporting() === 0) {
return true;
}
$tips = [
E_WARNING => ['PHP Warning: ', 'warning'],
E_NOTICE => ['PHP Notice: ', 'notice'],
Expand Down
2 changes: 1 addition & 1 deletion src/StaticPHP/Config/ArtifactConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function loadFromDir(string $dir, string $registry_name): array
*/
public static function loadFromFile(string $file, string $registry_name): string
{
$content = file_get_contents($file);
$content = @file_get_contents($file);
if ($content === false) {
throw new WrongUsageException("Failed to read artifact config file: {$file}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/StaticPHP/Config/PackageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function loadFromDir(string $dir, string $registry_name): array
*/
public static function loadFromFile(string $file, string $registry_name): string
{
$content = file_get_contents($file);
$content = @file_get_contents($file);
if ($content === false) {
throw new WrongUsageException("Failed to read package config file: {$file}");
}
Expand Down
14 changes: 11 additions & 3 deletions src/StaticPHP/Registry/PackageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ public static function getBeforeStageCallbacks(string $package_name, string $sta
// match condition
$installer = ApplicationContext::get(PackageInstaller::class);
$stages = self::$before_stages[$package_name][$stage] ?? [];
foreach ($stages as [$callback, $only_when_package_resolved, $conditionals]) {
foreach ($stages as $entry) {
$callback = $entry[0];
$only_when_package_resolved = $entry[1] ?? null;
$conditionals = $entry[2] ?? [];
if ($only_when_package_resolved !== null && !$installer->isPackageResolved($only_when_package_resolved)) {
continue;
}
Expand All @@ -389,7 +392,10 @@ public static function getAfterStageCallbacks(string $package_name, string $stag
$installer = ApplicationContext::get(PackageInstaller::class);
$stages = self::$after_stages[$package_name][$stage] ?? [];
$result = [];
foreach ($stages as [$callback, $only_when_package_resolved, $conditionals]) {
foreach ($stages as $entry) {
$callback = $entry[0];
$only_when_package_resolved = $entry[1] ?? null;
$conditionals = $entry[2] ?? [];
if ($only_when_package_resolved !== null && !$installer->isPackageResolved($only_when_package_resolved)) {
continue;
}
Expand Down Expand Up @@ -433,7 +439,9 @@ public static function checkLoadedStageEvents(): void
}
$pkg = self::getPackage($package_name);
foreach ($stages as $stage_name => $before_events) {
foreach ($before_events as [$event_callable, $only_when_package_resolved, $conditionals]) {
foreach ($before_events as $entry) {
$event_callable = $entry[0];
$only_when_package_resolved = $entry[1] ?? null;
// check only_when_package_resolved package exists
if ($only_when_package_resolved !== null && !self::hasPackage($only_when_package_resolved)) {
throw new RegistryException("{$event_name} event in package [{$package_name}] for stage [{$stage_name}] has unknown only_when_package_resolved package [{$only_when_package_resolved}].");
Expand Down
2 changes: 2 additions & 0 deletions tests/GlobalsFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ protected function setUp(): void
protected function tearDown(): void
{
$GLOBALS['spc_log_filters'] = null;
// Restore logger level to avoid polluting other tests with DEBUG noise
logger()->setLevel(LogLevel::ERROR);
}

public function testAddLogFilterDeduplicates(): void
Expand Down
5 changes: 0 additions & 5 deletions tests/StaticPHP/Artifact/ArtifactDownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ protected function setUp(): void
// Reset ArtifactConfig and ArtifactLoader static state
$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

$loaderReflection = new \ReflectionClass(ArtifactLoader::class);
$loaderProperty = $loaderReflection->getProperty('artifacts');
$loaderProperty->setAccessible(true);
$loaderProperty->setValue(null, null);
}

Expand All @@ -38,12 +36,10 @@ protected function tearDown(): void

$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

$loaderReflection = new \ReflectionClass(ArtifactLoader::class);
$loaderProperty = $loaderReflection->getProperty('artifacts');
$loaderProperty->setAccessible(true);
$loaderProperty->setValue(null, null);
}

Expand Down Expand Up @@ -343,7 +339,6 @@ private function injectArtifactConfig(string $name, array $config): void
{
$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$configs = $property->getValue(null) ?? [];
$configs[$name] = $config;
$property->setValue(null, $configs);
Expand Down
7 changes: 0 additions & 7 deletions tests/StaticPHP/Artifact/ArtifactExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ protected function setUp(): void

$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

$loaderReflection = new \ReflectionClass(ArtifactLoader::class);
$loaderProperty = $loaderReflection->getProperty('artifacts');
$loaderProperty->setAccessible(true);
$loaderProperty->setValue(null, null);

ApplicationContext::reset();
Expand All @@ -51,12 +49,10 @@ protected function tearDown(): void

$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

$loaderReflection = new \ReflectionClass(ArtifactLoader::class);
$loaderProperty = $loaderReflection->getProperty('artifacts');
$loaderProperty->setAccessible(true);
$loaderProperty->setValue(null, null);

ApplicationContext::reset();
Expand Down Expand Up @@ -157,7 +153,6 @@ public function testExtractReturnsAlreadyExtractedForSecondCall(): void
// Pre-populate the extracted map for 'my-pkg' via reflection
$reflection = new \ReflectionClass(ArtifactExtractor::class);
$extractedProperty = $reflection->getProperty('extracted');
$extractedProperty->setAccessible(true);
$extractedProperty->setValue($extractor, ['my-pkg' => true]);

$result = $extractor->extract($artifact, false);
Expand All @@ -181,7 +176,6 @@ public function testExtractWithStringNameLooksUpFromArtifactLoader(): void
// Pre-populate the extracted map so we don't need actual downloads
$reflection = new \ReflectionClass(ArtifactExtractor::class);
$extractedProperty = $reflection->getProperty('extracted');
$extractedProperty->setAccessible(true);
$extractedProperty->setValue($extractor, ['my-pkg' => true]);

$result = $extractor->extract('my-pkg', false);
Expand All @@ -204,7 +198,6 @@ private function injectArtifactConfig(string $name, array $config): void
{
$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$configs = $property->getValue(null) ?? [];
$configs[$name] = $config;
$property->setValue(null, $configs);
Expand Down
3 changes: 0 additions & 3 deletions tests/StaticPHP/Artifact/ArtifactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ protected function setUp(): void
// Reset ArtifactConfig static state
$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

// Reset DI container
Expand All @@ -45,7 +44,6 @@ protected function tearDown(): void

$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$property->setValue(null, []);

ApplicationContext::reset();
Expand Down Expand Up @@ -715,7 +713,6 @@ private function injectArtifactConfig(string $name, array $config): void
{
$reflection = new \ReflectionClass(ArtifactConfig::class);
$property = $reflection->getProperty('artifact_configs');
$property->setAccessible(true);
$configs = $property->getValue(null) ?? [];
$configs[$name] = $config;
$property->setValue(null, $configs);
Expand Down
Loading
Loading