/** * @see xfLogger */ public function log($message, $section = 'sfSearch') { $message = preg_replace('/"(.+?)"/e', '$this->formatter->format("\\1", array("fg" => "blue", "bold" => true));', $message); $message = preg_replace('/\\.{3}$/e', '$this->formatter->format("...", array("fg" => "red", "bold" => true));', $message); $message = preg_replace('/(Warning|Error)!/e', '$this->formatter->format("\\1!", array("fg" => "red", "bold" => true));', $message); $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format($section, array('fg' => 'green', 'bold' => true)) . ' >> ' . $message))); }
public static function notifyPostExecuteActionEvent($subject, sfEventDispatcher $dispatcher, sfAction $actionInstance, $result) { $moduleName = $actionInstance->getModuleName(); $actionName = $actionInstance->getActionName(); $params = array('moduleName' => $moduleName, 'actionName' => $actionName, 'actionInstance' => $actionInstance, 'result' => $result); $dispatcher->notify(new sfEvent($subject, 'op_action.post_execute_' . $moduleName . '_' . $actionName, $params)); $dispatcher->notify(new sfEvent($subject, 'op_action.post_execute', $params)); }
/** * Dispatches an event to the Event Dispatcher. * * This method tries to dispatch an event; if no Event Dispatcher has been * set than this method will explicitly not fail and return null. * * By not failing we make the Event Dispatcher optional and is it easier * for people to re-use this component in their own application. * * @param string $name Name of the event to dispatch. * @param string[] $arguments Arguments for this event. * * @throws DocBlox_Parser_Exception if there is a dispatcher but it is not * of type sfEventDispatcher * * @return mixed|null */ public function dispatch($name, $arguments) { if (!self::$event_dispatcher) { return null; } if (!self::$event_dispatcher instanceof sfEventDispatcher) { throw new DocBlox_Parser_Exception('Expected the event dispatcher to be an instance of ' . 'sfEventDispatcher'); } $event = self::$event_dispatcher->notify(new sfEvent($this, $name, $arguments)); return $event ? $event->getReturnValue() : null; }
public function handleEventMessage(sfEvent $event) { $message = $this->notifier()->decoratedMessage($event->getSubject()); $message->addSection('Message Details', $event->getParameters()); $message->addSection('Server', $this->notifier()->helper()->formatServer()); $this->dispatcher->notify(new sfEvent($message, 'notify.decorate_message')); $this->notifier()->driver()->notify($message); }
/** * * @param Exception $e * * @return void */ public function handleException(Exception $e) { $message = $this->notifier()->decoratedMessage($e->getMessage()); $message->addSection('Exception', $this->notifier()->helper()->formatException($e)); $message->addSection('Server', $this->notifier()->helper()->formatServer()); $this->dispatcher->notify(new sfEvent($message, 'notify.exception')); $this->notifier()->driver()->notify($message); }
/** * Initialize symfony propel * * @param sfEventDispatcher $dispatcher * @param string $culture * * @deprecated Moved to {@link sfPropelPluginConfiguration} */ public static function initialize(sfEventDispatcher $dispatcher, $culture = null) { $dispatcher->notify(new sfEvent(__CLASS__, 'application.log', array(__METHOD__ . '() has been deprecated. Please call sfPropel::setDefaultCulture() to set the culture.', 'priority' => sfLogger::NOTICE))); if (null !== $culture) { self::setDefaultCulture($culture); } else { if (class_exists('sfContext', false) && sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::setDefaultCulture($user->getCulture()); } } }
$t->is($dispatcher->getListeners('foobar'), array(), '->getListeners() returns an empty array if no listener are connected to the given event name'); $listener = new Listener(); // ->notify() $t->diag('->notify()'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $e = $dispatcher->notify($event = new sfEvent(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFoolistenToFooBis', '->notify() notifies all registered listeners in order'); $t->is($e, $event, '->notify() returns the event object'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->notify(new sfEvent(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBislistenToFoo', '->notify() notifies all registered listeners in order'); // ->notifyUntil() $t->diag('->notifyUntil()'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $e = $dispatcher->notifyUntil($event = new sfEvent(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFoolistenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); $t->is($e, $event, '->notifyUntil() returns the event object'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $e = $dispatcher->notifyUntil($event = new sfEvent(new stdClass(), 'foo'));
/** * @package sfLucenePlugin * @subpackage Test * @author Carl Vondrick * @version SVN: $Id: sfLuceneEventConnectorTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $ */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new limeade_test(5, limeade_output::get()); $limeade = new limeade_sf($t); $app = $limeade->bootstrap(); class FooListener { public $event; public function listen($event) { $this->event = $event; } } $source = new sfEventDispatcher(); $target = new sfEventDispatcher(); $connector = new sfLuceneEventConnector($source, 'foo', $target, 'bar'); $t->ok($source->hasListeners('foo'), '__construct() connects a listener to the source'); $subject = 'Fabien'; $params = array('a', 'b', 'c'); $listener = new FooListener(); $target->connect('bar', array($listener, 'listen')); $source->notify(new sfEvent($subject, 'foo', $params)); $t->isa_ok($listener->event, 'sfEvent', 'calling a linked event calls target'); $t->is($listener->event->getSubject(), $subject, 'calling a linked event sends correct subject'); $t->is($listener->event->getName(), 'bar', 'calling a linked event sends correct name'); $t->is($listener->event->getParameters(), $params, 'calling a linked event sends correct parameters');
/** * Constructor. * * Available options: * * * charset: The default charset to use for messages * * logging: Whether to enable logging or not * * delivery_strategy: The delivery strategy to use * * spool_class: The spool class (for the spool strategy) * * spool_arguments: The arguments to pass to the spool constructor * * delivery_address: The email address to use for the single_address strategy * * transport: The main transport configuration * * * class: The main transport class * * * param: The main transport parameters * * @param sfEventDispatcher $dispatcher An event dispatcher instance * @param array $options An array of options */ public function __construct(sfEventDispatcher $dispatcher, $options) { // options $options = array_merge(array('charset' => 'UTF-8', 'logging' => false, 'delivery_strategy' => 'realtime', 'transport' => array('class' => 'Swift_MailTransport', 'param' => array())), $options); $constantName = 'sfMailer::' . strtoupper($options['delivery_strategy']); $this->strategy = defined($constantName) ? constant($constantName) : false; if (!$this->strategy) { throw new InvalidArgumentException(sprintf('Unknown mail delivery strategy "%s" (should be one of realtime, spool, single_address, or none)', $options['delivery_strategy'])); } // transport $class = $options['transport']['class']; $transport = new $class(); if (isset($options['transport']['param'])) { foreach ($options['transport']['param'] as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($transport, $method)) { $transport->{$method}($value); } elseif (method_exists($transport, 'getExtensionHandlers')) { foreach ($transport->getExtensionHandlers() as $handler) { if (in_array(strtolower($method), array_map('strtolower', (array) $handler->exposeMixinMethods()))) { $transport->{$method}($value); } } } } } $this->realtimeTransport = $transport; if (sfMailer::SPOOL == $this->strategy) { if (!isset($options['spool_class'])) { throw new InvalidArgumentException('For the spool mail delivery strategy, you must also define a spool_class option'); } $arguments = isset($options['spool_arguments']) ? $options['spool_arguments'] : array(); if ($arguments) { $r = new ReflectionClass($options['spool_class']); $this->spool = $r->newInstanceArgs($arguments); } else { $this->spool = new $options['spool_class'](); } $transport = new Swift_SpoolTransport($this->spool); } elseif (sfMailer::SINGLE_ADDRESS == $this->strategy) { if (!isset($options['delivery_address'])) { throw new InvalidArgumentException('For the single_address mail delivery strategy, you must also define a delivery_address option'); } $this->address = $options['delivery_address']; $transport->registerPlugin($this->redirectingPlugin = new Swift_Plugins_RedirectingPlugin($this->address)); } parent::__construct($transport); // logger if ($options['logging']) { $this->logger = new sfMailerMessageLoggerPlugin($dispatcher); $transport->registerPlugin($this->logger); } if (sfMailer::NONE == $this->strategy) { // must be registered after logging $transport->registerPlugin(new Swift_Plugins_BlackholePlugin()); } // preferences Swift_Preferences::getInstance()->setCharset($options['charset']); $dispatcher->notify(new sfEvent($this, 'mailer.configure')); }
/** * Notify all listeners of the event, through the event dispatcher instance for the class. This is just a convenience method to * avoid accessing the event dispatcher directly * * @param sfEvent $event The event that has occured */ function notify($event) { $this->eventdispatcher->notify($event); }
/** * @see xfLogger */ public function log($message, $section = 'sfSearch') { $this->dispatcher->notify(new sfEvent($this, $this->event, array($message, 'section' => $section))); }
public function notify(sfEvent $event) { $this->_events[] = $event; return parent::notify($event); }
public function setEventDispatcher(sfEventDispatcher $dispatcher) { if ($this->isUnknown()) { $dispatcher->notify(new sfEvent($this, 'dm.browser.unknown', $this->getUserAgentString())); } }
protected function log($message) { if ($this->dispatcher) { $this->dispatcher->notify(new sfEvent($this, 'command.log', array($message))); } }