symfony event dispatcher cheat sheet


Create a notifier


The registered methods of the listeners are executed

    $this->dispatcher->notify(new sfEvent($this, 'rest_request.fetch_prepare', array(
      'uri'        => $uri,
      'parameters' => $parameters


The first registered method that returns true of the listeners is executed

    $this->dispatcher->notifyUntil(new sfEvent($this, 'rest_request.fetch_prepare', array(
      'uri'        => $uri,
      'parameters' => $parameters



The listener can change values

    $values = sfContext::getInstance()->getEventDispatcher()->filter(
        new sfEvent($this, 'form.update_object'), $values

(getting dispatcher from the symfony context)



Connect a listener to the notifier

In class ullMetaWidgetPassword:

$this->dispatcher->connect('form.update_object', array('ullMetaWidgetPassword', 'listenToUpdateObjectEvent'));

(getting dispatcher from within a objects attribute)


The method to be called by the notifier in case of filter


  public static function listenToUpdateObjectEvent(sfEvent $event, $values)
    if ($values['password'] == '')

    return $values;


In case of a notify:

  public static function listenToUpdateSingleColumnEvent(sfEvent $event)
    $params = $event->getParameters();
    $column = $params['column'];
    $booking = $params['object'];
    // to something  


Use symfony event dispatcher in doctrine models

sfProjectConfiguration::getActive()->getEventDispatcher()->notify(new sfEvent($this, ''))