nette / tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.
https://tracy.nette.org
Other
1.75k stars 218 forks source link

Fix deprecation with custom logger that doesn't have public mailer property #550

Closed josefsabl closed 1 year ago

josefsabl commented 1 year ago
mabar commented 1 year ago

Issue is not just about mailer, it includes also properties fromEmail and emailSnooze. Fixing it by condition just continues to ignore error - user set a property, which is expected to do something, but in reality does nothing. And fixing it by introducing new interface is a BC break making existing compatible loggers broken.

If a library replaces original logger, it is its responsibility to maintain compatibility.

Compatibility logger wrapper in its simplest version may look like this:

use Tracy\ILogger;

class ReplacingLogger implements ILogger
{

    private ILogger $originalLogger;

    public function __construct(ILogger $originalLogger)
    {
        $this->originalLogger = $originalLogger;
    }

    public function log($value, $level = self::INFO)
    {
        $this->originalLogger->log($value, $level);
    }

    public function __set(string $name, mixed $value): void
    {
        $this->originalLogger->$name = $value;
    }

    public function __get(string $name): mixed
    {
        return $this->originalLogger->$name;
    }

    public function __isset(string $name): bool
    {
        return isset($this->originalLogger->$name);
    }

    /**
     * @param array<mixed> $arguments
     */
    public function __call(string $name, array $arguments): mixed
    {
        return $this->originalLogger->$name(...$arguments);
    }

}
dg commented 1 year ago

Fixed dea9aa33fd2ab91e3123d90d83cffe00feb62f72