Convert this to an event subscriber (see https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/EventSubscriber.php)