What is the purpose of the LoggerAwareInterface in PHP and how does it differ from the LoggerInterface?

The purpose of the LoggerAwareInterface in PHP is to provide a standard way for classes to receive a logger instance. This interface requires classes to implement a setLogger() method, allowing them to be injected with a logger object. This differs from the LoggerInterface, which defines methods for logging messages but does not provide a way to inject a logger into a class.

<?php

use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

class MyClass implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    public function doSomething()
    {
        $this->logger->info('Doing something...');
    }
}

// Usage
$myClass = new MyClass();
$myClass->setLogger($logger);
$myClass->doSomething();