Skip to content

Instantly share code, notes, and snippets.

@marekkalnik
Last active December 12, 2015 00:29
Show Gist options
  • Save marekkalnik/4684258 to your computer and use it in GitHub Desktop.
Save marekkalnik/4684258 to your computer and use it in GitHub Desktop.
EventDispatcherAwareModelInterface hack
<?php
namespace Project\Bundle\Propel;
use Project\Bundle\Propel\om\BaseNewsletterSubscription;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class NewsletterSubscription extends BaseNewsletterSubscription implements \EventDispatcherAwareModelInterface
{
/**
* Declaring this function avoids throwing a WARNING when the Base* class is not
* generated yet (eg. on propel:build)
*
* @param EventDispatcherInterface $eventDispatcher
*/
public static function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
{
if (method_exists('Project\Bundle\Propel\om\BaseNewsletterSubscription', 'setEventDispatcher')) {
BaseNewsletterSubscription::setEventDispatcher($eventDispatcher);
}
}
/**
* Declaring this function avoids throwing a WARNING when the Base* class is not
* generated yet (eg. on propel:build)
*
* @return EventDispatcherInterface
*/
public static function getEventDispatcher()
{
if (method_exists('Project\Bundle\Propel\om\BaseNewsletterSubscription', 'getEventDispatcher')) {
BaseNewsletterSubscription::getEventDispatcher();
}
}
}
@willdurand
Copy link

Not bad, but a lot of boilerplate...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment