for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of Ekino New Relic bundle.
*
* (c) Ekino - Thomas Rabaix <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ekino\Bundle\NewRelicBundle\Listener;
use Ekino\Bundle\NewRelicBundle\Exception\DeprecationException;
use Ekino\Bundle\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
class DeprecationListener
{
private $isRegistered = false;
private $interactor;
public function __construct(NewRelicInteractorInterface $interactor)
$this->interactor = $interactor;
}
public function register(): void
if ($this->isRegistered) {
return;
$this->isRegistered = true;
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$prevErrorHandler) {
$prevErrorHandler
if (E_USER_DEPRECATED === $type) {
$this->interactor->noticeThrowable(new DeprecationException($msg, 0, $type, $file, $line));
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
});
public function unregister(): void
if (!$this->isRegistered) {
$this->isRegistered = false;
restore_error_handler();