/** * Initializes this logger. * * Available options: * * * web_debug_class: The web debug class (sfWebDebug by default) * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. * * @return Boolean true, if initialization completes successfully, otherwise false. * * @see sfVarLogger */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { $this->context = sfContext::getInstance(); $this->webDebugClass = isset($options['web_debug_class']) ? $options['web_debug_class'] : 'sfWebDebug'; if (sfConfig::get('sf_web_debug')) { $dispatcher->connect('context.load_factories', array($this, 'listenForLoadFactories')); $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); } $this->registerErrorHandler(); return parent::initialize($dispatcher, $options); }
/** * Main entry point into the application. * * @return void */ public function main() { $runner = new DocBlox_Task_Runner($_SERVER['argc'] == 1 ? false : $_SERVER['argv'][1], 'project:run'); $task = $runner->getTask(); $threshold = DocBlox_Core_Log::WARN; if (!$task->getQuiet()) { DocBlox_Core_Application::renderVersion(); } else { $threshold = DocBlox_Core_Log::QUIET; } if ($task->getVerbose()) { $threshold = DocBlox_Core_Log::DEBUG; } $dispatcher = new sfEventDispatcher(); $logger = new DocBlox_Core_Log(DocBlox_Core_Log::FILE_STDOUT); $logger->setThreshold($threshold); $dispatcher->connect('system.log', array($logger, 'log')); DocBlox_Parser_Abstract::$event_dispatcher = $dispatcher; DocBlox_Transformer_Abstract::$event_dispatcher = $dispatcher; DocBlox_Reflection_Abstract::$event_dispatcher = $dispatcher; try { $task->execute(); } catch (Exception $e) { if (!$task->getQuiet()) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL . PHP_EOL; echo $task->getUsageMessage(); } die(1); } }
/** * Initializes this sfLogger instance. * * Available options: * * - level: The log level. * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. * * @return Boolean true, if initialization completes successfully, otherwise false. * * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfLogger. */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { if (isset($options['level'])) { $this->setLogLevel($options['level']); } $dispatcher->connect('application.log', array($this, 'listenToLogEvent')); }
protected function _start() { $formatter = new sfFormatter(80); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('command.log', array($this, "logTask")); $this->taskLog = array(); $this->task = new InstallNotifierTask($dispatcher, $formatter); }
/** * Initializes this logger. * * Available options: * * - logger_service_id: The service id to use as the logger. Default: logger.psr * - auto_connect: If we must connect automatically to the context.load_factories to set the logger. Default: true * * @param sfEventDispatcher $dispatcher * @param array $options * * @return void */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { if (isset($options['logger_service_id'])) { $this->loggerServiceId = $options['logger_service_id']; } if (!isset($options['auto_connect']) || $options['auto_connect']) { $dispatcher->connect('context.load_factories', array($this, 'listenContextLoadFactoriesEvent')); } parent::initialize($dispatcher, $options); }
/** * Initializes this logger. * * Available options: * * - web_debug_class: The web debug class (sfWebDebug by default). * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. * * @return Boolean true, if initialization completes successfully, otherwise false. * * @see sfVarLogger */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { $this->context = sfContext::getInstance(); $this->dispatcher = $dispatcher; $this->webDebugClass = isset($options['web_debug_class']) ? $options['web_debug_class'] : 'sfWebDebug'; if (sfConfig::get('sf_web_debug')) { $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); } return parent::initialize($dispatcher, $options); }
public static function initialize(sfEventDispatcher $dispatcher, $culture = null) { $dispatcher->connect('user.change_culture', array('sfPropel', 'listenToChangeCultureEvent')); if (!is_null($culture)) { self::setDefaultCulture($culture); } else { if (class_exists('sfContext', false) && sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::setDefaultCulture($user->getCulture()); } } self::$initialized = true; }
public function initialize(sfEventDispatcher $dispatcher, $options = array()) { $this->sfFire = sfFirePHP::getInstance(true); if (isset($options['processor'])) { sfFirePHP::setProcessor($options['processor'] . '?' . time()); } if (isset($options['renderer'])) { sfFirePHP::setRenderer($options['renderer'] . '?' . time()); } $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); $this->dispatcher = $dispatcher; return parent::initialize($dispatcher, $options); }
public function register($file) { if (!file_exists($file) || !is_readable($file)) { throw new Exception('The plugin file "' . $file . '" must exist and be readable'); } $reflection = new DocBlox_Reflection_File($file); $classes = $reflection->getClasses(); if (count($classes) > 1) { throw new Exception('Plugin file should only contain one class'); } /** @var DocBlox_Reflection_Class $listener_definition */ $listener_definition = reset($classes); // initialize the plugin / event listener include_once $file; $listener_name = $listener_definition->getName(); $listener = new $listener_name($this->event_dispatcher); // connect all events of the each method to the event_dispatcher foreach ($listener_definition->getMethods() as $method) { /** @var DocBlox_Reflection_Tag $event */ foreach ($method->getDocBlock()->getTagsByName('event') as $event) { $this->event_dispatcher->connect($event->getDescription(), array($listener, $method->getName())); } } }
/** * Initializes this logger. * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. * * @return Boolean true, if initialization completes successfully, otherwise false. */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { $this->context = sfContext::getInstance(); $this->dispatcher = $dispatcher; $class = isset($options['web_debug_class']) ? $options['web_debug_class'] : 'sfWebDebug'; $this->webDebug = new $class($dispatcher); $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); if (isset($options['xdebug_logging'])) { $this->xdebugLogging = $options['xdebug_logging']; } // disable xdebug when an HTTP debug session exists (crashes Apache, see #2438) if (isset($_GET['XDEBUG_SESSION_START']) || isset($_COOKIE['XDEBUG_SESSION'])) { $this->xdebugLogging = false; } return parent::initialize($dispatcher, $options); }
/** * Подготовить таск (мок), запустить и проверить вызовы методов * * @param array $ntfnList - Массив OperationNotification * @param bool $isOk - Успешно отправить уведомления */ private function runAndCheckTask(array $ntfnList, $isOk) { // Мок таска - перекроем 'getEventsFromQueue', чтобы изолировать логику // выборки уведомлений. И будем свои уведомления на отправку $task = $this->getMock('myOperationNotificationTask', array('getEventsFromQueue'), array($dispatcher = new sfEventDispatcher(), new sfFormatter())); $task->expects($this->once())->method('getEventsFromQueue')->will($this->returnValue($ntfnList)); // Создаем и регистрируем обработчик уведомлении и будем проверять его вызовы $handler = $this->getMock('myNotificationHandlerInterface', array('run')); $handler->expects($this->exactly(count($ntfnList)))->method('run')->will($this->returnValue($isOk)); foreach ($ntfnList as $ntfn) { $task->registerHandler($ntfn->getType(), $handler); } // Повесим собственный обработчик на логи таска, чтобы их сохранять и проверять $dispatcher->connect('command.log', array($this, 'handleTaskLogs')); // Запустить таск $task->run($args = array(), $options = array('env' => 'test')); }
/** * Initialize sfymfony propel * * @param sfEventDispatcher $dispatcher * @param string $culture */ public static function initialize(sfEventDispatcher $dispatcher, $culture = null) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { // add propel logger Propel::setLogger(new sfPropelLogger($dispatcher)); } // propel initialization $configuration = sfPropelDatabase::getConfiguration(); if ($configuration) { Propel::setConfiguration($configuration); if (!Propel::isInit()) { Propel::initialize(); } } $dispatcher->connect('user.change_culture', array('sfPropel', 'listenToChangeCultureEvent')); if (!is_null($culture)) { self::setDefaultCulture($culture); } else { if (class_exists('sfContext', false) && sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::setDefaultCulture($user->getCulture()); } } self::$initialized = true; }
/** * Registers the new methods in the component class. * * @param sfEventDispatcher A sfEventDispatcher instance */ public static function register(sfEventDispatcher $dispatcher) { $mixin = new sfSslRequirementActionMixin(); $dispatcher->connect('component.method_not_found', array($mixin, 'listenToMethodNotFound')); return $mixin; }
/** * Initializes this logger. * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { $dispatcher->connect('command.log', array($this, 'listenToLogEvent')); return parent::initialize($dispatcher, $options); }
/** * Initialize and Configure an SFEventDispatcher instance * * @return sfEventDispatcher A configured event dispatcher instance */ function initializeSFEventDispatcher() { $eventdispatcher = new sfEventDispatcher(); $eventdispatcher->connect(SYSTEM_ADDVARIABLE, "auditTransactionEventHandler"); $eventdispatcher->connect(SYSTEM_UPDATEVARIABLE, "auditTransactionEventHandler"); $eventdispatcher->connect(SYSTEM_DELETEVARIABLE, "auditTransactionEventHandler"); $eventdispatcher->connect(SYSTEM_CREATEROLE, "auditTransactionEventHandler"); $eventdispatcher->connect(SYSTEM_UPDATEROLE, "auditTransactionEventHandler"); $eventdispatcher->connect(SYSTEM_DELETEROLE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_LOGIN, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_LOGOUT, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_CREATE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_UPDATE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_DELETE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_DEACTIVATE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_REACTIVATE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_CHANGE_PASSWORD, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_RESET_PASSWORD, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_RESET_PASSWORD_CONFIRM, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_CHANGE_EMAIL, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_CHANGE_EMAIL_CONFIRM, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_CHANGE_USERNAME, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_RECOVER_PASSWORD, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_INVITE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_ACTIVATE, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_SIGNUP, "auditTransactionEventHandler"); $eventdispatcher->connect(USER_UPLOADPHOTO, "auditTransactionEventHandler"); return $eventdispatcher; }
{ $this->events[] = func_get_args(); } public function filter(sfEvent $event, $value) { $this->events[] = func_get_args(); return $value; } public function reset() { $this->events = array(); } } $listener = new FormListener(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('form.post_configure', array($listener, 'listen')); $dispatcher->connect('form.filter_values', array($listener, 'filter')); $dispatcher->connect('form.validation_error', array($listener, 'listen')); sfFormSymfony::setEventDispatcher($dispatcher); class TestForm extends sfFormSymfony { public function configure() { $this->setValidators(array('first_name' => new sfValidatorString(), 'last_name' => new sfValidatorString())); } } // ->__construct() $t->diag('->__construct()'); $listener->reset(); $form = new TestForm(); $t->is(count($listener->events), 1, '->__construct() notifies one event');
/** * This file is part of the sfSearch package. * (c) Carl Vondrick <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'event/sfEventDispatcher.class.php'; require 'event/sfEvent.class.php'; require 'log/xfLogger.interface.php'; require 'log/xfLoggerEventDispatcher.class.php'; $t = new lime_test(3, new lime_output_color()); $dispatcher = new sfEventDispatcher(); $logger = new xfLoggerEventDispatcher($dispatcher); $logger->setEventName('search.test'); function handle(sfEvent $event = null) { static $got; if ($event) { $got = $event; } else { return $got; } } $dispatcher->connect('search.test', 'handle'); $logger->log('foobar', 'MySearch'); $t->is(handle()->getName(), 'search.test', '->setEventName() changes the event name'); $t->is(handle()->getSubject(), $logger, '->log() sets the index name'); $t->is(handle()->getParameters(), array('foobar', 'section' => 'MySearch'), '->log() logs a message');
$t->diag('->getCurrentInternalUri()'); $r->clearRoutes(); $r->connect('test2', new sfRoute('/module/action/:id', array('module' => 'foo', 'action' => 'bar'))); $r->connect('test', new sfRoute('/:module', array('action' => 'index'))); $r->connect('test1', new sfRoute('/:module/:action/*', array())); $r->connect('test3', new sfRoute('/', array())); $r->parse('/'); $t->is($r->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); $r->parse('/foo/bar/bar/foo/a/b'); $t->is($r->getCurrentInternalUri(), 'foo/bar?a=b&bar=foo', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); $r->parse('/module/action/2'); $t->is($r->getCurrentInternalUri(true), '@test2?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); // Lazy routes config cache $t->diag('Lazy Routes Config Cache'); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('routing.load_configuration', 'configureRouting'); function configureRouting($event) { $event->getSubject()->connect('first', new sfRoute('/first')); $event->getSubject()->connect('second', new sfRoute('/', array())); } // these tests are against r7363 $t->is($r->getCurrentInternalUri(false), 'foo/bar?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); $t->is($r->getCurrentInternalUri(true), '@test2?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); $t->is($r->getCurrentInternalUri(false), 'foo/bar?id=2', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); // regression for ticket #3423 occuring when cache is used. (for the test its enough to have it non null) $rCached = new sfPatternRoutingTest(new sfEventDispatcher(), new sfNoCache(), $options); $rCached->connect('test', new sfRoute('/:module', array('action' => 'index'))); $rCached->connect('test2', new sfRoute('/', array())); $rCached->parse('/'); $t->is($rCached->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL using cache');
$dispatcher->connect('foo', array($listener, 'listenToFooBis')); $dispatcher->connect('foo', array($listener, 'listenToFoo')); $e = $dispatcher->notifyUntil($event = new sfEvent(new stdClass(), 'foo')); $t->is($listener->getValue(), 'listenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true'); // ->filter() $t->diag('->filter()'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFoo')); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $e = $dispatcher->filter($event = new sfEvent(new stdClass(), 'foo'), 'foo'); $t->is($e->getReturnValue(), '-*foo*-', '->filter() filters a value'); $t->is($e, $event, '->filter() returns the event object'); $listener->reset(); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('foo', array($listener, 'filterFooBis')); $dispatcher->connect('foo', array($listener, 'filterFoo')); $e = $dispatcher->filter($event = new sfEvent(new stdClass(), 'foo'), 'foo'); $t->is($e->getReturnValue(), '*-foo-*', '->filter() filters a value'); class Listener { protected $value = ''; function filterFoo(sfEvent $event, $foo) { return "*{$foo}*"; } function filterFooBis(sfEvent $event, $foo) { return "-{$foo}-"; } function listenToFoo(sfEvent $event)
public function connect(sfEventDispatcher $dispatcher) { $dispatcher->connect('routing.load_configuration', array($this, 'updateDefaultConfig')); }
/** * @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');
public function connect(sfEventDispatcher $dispatcher) { $dispatcher->connect('template.filter_parameters', array($this, 'filterParameters')); }
* (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; class myRequest extends sfRequest { public function getEventDispatcher() { return $this->dispatcher; } } $t = new lime_test(15, new lime_output_color()); $dispatcher = new sfEventDispatcher(); $dispatcher->connect('request.method_not_found', array('sfRequestCompat10', 'call')); $request = new myRequest($dispatcher); // ->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames() $t->diag('->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames()'); // single error $key = "test"; $value = "error"; $request->setError($key, $value, '->setError() add an error message for the given parameter'); $t->is($request->hasError($key), true, '->hasError() returns true if an error exists for the given parameter'); $t->is($request->hasErrors(), true, '->hasErrors() returns true if there are some errors'); $t->is($request->getError($key), $value, '->getError() returns the error text for the given parameter'); $t->is($request->removeError($key), $value, '->removeError() removes the error for the given parameter'); $t->is($request->hasError($key), false, '->hasError() returns false if no error exists for the given parameter'); $t->is($request->hasErrors(), false, '->hasErrors() returns false if there is no error'); // multiple errors $key1 = "test1";
/** * This file is part of the sfSearch package. * (c) Carl Vondrick <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'log/xfLogger.interface.php'; require 'log/xfLoggerTask.class.php'; require 'event/sfEvent.class.php'; require 'event/sfEventDispatcher.class.php'; require 'command/sfFormatter.class.php'; $t = new lime_test(3, new lime_output_color()); $formatter = new sfFormatter(); $dispatcher = new sfEventDispatcher(); function handle(sfEvent $event = null) { static $got; if ($event) { $got = $event; } else { return $got; } } $dispatcher->connect('command.log', 'handle'); $logger = new xfLoggerTask($dispatcher, $formatter); $logger->log('Did something', 'MySearch'); $t->is(handle()->getSubject(), $logger, '->log() logs with the logger as the subject'); $t->is(handle()->getParameters(), array('MySearch >> Did something'), '->log() formats the message'); $t->is(handle()->getName(), 'command.log', '->log() notifies the correct event');
public function connect($name, $listener) { if (!isset($this->_connected[$name])) { $this->_connected[$name] = array(); } $this->_connected[$name][] = $listener; parent::connect($name, $listener); }