develop7
11/2/2009 - 11:51 AM

ProjectConfiguration.class.php

<?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
class userActions extends sfActions
{
  //...где-то в контроллере
  public function executeSomething(sfWebRequest $request)
  {
    //...ещё глубже в дебри
    $this->getEventDispatcher()->notify(new sfEvent($this, 'logging.triggerblabla', array('param1' => 'foo)));
  }
}
<?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'));
  }
}