Skip to content

Allow injecting a PSR-3 logger for requirement checks instead of trigger_error #451

@la-refactory

Description

@la-refactory

Problem

Utils::checkRequirement() reports findings via trigger_error(). The check is correct; the channel is the issue.

My setup: I run PHP through the official php:8.5-cli Docker image rather than installing PHP on the host, so my php is effectively docker run --rm -v $PWD:/app -w /app php:8.5-cli php. The base image ships without GMP or BCMath, which is exactly what the recommendation notice is about.

In frameworks that promote PHP errors to exceptions (Yii 2.0 in my case), the E_USER_NOTICE raised from WebPush::__construct() becomes a fatal ErrorException at container boot - crashing unrelated CLI commands that never send a push notification. Installing GMP fixes the symptom for me, but the library hard-coding how its diagnostics are delivered is the real design issue, and it'll resurface for anyone running on a minimal/containerized PHP.

Proposal

Accept an optional Psr\Log\LoggerInterface on WebPush::__construct() and forward it to Utils::checkRequirement(). When provided, log; when not, fall back to trigger_error.

Happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions