Skip to content

Instantly share code, notes, and snippets.

@develop7
Created November 2, 2009 11:51
Show Gist options
  • Save develop7/224108 to your computer and use it in GitHub Desktop.
Save develop7/224108 to your computer and use it in GitHub Desktop.
<?php
class userActions extends sfActions
{
//...где-то в контроллере
public function executeSomething(sfWebRequest $request)
{
//...ещё глубже в дебри
$this->getEventDispatcher()->notify(new sfEvent($this, 'logging.triggerblabla', array('param1' => 'foo)));
}
}
<?php
class myLogHandler
{
static $logger = null;
static public function handleLogEvent(sfEvent $evt)
{
self::$logger->log('By '.$evt->getSubject().' param1='.$evt['param1']);//Например, так
}
protected getLogger()
{
if (self::$logger == null)
{
self::$logger = new BlaBlaLogger('foo', 'bar', 'baz');
}
return self::$logger;
}
}
<?php
# FROZEN_SF_LIB_DIR: /usr/share/php/symfony
require_once dirname(__FILE__).'/../lib/symfony/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// for compatibility / remove and enable only the plugins you want
$this->enableAllPluginsExcept(array());
$this->registerEventHandlers();
}
//...
protected function registerEventHandlers()
{
//...
$this->getEventDispatcher()->connect('logging.triggerblabla', array('myLogHandler', 'handleLogEvent'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment