tuupola / cors-middleware

PSR-7 and PSR-15 CORS middleware
MIT License
132 stars 16 forks source link

The middleware is too restrictive for PSR-3 compliant loggers that do not implement the `Psr\Log\LoggerInterface` #24

Closed halfpastfouram closed 6 years ago

halfpastfouram commented 6 years ago

The class Tuupola\Middleware\CorsMiddleware requires the supplied logger to be an instance of Psr\Log\LoggerInterface.

This means any PSR-3 logger that does not implement that interface, like Zend\Log\Logger, cannot be used.

Are you willing to remove the requirement of the interface so that all PSR-3 compliant loggers can be allowed?

tuupola commented 6 years ago

I was going to ask why on earth Zend\Log\Logger does not implement Psr\Log\LoggerInterface if it implements PSR-3. Then I read https://github.com/zendframework/zend-log/issues/35 which makes sense.

I do however prefer developing against interfaces so I rather not drop the requirement. To use Zend one could create a wrapper class which implements the Psr\Log\LoggerInterface but forwards the logging request to the original class.

halfpastfouram commented 6 years ago

I understand. But this means that this middleware (tested with zend-expressive) does not support Zend's logger. It might be helpful to add that to the README.md.

tuupola commented 6 years ago

Zend seems to provide PsrLoggerAdapter for this usecase.