Development

Changeset 4951

You must first sign up to be able to contribute.

Changeset 4951

Show
Ignore:
Timestamp:
09/02/07 18:27:23 (2 years ago)
Author:
fabien
Message:

added sfEventDispatcher / sfEvent classes

  • added sfEventDispatcher/sfEvent classes (replaces the sfMixer class)
  • moved sfMixer to addon/propel as Propel behavior still uses the sfMixer system
  • changed all calls to sfLogger to events
  • changed sfLogger first argument to a sfEventDispatcher
  • changed sfRouting first argument to a sfEventDispatcher (instead of a logger)
  • changed sfRequest first argument to a sfEventDispatcher (instead of a logger)
  • changed sfResponse first argument to a sfEventDispatcher (instead of a logger)
  • removed sfContext from sfUser dependencies (now takes a sfEventDispatcher and a sfStorage)
  • added the following events:
    • application.log
    • application.throw_exception
    • request.load_parameters
    • controller.change_action
    • controller.page_not_found
    • user.change_culture
    • [component|controller|request|response|user|view].method_not_found
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/config/core_compile.yml

    r4845 r4951  
    77- %SF_SYMFONY_LIB_DIR%/controller/sfController.class.php 
    88- %SF_SYMFONY_LIB_DIR%/database/sfDatabaseManager.class.php 
     9- %SF_SYMFONY_LIB_DIR%/event/sfEvent.class.php 
     10- %SF_SYMFONY_LIB_DIR%/event/sfEventDispatcher.class.php 
    911- %SF_SYMFONY_LIB_DIR%/filter/sfFilter.class.php 
    1012- %SF_SYMFONY_LIB_DIR%/filter/sfCommonFilter.class.php 
  • trunk/lib/action/sfAction.class.php

    r4593 r4951  
    129129    if (sfConfig::get('sf_logging_enabled')) 
    130130    { 
    131       $this->context->getLogger()->info('{sfAction} forward to action "'.$module.'/'.$action.'"'); 
     131      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forward to action "%s/%s"', $module, $action)))); 
    132132    } 
    133133 
     
    191191  public function redirect($url, $statusCode = 302) 
    192192  { 
    193     $url = $this->getController()->genUrl($url, true); 
    194  
    195     if (sfConfig::get('sf_logging_enabled')) 
    196     { 
    197       $this->context->getLogger()->info('{sfAction} redirect to "'.$url.'"'); 
    198     } 
    199  
    200193    $this->getController()->redirect($url, 0, $statusCode); 
    201194 
     
    412405    if (sfConfig::get('sf_logging_enabled')) 
    413406    { 
    414       $this->context->getLogger()->info('{sfAction} change template to "'.$name.'"'); 
     407      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change template to "%s"', $name)))); 
    415408    } 
    416409 
     
    446439    if (sfConfig::get('sf_logging_enabled')) 
    447440    { 
    448       $this->context->getLogger()->info('{sfAction} change layout to "'.$name.'"'); 
     441      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change layout to "%s"', $name)))); 
    449442    } 
    450443 
  • trunk/lib/action/sfActions.class.php

    r4597 r4951  
    4545    if (sfConfig::get('sf_logging_enabled')) 
    4646    { 
    47       $this->context->getLogger()->info('{sfAction} call "'.get_class($this).'->'.$actionToRun.'()'.'"'); 
     47      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun)))); 
    4848    } 
    4949 
  • trunk/lib/action/sfComponent.class.php

    r4937 r4951  
    2121  protected 
    2222    $context                = null, 
     23    $dispatcher             = null, 
    2324    $request                = null, 
    2425    $response               = null, 
     
    2728 
    2829  /** 
    29    * Execute any application/business logic for this component. 
    30    * 
    31    * In a typical database-driven application, execute() handles application 
    32    * logic itself and then proceeds to create a model instance. Once the model 
    33    * instance is initialized it handles all business logic for the action. 
    34    * 
    35    * A model should represent an entity in your application. This could be a 
    36    * user account, a shopping cart, or even a something as simple as a 
    37    * single product. 
    38    * 
    39    * @return mixed A string containing the view name associated with this action 
    40    */ 
    41   abstract function execute(); 
    42  
    43   /** 
    44    * Gets the module name associated with this component. 
    45    * 
    46    * @return string A module name 
    47    */ 
    48   public function getModuleName() 
    49   { 
    50     return $this->context->getModuleName(); 
    51   } 
    52  
    53   /** 
    54    * Gets the action name associated with this component. 
    55    * 
    56    * @return string An action name 
    57    */ 
    58   public function getActionName() 
    59   { 
    60     return $this->context->getActionName(); 
    61   } 
    62  
    63   /** 
    6430   * Initializes this component. 
    6531   * 
     
    7137  { 
    7238    $this->context                = $context; 
     39    $this->dispatcher             = $context->getEventDispatcher(); 
    7340    $this->varHolder              = new sfParameterHolder(); 
    7441    $this->request                = $context->getRequest(); 
     
    8047 
    8148  /** 
     49   * Execute any application/business logic for this component. 
     50   * 
     51   * In a typical database-driven application, execute() handles application 
     52   * logic itself and then proceeds to create a model instance. Once the model 
     53   * instance is initialized it handles all business logic for the action. 
     54   * 
     55   * A model should represent an entity in your application. This could be a 
     56   * user account, a shopping cart, or even a something as simple as a 
     57   * single product. 
     58   * 
     59   * @return mixed A string containing the view name associated with this action 
     60   */ 
     61  abstract function execute(); 
     62 
     63  /** 
     64   * Gets the module name associated with this component. 
     65   * 
     66   * @return string A module name 
     67   */ 
     68  public function getModuleName() 
     69  { 
     70    return $this->context->getModuleName(); 
     71  } 
     72 
     73  /** 
     74   * Gets the action name associated with this component. 
     75   * 
     76   * @return string An action name 
     77   */ 
     78  public function getActionName() 
     79  { 
     80    return $this->context->getActionName(); 
     81  } 
     82 
     83  /** 
    8284   * Retrieves the current application context. 
    8385   * 
     
    112114    if (sfConfig::get('sf_logging_enabled')) 
    113115    { 
    114       $this->context->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 
     116      $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => constant('sfLogger::'.strtoupper($priority))))); 
    115117    } 
    116118  } 
     
    318320 
    319321  /** 
    320    * Calls methods defined via the sfMixer class
     322   * Calls methods defined via sfEventDispatcher
    321323   * 
    322324   * @param string The method name 
     
    324326   * 
    325327   * @return mixed The returned value of the called method 
    326    * 
    327    * @see sfMixer 
    328328   */ 
    329329  public function __call($method, $arguments) 
    330330  { 
    331     if (!$callable = sfMixer::getCallable('sfComponent:'.$method)) 
     331    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     332    if (!$event->isProcessed()) 
    332333    { 
    333334      throw new sfException(sprintf('Call to undefined method sfComponent::%s.', $method)); 
    334335    } 
    335336 
    336     array_unshift($arguments, $this); 
    337  
    338     return call_user_func_array($callable, $arguments); 
     337    return $event->getReturnValue(); 
    339338  } 
    340339} 
  • trunk/lib/addon/creole/drivers/sfDebugConnection.php

    r4597 r4951  
    3737 
    3838  /** 
    39    * Optional PEAR Log class; if set queries will be logged at PEAR_LOG_INFO level
     39   * Optional sfEventDispatcher object
    4040   * @var Log 
    4141   */ 
    42   private static $logger; 
    43  
    44   /** 
    45    * Sets a Logger class (e.g. PEAR Log) to use for logging
    46    * The logger class must have a log() method.  All messages are logged at default log level. 
    47    * @param object $logger 
    48    */ 
    49   public static function setLogger($logger) 
    50   { 
    51     self::$logger = $logger; 
     42  private static $dispatcher; 
     43 
     44  /** 
     45   * Sets a sfEventDispatcher object
     46   * 
     47   * @param object $dispatcher 
     48   */ 
     49  public static function setDispatcher($dispatcher) 
     50  { 
     51    self::$dispatcher = $dispatcher; 
    5252  } 
    5353 
     
    8383    $connectionClass = Creole::import($driver); 
    8484    $this->childConnection = new $connectionClass(); 
    85     $this->log("{sfCreole} connect(): DSN: ". var_export($dsninfo, true) . ", FLAGS: " . var_export($flags, true)); 
     85    $this->log("connect(): DSN: ". var_export($dsninfo, true) . ", FLAGS: " . var_export($flags, true)); 
    8686    return $this->childConnection->connect($dsninfo, $flags); 
    8787  } 
     
    116116  public function prepareStatement($sql) 
    117117  { 
    118     $this->log("{sfCreole} prepareStatement(): $sql"); 
     118    $this->log("prepareStatement(): $sql"); 
    119119    $obj = $this->childConnection->prepareStatement($sql); 
    120120    $objClass = get_class($obj); 
     
    137137  public function applyLimit(&$sql, $offset, $limit) 
    138138  { 
    139     $this->log("{sfCreole} applyLimit(): $sql, offset: $offset, limit: $limit"); 
     139    $this->log("applyLimit(): $sql, offset: $offset, limit: $limit"); 
    140140    return $this->childConnection->applyLimit($sql, $offset, $limit); 
    141141  } 
     
    146146  public function close() 
    147147  { 
    148     $this->log("{sfCreole} close(): Closing connection."); 
     148    $this->log("close(): Closing connection."); 
    149149    return $this->childConnection->close(); 
    150150  } 
     
    173173    } 
    174174 
    175     $this->log(sprintf("{sfCreole} executeQuery(): [%.2f ms] %s", $elapsedTime * 1000, $sql)); 
     175    $this->log(sprintf("executeQuery(): [%.2f ms] %s", $elapsedTime * 1000, $sql)); 
    176176 
    177177    return $retval; 
     
    183183  public function executeUpdate($sql) 
    184184  { 
    185     $this->log("{sfCreole} executeUpdate(): $sql"); 
     185    $this->log("executeUpdate(): $sql"); 
    186186    $this->lastExecutedQuery = $sql; 
    187187    $this->numQueriesExecuted++; 
     
    202202  public function prepareCall($sql) 
    203203  { 
    204     $this->log("{sfCreole} prepareCall(): $sql"); 
     204    $this->log("prepareCall(): $sql"); 
    205205    return $this->childConnection->prepareCall($sql); 
    206206  } 
     
    235235  public function begin() 
    236236  { 
    237     $this->log("{sfCreole} beginning transaction."); 
     237    $this->log("beginning transaction."); 
    238238    return $this->childConnection->begin(); 
    239239  } 
     
    244244  public function commit() 
    245245  { 
    246     $this->log("{sfCreole} committing transaction."); 
     246    $this->log("committing transaction."); 
    247247    return $this->childConnection->commit(); 
    248248  } 
     
    253253  public function rollback() 
    254254  { 
    255     $this->log("{sfCreole} rolling back transaction."); 
     255    $this->log("rolling back transaction."); 
    256256    return $this->childConnection->rollback(); 
    257257  } 
     
    262262  public function setAutoCommit($bit) 
    263263  { 
    264     $this->log("{sfCreole} setting autocommit to: ".var_export($bit, true)); 
     264    $this->log("setting autocommit to: ".var_export($bit, true)); 
    265265    return $this->childConnection->setAutoCommit($bit); 
    266266  } 
     
    275275 
    276276  /** 
    277    * Private function that logs message using specified logger (if provided). 
     277   * Private function that logs message using specified dispatcher (if provided). 
    278278   * @param string $msg Message to log. 
    279279   */ 
    280280  private function log($msg) 
    281281  { 
    282     if (self::$logger
     282    if (self::$dispatcher && sfConfig::get('sf_logging_enabled')
    283283    { 
    284284      // message on one line 
    285285      $msg = preg_replace("/\r?\n/", ' ', $msg); 
    286       self::$logger->log($msg); 
     286      self::$dispatcher->notify(new sfEvent($this, 'application.log', array($msg))); 
    287287    } 
    288288  } 
  • trunk/lib/addon/propel/generator/sfPropelAdminGenerator.class.php

    r3302 r4951  
    2727   * @param sfGeneratorManager A sfGeneratorManager instance 
    2828   */ 
    29   public function initialize($generatorManager) 
     29  public function initialize(sfGeneratorManager $generatorManager) 
    3030  { 
    3131    parent::initialize($generatorManager); 
  • trunk/lib/addon/propel/generator/sfPropelCrudGenerator.class.php

    r4597 r4951  
    2727   * @param sfGeneratorManager A sfGeneratorManager instance 
    2828   */ 
    29   public function initialize($generatorManager) 
     29  public function initialize(sfGeneratorManager $generatorManager) 
    3030  { 
    3131    parent::initialize($generatorManager); 
  • trunk/lib/addon/propel/sfPropelAutoload.php

    r4845 r4951  
    2525  // register our logger 
    2626  require_once(sfConfig::get('sf_symfony_lib_dir').'/addon/creole/drivers/sfDebugConnection.php'); 
    27   sfDebugConnection::setLogger(sfContext::getInstance()->getLogger()); 
     27  sfDebugConnection::setDispatcher(sfContext::getInstance()->getEventDispatcher()); 
    2828} 
    2929 
  • trunk/lib/command/sfCommandLogger.class.php

    r4743 r4951  
    2525   * Initializes this logger. 
    2626   * 
    27    * @param array Options for the logger 
     27   * @param  sfEventDispatcher A sfEventDispatcher instance 
     28   * @param  array        An array of options. 
    2829   */ 
    29   public function initialize($options = array()) 
     30  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
    3031  { 
    3132    if (!isset($options['output'])) 
  • trunk/lib/command/sfSymfonyCommandApplication.class.php

    r4842 r4951  
    8686  { 
    8787    $logger = new sfCommandLogger(); 
    88     $logger->initialize(array('output' => new sfConsoleColorizer())); 
     88    $logger->initialize(new sfEventDispatcher(), array('output' => new sfConsoleColorizer())); 
    8989    $this->setLogger($logger); 
    9090  } 
  • trunk/lib/config/sfFactoryConfigHandler.class.php

    r4934 r4951  
    111111 
    112112          // append instance initialization 
    113           $inits[] = sprintf("  \$this->factories['request']->initialize(\$this->factories['logger'], \$this->factories['routing'], sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true)); 
     113          $inits[] = sprintf("  \$this->factories['request']->initialize(\$this->dispatcher, sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true)); 
    114114          break; 
    115115 
     
    119119 
    120120          // append instance initialization 
    121           $inits[] = sprintf("  \$this->factories['response']->initialize(\$this->factories['logger'], sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 
     121          $inits[] = sprintf("  \$this->factories['response']->initialize(\$this->dispatcher, sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 
    122122          $inits[] = sprintf("  if ('HEAD' == \$this->factories['request']->getMethodName())\n  {  \n    \$this->factories['response']->setHeaderOnly(true);\n  }\n"); 
    123123          break; 
     
    142142 
    143143          // append instance initialization 
    144           $inits[] = sprintf("  \$this->factories['user']->initialize(\$this, array_merge(array('use_flash' => sfConfig::get('sf_use_flash')), sfConfig::get('sf_factory_user_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 
     144          $inits[] = sprintf("  \$this->factories['user']->initialize(\$this->dispatcher, \$this->factories['storage'], array_merge(array('culture' => \$this->factories['request']->getParameter('sf_culture'), 'default_culture' => sfConfig::get('sf_i18n_default_culture'), 'use_flash' => sfConfig::get('sf_use_flash')), sfConfig::get('sf_factory_user_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 
    145145          break; 
    146146 
     
    186186 
    187187          // append instance initialization 
    188           $inits[] = sprintf("  \$this->factories['routing']->initialize(\$this->factories['logger'], array_merge(array('suffix' => sfConfig::get('sf_suffix'), 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action')), sfConfig::get('sf_factory_routing_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 
     188          $inits[] = sprintf("  \$this->factories['routing']->initialize(\$this->dispatcher, array_merge(array('suffix' => sfConfig::get('sf_suffix'), 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action')), sfConfig::get('sf_factory_routing_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 
    189189          break; 
    190190 
     
    217217              { 
    218218                // create logger instance 
    219                 $loggers .= sprintf("\n\$logger = sfLogger::newInstance('%s');\n\$logger->initialize(%s);\n\$this->factories['logger']->addLogger(\$logger);\n",  
     219                $loggers .= sprintf("\n\$logger = sfLogger::newInstance('%s');\n\$logger->initialize(\$this->dispatcher, %s);\n\$this->factories['logger']->addLogger(\$logger);\n",  
    220220                              $keys['class'], 
    221221                              isset($keys['param']) ? var_export($keys['param'], true) : '' 
     
    229229          $instances[] = sprintf( 
    230230                         "  \$this->factories['logger'] = sfLogger::newInstance(sfConfig::get('sf_factory_logger', '%s'));\n". 
    231                          "  \$this->factories['logger']->initialize(sfConfig::get('sf_factory_logger_parameters', %s));\n". 
     231                         "  \$this->factories['logger']->initialize(\$this->dispatcher, sfConfig::get('sf_factory_logger_parameters', %s));\n". 
    232232                         "  %s" 
    233233                         , $class, var_export($parameters, true), $loggers); 
  • trunk/lib/config/sfViewConfigHandler.class.php

    r4593 r4951  
    155155 
    156156      $data .= "  \$this->setComponentSlot('$name', '{$component[0]}', '{$component[1]}');\n"; 
    157       $data .= "  if (sfConfig::get('sf_logging_enabled')) \$this->context->getLogger()->info('{sfViewConfig} set component \"$name\" ({$component[0]}/{$component[1]})');\n"; 
     157      $data .= "  if (sfConfig::get('sf_logging_enabled')) \$this->context->getEventDispatcher()->notify(new sfEvent(\$this, 'application.log', array(sprintf('Set component \"%s\" (%s/%s)', $name, $component[0], $component[1]))));\n"; 
    158158    } 
    159159 
  • trunk/lib/controller/sfController.class.php

    r4937 r4951  
    2323  protected 
    2424    $context           = null, 
     25    $dispatcher        = null, 
    2526    $controllerClasses = array(), 
    2627    $maxForwards       = 5, 
     
    172173      if (sfConfig::get('sf_logging_enabled')) 
    173174      { 
    174         $this->context->getLogger()->info('{sfController} action does not exist'); 
     175        $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Action does not exist'))); 
    175176      } 
    176177 
     
    224225        require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/filters.yml')); 
    225226 
    226         if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action')) 
    227         { 
    228           $this->context->getResponse()->setStatusCode(404); 
    229           $this->context->getResponse()->setHttpHeader('Status', '404 Not Found'); 
    230  
    231           foreach (sfMixer::getCallables('sfController:forward:error404') as $callable) 
    232           { 
    233             call_user_func($callable, $this, $moduleName, $actionName); 
    234           } 
    235         } 
    236  
    237         // change i18n message source directory to our module 
    238         if (sfConfig::get('sf_i18n')) 
    239         { 
    240           $this->context->getI18N()->setMessageSource(sfLoader::getI18NDirs($moduleName), $this->context->getUser()->getCulture()); 
    241         } 
     227        $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', array('module' => $moduleName, 'action' => $actionName))); 
    242228 
    243229        // process the filter chain 
     
    335321 
    336322  /** 
    337    * Retrieves the current application context. 
    338    * 
    339    * @return sfContext A sfContext instance 
    340    */ 
    341   public function getContext() 
    342   { 
    343     return $this->context; 
    344   } 
    345  
    346   /** 
    347323   * Retrieves the presentation rendering mode. 
    348324   * 
     
    401377  public function initialize($context) 
    402378  { 
    403     $this->context = $context; 
     379    $this->context    = $context; 
     380    $this->dispatcher = $context->getEventDispatcher(); 
    404381 
    405382    if (sfConfig::get('sf_logging_enabled')) 
    406383    { 
    407       $this->context->getLogger()->info('{sfController} initialization'); 
     384      $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Initialization'))); 
    408385    } 
    409386 
     
    470447    if (sfConfig::get('sf_logging_enabled')) 
    471448    { 
    472       $this->context->getLogger()->info('{sfController} get presentation for action "'.$module.'/'.$action.'" (view class: "'.$viewName.'")'); 
     449      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Get presentation for action "%s/%s" (view class: "%s")', $module, $action, $viewName)))); 
    473450    } 
    474451 
     
    559536 
    560537  /** 
    561    * Calls methods defined via the sfMixer class
     538   * Calls methods defined via sfEventDispatcher
    562539   * 
    563540   * @param string The method name 
     
    565542   * 
    566543   * @return mixed The returned value of the called method 
    567    * 
    568    * @see sfMixer 
    569544   */ 
    570545  public function __call($method, $arguments) 
    571546  { 
    572     if (!$callable = sfMixer::getCallable('sfController:'.$method)) 
     547    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'controller.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     548    if (!$event->isProcessed()) 
    573549    { 
    574550      throw new sfException(sprintf('Call to undefined method sfController::%s.', $method)); 
    575551    } 
    576552 
    577     array_unshift($arguments, $this); 
    578  
    579     return call_user_func_array($callable, $arguments); 
     553    return $event->getReturnValue(); 
    580554  } 
    581555} 
  • trunk/lib/controller/sfFrontWebController.class.php

    r4839 r4951  
    3434      if (sfConfig::get('sf_logging_enabled')) 
    3535      { 
    36         $this->context->getLogger()->info('{sfController} dispatch request'); 
     36        $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Dispatch request'))); 
    3737      } 
    3838 
  • trunk/lib/controller/sfWebController.class.php

    r4762 r4951  
    9494    } 
    9595 
    96     $r = $this->context->getRouting(); 
    97     if ($r->hasRoutes() && $generated_url = $r->generate($route_name, $parameters, $querydiv, $divider, $equals)) 
    98     { 
    99       $url .= $generated_url; 
    100     } 
    101     else 
    102     { 
    103       $query = http_build_query($parameters); 
    104  
    105       if (sfConfig::get('sf_url_format') == 'PATH') 
    106       { 
    107         $query = strtr($query, ini_get('arg_separator.output').'=', '/'); 
    108       } 
    109  
    110       $url .= $query; 
    111     } 
     96    // routing to generate path 
     97    $url .= $this->context->getRouting()->generate($route_name, $parameters, $querydiv, $divider, $equals); 
    11298 
    11399    if ($absolute) 
     
    211197  public function redirect($url, $delay = 0, $statusCode = 302) 
    212198  { 
     199    $url = $this->genUrl($url, true); 
     200 
    213201    $response = $this->context->getResponse(); 
    214202 
     
    219207    $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="%d;url=%s"/></head></html>', $delay, htmlentities($url, ENT_QUOTES, sfConfig::get('sf_charset')))); 
    220208 
     209    if (sfConfig::get('sf_logging_enabled')) 
     210    { 
     211      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Redirect to "%s"', $url)))); 
     212    } 
     213 
    221214    if (!sfConfig::get('sf_test')) 
    222215    { 
  • trunk/lib/exception/sfException.class.php

    r4938 r4951  
    6161    } 
    6262 
    63     if (class_exists('sfMixer', false)) 
    64     { 
    65       foreach (sfMixer::getCallables('sfException:printStackTrace:printStackTrace') as $callable) 
    66       { 
    67         $ret = call_user_func($callable, $this, $exception); 
    68         if ($ret) 
     63    if (sfContext::hasInstance()) 
     64    { 
     65      $dispatcher = sfContext::getInstance()->getEventDispatcher(); 
     66 
     67      if (sfConfig::get('sf_logging_enabled')) 
     68      { 
     69        $dispatcher->notify(new sfEvent($this, 'application.log', array($exception->getMessage(), 'priority' => sfLogger::ERR))); 
     70      } 
     71 
     72      $event = $dispatcher->notifyUntil(new sfEvent($this, 'application.throw_exception', array('exception' => $exception))); 
     73      if ($event->isProcessed()) 
     74      { 
     75        if (!sfConfig::get('sf_test')) 
    6976        { 
    70           if (!sfConfig::get('sf_test')) 
    71           { 
    72             exit(1); 
    73           } 
    74  
    75           return; 
     77          exit(1); 
    7678        } 
    77       } 
    78     } 
    79  
    80     if (sfConfig::get('sf_logging_enabled') && sfContext::hasInstance()) 
    81     { 
    82       sfContext::getInstance()->getLogger()->err(sprintf('{%s} %s', __CLASS__, $exception->getMessage())); 
     79 
     80        return; 
     81      } 
    8382    } 
    8483 
  • trunk/lib/filter/sfCacheFilter.class.php

    r4603 r4951  
    148148        if (sfConfig::get('sf_logging_enabled')) 
    149149        { 
    150           $this->context->getLogger()->info('{sfFilter} ETag matches If-None-Match (send 304)'); 
     150          $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('ETag matches If-None-Match (send 304)'))); 
    151151        } 
    152152      } 
     
    166166        if (sfConfig::get('sf_logging_enabled')) 
    167167        { 
    168           $this->context->getLogger()->info('{sfFilter} Last-Modified matches If-Modified-Since (send 304)'); 
     168          $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Last-Modified matches If-Modified-Since (send 304)'))); 
    169169        } 
    170170      } 
  • trunk/lib/filter/sfExecutionFilter.class.php

    r4606 r4951  
    140140    } 
    141141 
    142     if (!$validated && sfConfig::get('sf_logging_enabled')) 
    143     { 
    144       $this->context->getLogger()->info('{sfFilter} action validation failed'); 
     142    if (sfConfig::get('sf_logging_enabled')) 
     143    { 
     144      $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Action validation failed'))); 
    145145    } 
    146146 
  • trunk/lib/filter/sfFillInFormFilter.class.php

    r4593 r4951  
    6060      if (sfConfig::get('sf_logging_enabled')) 
    6161      { 
    62         $this->context->getLogger()->err(sprintf('{sfFilter} %s', $e->getMessage())); 
     62        $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array($e->getMessage(), 'priority' => sfLogger::ERR))); 
    6363      } 
    6464    } 
  • trunk/lib/filter/sfFilterChain.class.php

    r3244 r4951  
    3737      if (sfConfig::get('sf_logging_enabled')) 
    3838      { 
    39         sfContext::getInstance()->getLogger()->info(sprintf('{sfFilter} executing filter "%s"', get_class($this->chain[$this->index]))); 
     39        sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Executing filter "%s"', get_class($this->chain[$this->index]))))); 
    4040      } 
    4141 
  • trunk/lib/filter/sfRenderingFilter.class.php

    r4593 r4951  
    3535    if (sfConfig::get('sf_logging_enabled')) 
    3636    { 
    37       $this->context->getLogger()->info('{sfFilter} render to client'); 
     37      $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Render to the client'))); 
    3838    } 
    3939 
     
    5050    if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) 
    5151    { 
    52       $logger = $this->context->getLogger(); 
     52      $messages = array(); 
    5353      foreach (sfTimerManager::getTimers() as $name => $timer) 
    5454      { 
    55         $logger->info(sprintf('{sfTimerManager} %s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls())); 
     55        $messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls()); 
    5656      } 
     57 
     58      $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', $messages)); 
    5759    } 
    5860  } 
  • trunk/lib/generator/sfGenerator.class.php

    r4597 r4951  
    3131   * @param sfGeneratorManager A sfGeneratorManager instance 
    3232   */ 
    33   public function initialize($generatorManager) 
     33  public function initialize(sfGeneratorManager $generatorManager) 
    3434  { 
    3535    $this->generatorManager = $generatorManager; 
     
    210210    $this->theme = $theme; 
    211211  } 
    212  
    213   /** 
    214    * Calls methods defined via the sfMixer class. 
    215    * 
    216    * @param string The method name 
    217    * @param array  The method arguments 
    218    * 
    219    * @return mixed The returned value of the called method 
    220    * 
    221    * @see sfMixer 
    222    */ 
    223   public function __call($method, $arguments) 
    224   { 
    225     if (!$callable = sfMixer::getCallable('sfGenerator:'.$method)) 
    226     { 
    227       throw new sfException(sprintf('Call to undefined method sfGenerator::%s.', $method)); 
    228     } 
    229  
    230     array_unshift($arguments, $this); 
    231  
    232     return call_user_func_array($callable, $arguments); 
    233   } 
    234212} 
  • trunk/lib/helper/DebugHelper.php

    r4850 r4951  
    1313  if (sfConfig::get('sf_logging_enabled')) 
    1414  { 
    15     sfContext::getInstance()->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 
     15    sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array($message, 'priority' => constant('sfLogger::'.strtoupper($priority))))); 
    1616  } 
    1717} 
  • trunk/lib/helper/PartialHelper.php

    r4885 r4951  
    159159  if (sfConfig::get('sf_logging_enabled')) 
    160160  { 
    161     $context->getLogger()->info('{PartialHelper} call "'.$moduleName.'->'.$componentToRun.'()'.'"'); 
     161    $context->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array(sprintf('Call "%s->%s()'.'"', $moduleName, $componentToRun)))); 
    162162  } 
    163163 
     
    323323  if (sfConfig::get('sf_logging_enabled')) 
    324324  { 
    325     $context->getLogger()->info(sprintf('{PartialHelper} set slot "%s"', $name)); 
     325    $context->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array(sprintf('Set slot "%s"', $name)))); 
    326326  } 
    327327 
     
    389389  if (sfConfig::get('sf_logging_enabled')) 
    390390  { 
    391     $context->getLogger()->info(sprintf('{PartialHelper} get slot "%s"', $name)); 
     391    $context->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array(sprintf('Get slot "%s"', $name)))); 
    392392  } 
    393393 
     
    423423  if (sfConfig::get('sf_logging_enabled')) 
    424424  { 
    425     $context->getLogger()->info(sprintf('{PartialHelper} get slot "%s"', $name)); 
     425    $context->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array(sprintf('Get slot "%s"', $name)))); 
    426426  } 
    427427 
  • trunk/lib/i18n/sfI18N.class.php

    r4590 r4951  
    3737 
    3838    include(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/i18n.yml')); 
     39 
     40    $context->getEventDispatcher()->connect('user.change_culture', array($this, 'listenToChangeCultureEvent')); 
     41    $context->getEventDispatcher()->connect('controller.change_action', array($this, 'listenToChangeActionEvent')); 
    3942  } 
    4043 
     
    4548   * @param string The culture 
    4649   */ 
    47   public function setMessageSource($dirs, $culture
     50  public function setMessageSource($dirs, $culture = null
    4851  { 
    4952    if (is_null($dirs)) 
     
    6164    } 
    6265 
    63     $this->setCulture($culture); 
     66    if (!is_null($culture)) 
     67    { 
     68      $this->setCulture($culture); 
     69    } 
     70    else 
     71    { 
     72      $this->messageSource->setCulture($this->culture); 
     73    } 
     74 
    6475    $this->messageFormat = null; 
    6576  } 
     
    91102  public function setCulture($culture) 
    92103  { 
     104    $this->culture = $culture; 
     105 
    93106    if ($this->messageSource) 
    94107    { 
    95       $this->culture = $culture; 
    96108      $this->messageSource->setCulture($culture); 
    97109    } 
     
    234246    } 
    235247  } 
     248 
     249  /** 
     250   * Listens to the user.change_culture event. 
     251   * 
     252   * @param sfEvent An sfEvent instance 
     253   * 
     254   */ 
     255  public function listenToChangeCultureEvent(sfEvent $event) 
     256  { 
     257    // change the message format object with the new culture 
     258    $this->setCulture($event->getParameter('culture')); 
     259  } 
     260 
     261  /** 
     262   * Listens to the controller.change_action event. 
     263   * 
     264   * @param sfEvent An sfEvent instance 
     265   * 
     266   */ 
     267  public function listenToChangeActionEvent(sfEvent $event) 
     268  { 
     269    // change message source directory to our module 
     270    $this->setMessageSource(sfLoader::getI18NDirs($event->getParameter('module'))); 
     271  } 
    236272} 
  • trunk/lib/log/sfLogger.class.php

    r4847 r4951  
    7070   * Initializes this sfLogger instance. 
    7171   * 
    72    * @param array An associative array of initialization parameters. 
    73    * 
    7472   * Available options: 
    7573   * 
    7674   * - level: The log level. 
    7775   * 
    78    * @return bool true, if initialization completes successfully, otherwise false. 
    79    * 
    80    * @throws <b>sfInitializationException</b> If an error occurs while initializing this User. 
    81    */ 
    82   public function initialize($parameters = array()) 
    83   { 
    84     if (isset($parameters['level'])) 
    85     { 
    86       $this->setLogLevel($parameters['level']); 
    87     } 
     76   * @param  sfEventDispatcher A sfEventDispatcher instance 
     77   * @param  array        An array of options. 
     78   * 
     79   * @return Boolean      true, if initialization completes successfully, otherwise false. 
     80   * 
     81   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfLogger. 
     82   */ 
     83  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
     84  { 
     85    if (isset($options['level'])) 
     86    { 
     87      $this->setLogLevel($options['level']); 
     88    } 
     89 
     90    $dispatcher->connect('application.log',   array($this, 'listenToLogEvent')); 
    8891  } 
    8992 
     
    215218  { 
    216219    $this->log($message, self::DEBUG); 
     220  } 
     221 
     222  /** 
     223   * Listens to application.log events. 
     224   * 
     225   * @param sfEvent An sfEvent instance 
     226   * 
     227   */ 
     228  public function listenToLogEvent(sfEvent $event) 
     229  { 
     230    $priority = $event->getParameterHolder()->remove('priority'); 
     231    if (!$priority) 
     232    { 
     233      $priority = self::INFO; 
     234    } 
     235    $subject = $event->getSubject(); 
     236    $subject = is_object($subject) ? get_class($subject) : (is_string($subject) ? $subject : 'main'); 
     237    foreach ($event->getParameterHolder()->getAll() as $message) 
     238    { 
     239      $this->log(sprintf('{%s} %s', $subject, $message), $priority); 
     240    } 
    217241  } 
    218242 
  • trunk/lib/log/sfLogger/sfAggregateLogger.class.php

    r4845 r4951  
    2929   * - loggers: Logger objects that extends sfLogger. 
    3030   * 
    31    * @param array Options for the logger 
     31   * @param  sfEventDispatcher A sfEventDispatcher instance 
     32   * @param  array        An array of options. 
     33   * 
     34   * @return Boolean      true, if initialization completes successfully, otherwise false. 
    3235   */ 
    33   public function initialize($options = array()) 
     36  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
    3437  { 
    3538    if (isset($options['loggers'])) 
     
    4346    } 
    4447 
    45     return parent::initialize($options); 
     48    return parent::initialize($dispatcher, $options); 
    4649  } 
    4750 
  • trunk/lib/log/sfLogger/sfFileLogger.class.php

    r4845 r4951  
    3030   *         You can use any support php wrapper. To write logs to the Apache error log, use php://stderr 
    3131   * 
    32    * @param array Options for the logger 
     32   * @param  sfEventDispatcher A sfEventDispatcher instance 
     33   * @param  array        An array of options. 
     34   * 
     35   * @return Boolean      true, if initialization completes successfully, otherwise false. 
    3336   */ 
    34   public function initialize($options = array()) 
     37  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
    3538  { 
    3639    if (!isset($options['file'])) 
     
    5255    $this->fp = fopen($options['file'], 'a'); 
    5356 
    54     return parent::initialize($options); 
     57    return parent::initialize($dispatcher, $options); 
    5558  } 
    5659 
  • trunk/lib/log/sfLogger/sfNoLogger.class.php

    r4845 r4951  
    2020{ 
    2121  /** 
     22   * Initializes this logger. 
     23   * 
     24   * @param  sfEventDispatcher A sfEventDispatcher instance 
     25   * @param  array        An array of options. 
     26   * 
     27   * @return Boolean      true, if initialization completes successfully, otherwise false. 
     28   */ 
     29  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
     30  { 
     31  } 
     32 
     33  /** 
    2234   * Logs a message. 
    2335   * 
  • trunk/lib/log/sfLogger/sfWebDebugLogger.class.php

    r4850 r4951  
    2727   * Initializes this logger. 
    2828   * 
    29    * @param array Logger options 
     29   * @param  sfEventDispatcher A sfEventDispatcher instance 
     30   * @param  array        An array of options. 
     31   * 
     32   * @return Boolean      true, if initialization completes successfully, otherwise false. 
    3033   */ 
    31   public function initialize($options = array()) 
     34  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
    3235  { 
    3336    if (!sfConfig::get('sf_web_debug')) 
     
    3942    $this->context = sfContext::getInstance(); 
    4043 
    41     return parent::initialize($options); 
     44    return parent::initialize($dispatcher, $options); 
    4245  } 
    4346 
  • trunk/lib/request/sfConsoleRequest.class.php

    r4895 r4951  
    2323   * Initializes this sfRequest. 
    2424   * 
    25    * @param sfLogger  A sfLogger instance (can be null) 
    26    * @param sfRouting A sfRouting instance (can be null) 
    27    * @param array     An associative array of initialization parameters 
    28    * @param array     An associative array of initialization attributes 
     25   * @param sfEventDispatcher  A sfEventDispatcher instance 
     26   * @param array         An associative array of initialization parameters 
     27   * @param array         An associative array of initialization attributes 
    2928   * 
    30    * @return Boolean true, if initialization completes successfully, otherwise false 
     29   * @return Boolean      true, if initialization completes successfully, otherwise false 
    3130   * 
    32    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
     31   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRequest 
    3332   */ 
    34   public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
     33  public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array()) 
    3534  { 
    36     parent::initialize($logger, $routing, $parameters, $attributes); 
     35    parent::initialize($dispatcher, $parameters, $attributes); 
    3736 
    3837    $this->getParameterHolder()->add($_SERVER['argv']); 
  • trunk/lib/request/sfRequest.class.php

    r4895 r4951  
    6161  protected 
    6262    $errors          = array(), 
    63     $logger          = null, 
    64     $routing         = null, 
     63    $dispatcher      = null, 
    6564    $method          = null, 
    6665    $parameterHolder = null, 
     
    7170   * Initializes this sfRequest. 
    7271   * 
    73    * @param  sfLogger  A sfLogger instance (can be null) 
    74    * @param  sfRouting A sfRouting instance (can be null) 
    75    * @param  array     An associative array of initialization parameters 
    76    * @param  array     An associative array of initialization attributes 
    77    * 
    78    * @return Boolean   true, if initialization completes successfully, otherwise false 
    79    * 
    80    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
    81    */ 
    82   public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
    83   { 
    84     $this->logger  = $logger; 
    85     $this->routing = $routing; 
     72   * @param  sfEventDispatcher  A sfEventDispatcher instance 
     73   * @param  array              An associative array of initialization parameters 
     74   * @param  array              An associative array of initialization attributes 
     75   * 
     76   * @return Boolean            true, if initialization completes successfully, otherwise false 
     77   * 
     78   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRequest 
     79   */ 
     80  public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array()) 
     81  { 
     82    $this->dispatcher = $dispatcher; 
    8683 
    8784    // initialize parameter and attribute holders 
     
    235232  public function setError($name, $message) 
    236233  { 
    237     if (!is_null($this->logger)) 
    238     { 
    239       $this->logger->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")'); 
     234    if (sfConfig::get('sf_logging_enabled')) 
     235    { 
     236      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Error in form for parameter "%s" (with message "%s")', $name, $message)))); 
    240237    } 
    241238 
     
    386383 
    387384  /** 
    388    * Overloads a given method
    389    * 
    390    * @param string Method name 
    391    * @param string Method arguments 
    392    * 
    393    * @return mixed User function callback 
     385   * Calls methods defined via sfEventDispatcher
     386   * 
     387   * @param string The method name 
     388   * @param array  The method arguments 
     389   * 
     390   * @return mixed The returned value of the called method 
    394391   * 
    395392   * @throws <b>sfException</b> if call fails 
     
    397394  public function __call($method, $arguments) 
    398395  { 
    399     if (!$callable = sfMixer::getCallable('sfRequest:'.$method)) 
     396    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'request.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     397    if (!$event->isProcessed()) 
    400398    { 
    401399      throw new sfException(sprintf('Call to undefined method sfRequest::%s.', $method)); 
    402400    } 
    403401 
    404     array_unshift($arguments, $this); 
    405  
    406     return call_user_func_array($callable, $arguments); 
     402    return $event->getReturnValue(); 
    407403  } 
    408404} 
  • trunk/lib/request/sfWebRequest.class.php

    r4895 r4951  
    1414 * 
    1515 * This class manages web requests. It parses input from the request and store them as parameters. 
    16  * sfWebRequest is able to parse request with routing support enabled. 
    1716 * 
    1817 * @package    symfony 
     
    3231    $getParameters          = null, 
    3332    $postParameters         = null, 
    34     $routingParameters      = null; 
     33    $requestParameters      = null; 
    3534 
    3635  /** 
    3736   * Initializes this sfRequest. 
    3837   * 
    39    * @param  sfLogger  A sfLogger instance (can be null) 
    40    * @param  sfRouting A sfRouting instance (can be null) 
    41    * @param  array     An associative array of initialization parameters 
    42    * @param  array     An associative array of initialization attributes 
    43    * 
    44    * @return Boolean   true, if initialization completes successfully, otherwise false 
    45    * 
    46    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
    47    */ 
    48   public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
    49   { 
    50     parent::initialize($logger, $routing, $parameters, $attributes); 
     38   * @param  sfEventDispatcher  A sfEventDispatcher instance 
     39   * @param  array         An associative array of initialization parameters 
     40   * @param  array         An associative array of initialization attributes 
     41   * 
     42   * @return Boolean       true, if initialization completes successfully, otherwise false 
     43   * 
     44   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRequest 
     45   */ 
     46  public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array()) 
     47  { 
     48    parent::initialize($dispatcher, $parameters, $attributes); 
    5149 
    5250    if (isset($_SERVER['REQUEST_METHOD'])) 
     
    431429  } 
    432430 
    433   public function getRoutingParameters() 
    434   { 
    435     return $this->routingParameters; 
     431  public function getRequestParameters() 
     432  { 
     433    return $this->requestParameters; 
    436434  } 
    437435 
     
    780778  } 
    781779 
    782   protected function parseRoutingParameters() 
    783   { 
    784     if (is_null($this->routing)) 
    785     { 
    786       return; 
    787     } 
    788  
    789     $parameters = $this->routing->parse($this->getPathInfo()); 
    790     if (!is_null($parameters)) 
    791     { 
    792       if (!isset($parameters['module'])) 
    793       { 
    794         $parameters['module'] = sfConfig::get('sf_default_module', 'default'); 
    795       } 
    796  
    797       if (!isset($parameters['action'])) 
    798       { 
    799         $parameters['action'] = sfConfig::get('sf_default_action', 'index'); 
    800       } 
    801     } 
    802     else 
     780  protected function parseRequestParameters() 
     781  { 
     782    $parameters = array(); 
     783 
     784    try 
     785    { 
     786      $parameters = $this->dispatcher->filter(new sfEvent($this, 'request.load_parameters', array('path_info' => $this->getPathInfo())), $parameters)->getReturnValue(); 
     787    } 
     788    catch (sfError404Exception $e) 
    803789    { 
    804790      $parameters['module'] = sfConfig::get('sf_error_404_module', 'default'); 
     
    806792    } 
    807793 
    808     $this->routingParameters = $parameters; 
     794    if (!isset($parameters['module'])) 
     795    { 
     796      $parameters['module'] = sfConfig::get('sf_default_module', 'default'); 
     797    } 
     798 
     799    if (!isset($parameters['action'])) 
     800    { 
     801      $parameters['action'] = sfConfig::get('sf_default_action', 'index'); 
     802    } 
     803 
     804    $this->requestParameters = $parameters; 
    809805  } 
    810806 
     
    819815    $this->parameterHolder->add($this->getParameters); 
    820816 
    821     // routing parameters 
    822     $this->parseRoutingParameters(); 
    823     $this->parameterHolder->add($this->routingParameters); 
     817    // additional parameters 
     818    $this->parseRequestParameters(); 
     819    $this->parameterHolder->add($this->requestParameters); 
    824820 
    825821    // POST parameters 
     
    837833    } 
    838834 
    839     if (!is_null($this->logger)) 
    840     { 
    841       $this->logger->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 
     835    if (sfConfig::get('sf_logging_enabled')) 
     836    { 
     837      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))))); 
    842838    } 
    843839  } 
  • trunk/lib/response/sfResponse.class.php

    r4895 r4951  
    2222  protected 
    2323    $parameterHolder = null, 
    24     $logger          = null, 
     24    $dispatcher      = null, 
    2525    $content         = ''; 
    2626 
     
    2828   * Initializes this sfResponse. 
    2929   * 
    30    * @param  sfLogger  A sfLogger instance (can be null) 
     30   * @param  sfEventDispatcher  A sfEventDispatcher instance 
     31   * @param  array         An array of parameters 
    3132   * 
    32    * @return Boolean   true, if initialization completes successfully, otherwise false 
     33   * @return Boolean       true, if initialization completes successfully, otherwise false 
    3334   * 
    34    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 
     35   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfResponse 
    3536   */ 
    36   public function initialize(sfLogger $logger = null, $parameters = array()) 
     37  public function initialize(sfEventDispatcher $dispatcher, $parameters = array()) 
    3738  { 
    38     $this->logger = $logger; 
     39    $this->dispatcher = $dispatcher; 
    3940 
    4041    $this->parameterHolder = new sfParameterHolder(); 
     
    8889  public function sendContent() 
    8990  { 
    90     if (!is_null($this->logger)) 
     91    if (sfConfig::get('sf_logging_enabled')) 
    9192    { 
    92       $this->logger->info('{sfResponse} send content ('.strlen($this->getContent()).' o)'); 
     93      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($this->getContent()))))); 
    9394    } 
    9495 
     
    146147 
    147148  /** 
    148    * Overloads a given method
     149   * Calls methods defined via sfEventDispatcher
    149150   * 
    150    * @param string Method name 
    151    * @param string Method arguments 
     151   * @param string The method name 
     152   * @param array  The method arguments 
    152153   * 
    153    * @return mixed User function callback 
     154   * @return mixed The returned value of the called method 
    154155   * 
    155156   * @throws <b>sfException</b> If the calls fails 
     
    157158  public function __call($method, $arguments) 
    158159  { 
    159     if (!$callable = sfMixer::getCallable('sfResponse:'.$method)) 
     160    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'response.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     161    if (!$event->isProcessed()) 
    160162    { 
    161163      throw new sfException(sprintf('Call to undefined method sfResponse::%s.', $method)); 
    162164    } 
    163165 
    164     array_unshift($arguments, $this); 
    165  
    166     return call_user_func_array($callable, $arguments); 
     166    return $event->getReturnValue(); 
    167167  } 
    168168} 
  • trunk/lib/response/sfWebResponse.class.php

    r4895 r4951  
    3131   * Initializes this sfWebResponse. 
    3232   * 
    33    * @param  sfLogger  A sfLogger instance (can be null) 
    34    * 
    35    * @return Boolean   true, if initialization completes successfully, otherwise false 
    36    * 
    37    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 
    38    */ 
    39   public function initialize(sfLogger $logger = null, $parameters = array()) 
    40   { 
    41     parent::initialize($logger, $parameters); 
     33   * @param  sfEventDispatcher  A sfEventDispatcher instance 
     34   * @param  array         An array of parameters 
     35   * 
     36   * @return Boolean       true, if initialization completes successfully, otherwise false 
     37   * 
     38   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfResponse 
     39   */ 
     40  public function initialize(sfEventDispatcher $dispatcher, $parameters = array()) 
     41  { 
     42    parent::initialize($dispatcher, $parameters); 
     43 
     44    $this->dispatcher->connect('controller.change_action', array($this, 'listenToChangeActionEvent')); 
    4245 
    4346    $this->statusTexts = array( 
     
    266269    header($status); 
    267270 
    268     if (!is_null($this->logger)) 
    269     { 
    270       $this->logger->info('{sfResponse} send status "'.$status.'"'); 
     271    if (sfConfig::get('sf_logging_enabled')) 
     272    { 
     273      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send status "%s"', $status)))); 
    271274    } 
    272275 
     
    276279      header($name.': '.$value); 
    277280 
    278       if (!is_null($this->logger) && $value != ''
    279       { 
    280         $this->logger->info('{sfResponse} send header "'.$name.'": "'.$value.'"'); 
     281      if ($value != '' && sfConfig::get('sf_logging_enabled')
     282      { 
     283        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send header "%s": "%s"', $name, $value)))); 
    281284      } 
    282285    } 
     
    294297      } 
    295298 
    296       if (!is_null($this->logger)) 
    297       { 
    298         $this->logger->info('{sfResponse} send cookie "'.$cookie['name'].'": "'.$cookie['value'].'"'); 
     299      if (sfConfig::get('sf_logging_enabled')) 
     300      { 
     301        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send cookie "%s": "%s"', $cookie['name'], $cookie['value'])))); 
    299302      } 
    300303    } 
     
    311314      parent::sendContent(); 
    312315    } 
     316  } 
     317 
     318  /** 
     319   * Sends the HTTP headers and the content. 
     320   */ 
     321  final public function send() 
     322  { 
     323    $this->sendHttpHeaders(); 
     324    $this->sendContent(); 
    313325  } 
    314326 
     
    623635    $data = unserialize($serialized); 
    624636 
    625     $this->initialize(); 
     637    $this->initialize(sfContext::hasInstance() ? sfContext::getInstance()->getEventDispatcher() : new sfEventDispatcher()); 
    626638 
    627639    $this->content         = $data[0]; 
     
    632644    $this->headerOnly      = $data[5]; 
    633645  } 
     646 
     647  /** 
     648   * Listens to the controller.change_action event. 
     649   * 
     650   * @param sfEvent An sfEvent instance 
     651   * 
     652   */ 
     653  public function listenToChangeActionEvent(sfEvent $event) 
     654  { 
     655    $moduleName = $event->getParameter('module'); 
     656    $actionName = $event->getParameter('action'); 
     657 
     658    if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action')) 
     659    { 
     660      $this->setStatusCode(404); 
     661      $this->setHttpHeader('Status', '404 Not Found'); 
     662 
     663      $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', array('module' => $moduleName, 'action' => $actionName))); 
     664    } 
     665  } 
    634666} 
  • trunk/lib/routing/sfPatternRouting.class.php

    r4899 r4951  
    3333   * Initialize this Routing. 
    3434   * 
    35    * @param sfLogger A sfLogger instance (or null) 
    36    * @param array An associative array of initialization parameters. 
    37    * 
    38    * @return bool true, if initialization completes successfully, otherwise false. 
    39    * 
    40    * @throws <b>sfInitializationException</b> If an error occurs while initializing this User
    41    */ 
    42   public function initialize(sfLogger $logger = null, $parameters = array()) 
    43   { 
    44     parent::initialize($logger, $parameters); 
     35   * @param sfEventDispatcher A sfEventDispatcher instance 
     36   * @param array        An associative array of initialization parameters. 
     37   * 
     38   * @return Boolean      true, if initialization completes successfully, otherwise false. 
     39   * 
     40   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRouting
     41   */ 
     42  public function initialize(sfEventDispatcher $dispatcher, $parameters = array()) 
     43  { 
     44    parent::initialize($dispatcher, $parameters); 
    4545 
    4646    $this->setDefaultSuffix($this->parameterHolder->get('suffix')); 
     
    166166  public function clearRoutes() 
    167167  { 
    168     if (!is_null($this->logger)) 
    169     { 
    170       $this->logger->info('{sfRouting} clear all current routes'); 
     168    if (sfConfig::get('sf_logging_enabled')) 
     169    { 
     170      $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Clear all current routes'))); 
    171171    } 
    172172 
     
    327327    } 
    328328 
    329     if (!is_null($this->logger)) 
    330     { 
    331       $this->logger->info(sprintf('{sfRouting} connect "%s"%s', $route, $suffix ? ' ("'.$suffix.'" suffix)' : '')); 
     329    if (sfConfig::get('sf_logging_enabled')) 
     330    { 
     331      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Connect "%s"%s', $route, $suffix ? ' ("'.$suffix.'" suffix)' : '')))); 
    332332    } 
    333333 
     
    575575          $this->currentInternalUri = null; 
    576576 
    577           if (!is_null($this->logger)) 
    578           { 
    579             $this->logger->info(sprintf('{sfRouting} match route [%s] "%s"', $routeName, $route)); 
     577          if (sfConfig::get('sf_logging_enabled')) 
     578          { 
     579            $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Match route [%s] "%s"', $routeName, $route)))); 
    580580          } 
    581581 
     
    584584      } 
    585585    } 
    586  
    587     $this->currentRouteParameters = $out; 
    588586 
    589587    // no route found 
    590588    if (!$break) 
    591589    { 
    592       if (!is_null($this->logger)) 
    593       { 
    594         $this->logger->info('{sfRouting} no matching route found'); 
     590      if (sfConfig::get('sf_logging_enabled')) 
     591      { 
     592        $this->dispatcher->notify(new sfEvent($this, 'application.log', array('No matching route found'))); 
    595593      } 
    596594 
    597595      $this->currentRouteParameters = null; 
    598     } 
     596 
     597      throw new sfError404Exception('No matching route found'); 
     598    } 
     599 
     600    $this->currentRouteParameters = $out; 
    599601 
    600602    return $this->currentRouteParameters; 
  • trunk/lib/routing/sfRouting.class.php

    r4892 r4951  
    2020{ 
    2121  protected 
    22     $logger            = null, 
     22    $dispatcher        = null, 
    2323    $defaultParameters = array(), 
    2424    $parameterHolder   = null; 
     
    3131   * @return sfRouting A sfRouting implementation instance. 
    3232   * 
    33    * @throws <b>sfFactoryException</b> If a routing implementation instance cannot 
     33   * @throws <b>sfFactoryException</b> If a routing implementation instance cannot be created 
    3434   */ 
    3535  public static function newInstance($class) 
    3636  { 
    37     // the class exists 
    3837    $object = new $class(); 
    3938 
     
    4948   * Initializes this sfRouting instance. 
    5049   * 
    51    * @param sfLogger A sfLogger instance (or null) 
    52    * @param array    An associative array of initialization parameters. 
     50   * @param sfEventDispatcher A sfEventDispatcher instance 
     51   * @param array        An associative array of initialization parameters. 
    5352   * 
    54    * @return bool    true, if initialization completes successfully, otherwise false. 
     53   * @return Boolean     true, if initialization completes successfully, otherwise false. 
    5554   * 
    56    * @throws <b>sfInitializationException</b> If an error occurs while initializing this User
     55   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfRouting
    5756   */ 
    58   public function initialize(sfLogger $logger = null, $parameters = array()) 
     57  public function initialize(sfEventDispatcher $dispatcher, $parameters = array()) 
    5958  { 
    60     $this->logger = $logger; 
     59    $this->dispatcher = $dispatcher; 
    6160 
    6261    if (!isset($parameters['default_module'])) 
     
    7271    $this->parameterHolder = new sfParameterHolder(); 
    7372    $this->parameterHolder->add($parameters); 
     73 
     74    $this->dispatcher->connect('user.change_culture', array($this, 'listenToChangeCultureEvent')); 
     75    $this->dispatcher->connect('request.load_parameters', array($this, 'listenToLoadParametersInfoEvent')); 
    7476  } 
    7577 
     
    131133  * 
    132134  * @return array  An array of parameters 
     135  * 
     136  * @throws sfError404Exception if the url is not parseable by the sfRouting object 
    133137  */ 
    134138  abstract public function parse($url); 
     
    156160 
    157161  /** 
     162   * Listens to the user.change_culture event. 
     163   * 
     164   * @param sfEvent An sfEvent instance 
     165   * 
     166   */ 
     167  public function listenToChangeCultureEvent(sfEvent $event) 
     168  { 
     169    // change the culture in the routing default parameters 
     170    $this->setDefaultParameter('sf_culture', $event->getParameter('culture')); 
     171  } 
     172 
     173  /** 
     174   * Listens to the request.load_parameters event. 
     175   * 
     176   * @param sfEvent An sfEvent instance 
     177   * 
     178   */ 
     179  public function listenToLoadParametersInfoEvent(sfEvent $event, $parameters) 
     180  { 
     181    return array_merge($parameters, $this->parse($event->getParameter('path_info'))); 
     182  } 
     183 
     184  /** 
    158185   * Execute the shutdown procedure. 
    159186   * 
  • trunk/lib/user/sfBasicSecurityUser.class.php

    r4593 r4951  
    6565          if (sfConfig::get('sf_logging_enabled')) 
    6666          { 
    67             $this->context->getLogger()->info('{sfUser} remove credential "'.$credential.'"'); 
     67            $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove credential "%s"', $credential)))); 
    6868          } 
    6969 
     
    9999    if (sfConfig::get('sf_logging_enabled')) 
    100100    { 
    101       $this->context->getLogger()->info('{sfUser} add credential(s) "'.implode(', ', $credentials).'"'); 
     101      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Add credential(s) "%s"', implode(', ', $credentials))))); 
    102102    } 
    103103 
     
    174174    if (sfConfig::get('sf_logging_enabled')) 
    175175    { 
    176       $this->context->getLogger()->info('{sfUser} user is '.($authenticated === true ? '' : 'not ').'authenticated'); 
     176      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('User is %sauthenticated', $authenticated === true ? '' : 'not ')))); 
    177177    } 
    178178 
     
    208208  } 
    209209 
    210   public function initialize($context, $parameters = null) 
     210  /** 
     211   * Initializes this sfUser. 
     212   * 
     213   * @param sfEventDispatcher A sfEventDispatcher instance. 
     214   * @param sfStorage    A sfStorage instance. 
     215   * @param array        An associative array of initialization parameters. 
     216   * 
     217   * @return Boolean     true, if initialization completes successfully, otherwise false. 
     218   * 
     219   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfUser. 
     220   */ 
     221  public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $parameters = array()) 
    211222  { 
    212223    // initialize parent 
    213     parent::initialize($context, $parameters); 
     224    parent::initialize($dispatcher, $storage, $parameters); 
    214225 
    215226    // read data from storage 
    216     $storage = $this->context->getStorage(); 
    217  
    218227    $this->authenticated = $storage->read(self::AUTH_NAMESPACE); 
    219228    $this->credentials   = $storage->read(self::CREDENTIAL_NAMESPACE); 
     
    231240      if (sfConfig::get('sf_logging_enabled')) 
    232241      { 
    233         $this->context->getLogger()->info('{sfUser} automatic user logout'); 
    234       } 
     242        $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Automatic user logout'))); 
     243      } 
     244 
    235245      $this->setTimedOut(); 
    236246      $this->clearCredentials(); 
     
    243253  public function shutdown() 
    244254  { 
    245     $storage = $this->context->getStorage(); 
    246  
    247255    // write the last request time to the storage 
    248     $storage->write(self::LAST_REQUEST_NAMESPACE, $this->lastRequest); 
    249  
    250     $storage->write(self::AUTH_NAMESPACE,         $this->authenticated); 
    251     $storage->write(self::CREDENTIAL_NAMESPACE,   $this->credentials); 
     256    $this->storage->write(self::LAST_REQUEST_NAMESPACE, $this->lastRequest); 
     257 
     258    $this->storage->write(self::AUTH_NAMESPACE,         $this->authenticated); 
     259    $this->storage->write(self::CREDENTIAL_NAMESPACE,   $this->credentials); 
    252260 
    253261    // call the parent shutdown method 
  • trunk/lib/user/sfUser.class.php

    r4934 r4951  
    3636    $attributeHolder = null, 
    3737    $culture         = null, 
    38     $context         = null; 
    39  
    40   /** 
    41    * Retrieve the current application context. 
    42    * 
    43    * @return Context A Context instance. 
    44    */ 
    45   public function getContext() 
    46   { 
    47     return $this->context; 
    48   } 
    49  
    50   /** 
    51    * Initialize this User. 
    52    * 
    53    * @param sfContext A sfContext instance. 
    54    * @param array     An associative array of initialization parameters. 
    55    * 
    56    * @return Boolean  true, if initialization completes successfully, otherwise false. 
     38    $storage         = null, 
     39    $dispatcher      = null; 
     40 
     41  /** 
     42   * Initializes this sfUser. 
     43   * 
     44   * @param sfEventDispatcher A sfEventDispatcher instance. 
     45   * @param sfStorage    A sfStorage instance. 
     46   * @param array        An associative array of initialization parameters. 
     47   * 
     48   * @return Boolean     true, if initialization completes successfully, otherwise false. 
    5749   * 
    5850   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfUser. 
    5951   */ 
    60   public function initialize($context, $parameters = array()) 
    61   { 
    62     $this->context = $context; 
     52  public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $parameters = array()) 
     53  { 
     54    $this->dispatcher = $dispatcher; 
     55    $this->storage    = $storage; 
    6356 
    6457    $this->parameterHolder = new sfParameterHolder(); 
     
    6861 
    6962    // read attributes from storage 
    70     $attributes = $context->getStorage()->read(self::ATTRIBUTE_NAMESPACE); 
     63    $attributes = $storage->read(self::ATTRIBUTE_NAMESPACE); 
    7164    if (is_array($attributes)) 
    7265    { 
     
    8174    //  - use the culture defined in the user session 
    8275    //  - use the default culture set in i18n.yml 
    83     if (!($culture = $context->getRequest()->getParameter('sf_culture'))) 
    84     { 
    85       if (null === ($culture = $context->getStorage()->read(self::CULTURE_NAMESPACE))) 
    86       { 
    87         $culture = sfConfig::get('sf_i18n_default_culture', 'en'); 
    88       } 
    89     } 
     76    $currentCulture = $storage->read(self::CULTURE_NAMESPACE); 
     77    $culture = $this->parameterHolder->get('culture', !is_null($currentCulture) ? $currentCulture : $this->parameterHolder->get('default_culture', 'en')); 
    9078 
    9179    $this->setCulture($culture); 
     
    9684      if (sfConfig::get('sf_logging_enabled')) 
    9785      { 
    98         $this->context->getLogger()->info(sprintf('{sfUser} flag old flash messages ("%s")', implode('", "', $names))); 
     86        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names))))); 
    9987      } 
    10088 
     
    138126      $this->culture = $culture; 
    139127 
    140       // change the message format object with the new culture 
    141       if (sfConfig::get('sf_i18n')) 
    142       { 
    143         $this->context->getI18N()->setCulture($culture); 
    144       } 
    145  
    146       // change the culture in the routing default parameters 
    147       $this->context->getRouting()->setDefaultParameter('sf_culture', $culture); 
     128      $this->dispatcher->notify(new sfEvent($this, 'user.change_culture', array('culture' => $culture))); 
    148129    } 
    149130  } 
     
    272253      if (sfConfig::get('sf_logging_enabled')) 
    273254      { 
    274         $this->context->getLogger()->info(sprintf('{sfUser} remove old flash messages ("%s")', implode('", "', $names))); 
     255        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove old flash messages ("%s")', implode('", "', $names))))); 
    275256      } 
    276257 
     
    282263    } 
    283264 
    284     $storage = $this->context->getStorage(); 
    285  
    286265    $attributes = array(); 
    287266    foreach ($this->attributeHolder->getNamespaces() as $namespace) 
     
    291270 
    292271    // write attributes to the storage 
    293     $storage->write(self::ATTRIBUTE_NAMESPACE, $attributes); 
     272    $this->storage->write(self::ATTRIBUTE_NAMESPACE, $attributes); 
    294273 
    295274    // write culture to the storage 
    296     $storage->write(self::CULTURE_NAMESPACE, $this->culture); 
     275    $this->storage->write(self::CULTURE_NAMESPACE, $this->culture); 
    297276 
    298277    session_write_close(); 
    299278  } 
    300279 
     280  /** 
     281   * Calls methods defined via sfEventDispatcher. 
     282   * 
     283   * @param string The method name 
     284   * @param array  The method arguments 
     285   * 
     286   * @return mixed The returned value of the called method 
     287   * 
     288   * @throws <b>sfException</b> If the calls fails 
     289   */ 
    301290  public function __call($method, $arguments) 
    302291  { 
    303     if (!$callable = sfMixer::getCallable('sfUser:'.$method)) 
     292    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'user.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     293    if (!$event->isProcessed()) 
    304294    { 
    305295      throw new sfException(sprintf('Call to undefined method sfUser::%s.', $method)); 
    306296    } 
    307297 
    308     array_unshift($arguments, $this); 
    309  
    310     return call_user_func_array($callable, $arguments); 
     298    return $event->getReturnValue(); 
    311299  } 
    312300} 
  • trunk/lib/util/sfContext.class.php

    r4895 r4951  
    2424{ 
    2525  protected 
    26     $factories = array(); 
     26    $dispatcher = null, 
     27    $factories  = array(); 
    2728 
    2829  protected static 
     
    3536  public function initialize() 
    3637  { 
     38    $this->dispatcher = new sfEventDispatcher(); 
     39 
    3740    if (sfConfig::get('sf_use_database')) 
    3841    { 
     
    99102  { 
    100103    self::$current = $name; 
     104  } 
     105 
     106  /** 
     107   * Retrieves the current event dispatcher. 
     108   * 
     109   * @return sfEventDispatcher A sfEventDispatcher instance 
     110   */ 
     111  public function getEventDispatcher() 
     112  { 
     113    return $this->dispatcher; 
    101114  } 
    102115 
  • trunk/lib/validator/sfValidatorManager.class.php

    r4283 r4951  
    4747    if (sfConfig::get('sf_logging_enabled')) 
    4848    { 
    49       sfContext::getInstance()->getLogger()->info('{sfValidator} validation execution'); 
     49      sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Validation execution'))); 
    5050    } 
    5151 
  • trunk/lib/view/sfMailView.class.php

    r4906 r4951  
    8282    if (sfConfig::get('sf_logging_enabled')) 
    8383    { 
    84       $this->context->getLogger()->info('{sfMailView} send email to client'); 
     84      $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Send email to client'))); 
    8585    } 
    8686 
  • trunk/lib/view/sfPHPView.class.php

    r4906 r4951  
    5858    if (sfConfig::get('sf_logging_enabled')) 
    5959    { 
    60       $this->context->getLogger()->info(sprintf('{sfView} render "%s"', $_sfFile)); 
     60      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $_sfFile)))); 
    6161    } 
    6262 
     
    121121    if (sfConfig::get('sf_logging_enabled')) 
    122122    { 
    123       $this->context->getLogger()->info(sprintf('{sfView} decorate content with "%s"', $this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate())); 
     123      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Decorate content with "%s/%s"', $this->getDecoratorDirectory(), $this->getDecoratorTemplate())))); 
    124124    } 
    125125 
  • trunk/lib/view/sfView.class.php

    r4933 r4951  
    7171  protected 
    7272    $context            = null, 
     73    $dispatcher         = null, 
    7374    $decorator          = false, 
    7475    $decoratorDirectory = null, 
     
    9596 
    9697  /** 
    97    * Retrieves the current application context. 
    98    * 
    99    * @return sfContext The current sfContext instance 
    100    */ 
    101   public final function getContext() 
    102   { 
    103     return $this->context; 
    104   } 
    105  
    106   /** 
    10798   * Retrieves this views decorator template directory. 
    10899   * 
     
    165156  public function initialize($context, $moduleName, $actionName, $viewName) 
    166157  { 
    167     if (sfConfig::get('sf_logging_enabled')) 
    168     { 
    169       $context->getLogger()->info(sprintf('{sfView} initialize view for "%s/%s"', $moduleName, $actionName)); 
    170     } 
    171  
    172158    $this->moduleName = $moduleName; 
    173159    $this->actionName = $actionName; 
    174160    $this->viewName   = $viewName; 
    175161 
    176     $this->context = $context; 
     162    $this->context    = $context; 
     163    $this->dispatcher = $context->getEventDispatcher(); 
     164 
     165    if (sfConfig::get('sf_logging_enabled')) 
     166    { 
     167      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Initialize view for "%s/%s"', $moduleName, $actionName)))); 
     168    } 
    177169 
    178170    $this->attributeHolder = false === sfConfig::get('sf_escaping_method') ? new sfViewParameterHolder() : new sfEscapedViewParameterHolder(); 
     
    478470 
    479471  /** 
    480    * Overloads a given method 
    481    * 
    482    * @param string Method name 
    483    * @param string Method arguments 
    484    * 
    485    * @return mixed User function callback 
    486    * 
    487    * @throws <b>sfException</b> If the call fails 
     472   * Calls methods defined via sfEventDispatcher. 
     473   * 
     474   * @param string The method name 
     475   * @param array  The method arguments 
     476   * 
     477   * @return mixed The returned value of the called method 
     478   * 
     479   * @throws <b>sfException</b> If the calls fails 
    488480   */ 
    489481  public function __call($method, $arguments) 
    490482  { 
    491     if (!$callable = sfMixer::getCallable('sfView:'.$method)) 
     483    $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'view.method_not_found', array('method' => $method, 'arguments' => $arguments))); 
     484    if (!$event->isProcessed()) 
    492485    { 
    493486      throw new sfException(sprintf('Call to undefined method sfView::%s.', $method)); 
    494487    } 
    495488 
    496     array_unshift($arguments, $this); 
    497  
    498     return call_user_func_array($callable, $arguments); 
     489    return $event->getReturnValue(); 
    499490  } 
    500491} 
  • trunk/lib/view/sfViewCacheManager.class.php

    r4885 r4951  
    2727    $cacheConfig = array(), 
    2828    $context     = null, 
     29    $dispatcher  = null, 
    2930    $controller  = null, 
    3031    $routing     = null, 
     
    4041  { 
    4142    $this->context    = $context; 
     43    $this->dispatcher = $context->getEventDispatcher(); 
    4244    $this->controller = $context->getController(); 
    4345 
     
    315317    if (sfConfig::get('sf_logging_enabled')) 
    316318    { 
    317       $this->context->getLogger()->info(sprintf('{sfViewCacheManager} cache for "%s" %s', $internalUri, $retval !== null ? 'exists' : 'does not exist')); 
     319      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Cache for "%s" %s', $internalUri, $retval !== null ? 'exists' : 'does not exist')))); 
    318320    } 
    319321 
     
    350352      if (sfConfig::get('sf_logging_enabled')) 
    351353      { 
    352         $this->context->getLogger()->info('{sfViewCacheManager} discard cache'); 
     354        $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Discard cache'))); 
    353355      } 
    354356 
     
    385387    if (sfConfig::get('sf_logging_enabled')) 
    386388    { 
    387       $this->context->getLogger()->info(sprintf('{sfViewCacheManager} save cache for "%s"', $internalUri)); 
     389      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Save cache for "%s"', $internalUri)))); 
    388390    } 
    389391 
     
    402404    if (sfConfig::get('sf_logging_enabled')) 
    403405    { 
    404       $this->context->getLogger()->info(sprintf('{sfViewCacheManager} remove cache for "%s"', $internalUri)); 
     406      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove cache for "%s"', $internalUri)))); 
    405407    } 
    406408 
  • trunk/test/unit/action/sfComponentTest.php

    r4892 r4951  
    5252$t->is($component->foo, array('bar'), '__set() populates component variables'); 
    5353 
    54 // mixins 
    55 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    56 $mixert = new sfMixerTest($t); 
    57 $mixert->launchTests($component, 'sfComponent'); 
     54// new methods via sfEventDispatcher 
     55require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     56$dispatcherTest = new sfEventDispatcherTest($t); 
     57$dispatcherTest->launchTests($context->getEventDispatcher(), $component, 'component'); 
  • trunk/test/unit/controller/sfControllerTest.php

    r4440 r4951  
    2424$controller->initialize($context); 
    2525 
    26 // mixins 
    27 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    28 $mixert = new sfMixerTest($t); 
    29 $mixert->launchTests($controller, 'sfController'); 
     26// new methods via sfEventDispatcher 
     27require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     28$dispatcherTest = new sfEventDispatcherTest($t); 
     29$dispatcherTest->launchTests($context->getEventDispatcher(), $controller, 'controller'); 
  • trunk/test/unit/controller/sfWebControllerTest.php

    r4440 r4951  
    1414$t = new lime_test(17, new lime_output_color()); 
    1515 
     16$_SERVER['HTTP_HOST'] = 'localhost'; 
     17$_SERVER['SCRIPT_NAME'] = '/index.php'; 
     18sfConfig::set('sf_url_format', 'PATH'); 
    1619sfConfig::set('sf_max_forwards', 10); 
    1720$context = sfContext::getInstance(array( 
     
    154157sfConfig::set('sf_charset', 'utf-8'); 
    155158ob_start(); 
    156 $controller->redirect('/module/action/id/1#photos'); 
     159$controller->redirect('module/action?id=1#photos'); 
    157160$content = ob_get_clean(); 
    158 $t->like($content, '~/module/action/id/1#photos~', '->redirect() adds a refresh meta in the content'); 
    159 $t->like($context->getResponse()->getHttpHeader('Location'), '~/module/action/id/1#photos~', '->redirect() adds a Location HTTP header'); 
     161$t->like($content, '~http\://localhost/index.php/\?module=module&amp;action=action&amp;id=1#photos~', '->redirect() adds a refresh meta in the content'); 
     162$t->like($context->getResponse()->getHttpHeader('Location'), '~http\://localhost/index.php/\?module=module&action=action&id=1#photos~', '->redirect() adds a Location HTTP header'); 
    160163 
    161164// ->genUrl() 
  • trunk/test/unit/generator/sfGeneratorTest.php

    r4440 r4951  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    14 $t = new lime_test(2, new lime_output_color()); 
     13$t = new lime_test(0, new lime_output_color()); 
    1514 
    1615class myGenerator extends sfGenerator 
     
    1918} 
    2019 
    21 $context = sfContext::getInstance(); 
     20$manager = new sfGeneratorManager(); 
    2221$generator = new myGenerator(); 
    23 $generator->initialize($context); 
    24  
    25 // mixins 
    26 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    27 $mixert = new sfMixerTest($t); 
    28 $mixert->launchTests($generator, 'sfGenerator'); 
     22$generator->initialize($manager); 
  • trunk/test/unit/log/sfAggregateLoggerTest.php

    r4845 r4951  
    1313$t = new lime_test(6, new lime_output_color()); 
    1414 
     15$dispatcher = new sfEventDispatcher(); 
     16 
    1517require_once(dirname(__FILE__).'/../../../lib/util/sfToolkit.class.php'); 
    1618$file = sfToolkit::getTmpDir().DIRECTORY_SEPARATOR.'sf_log_file.txt'; 
     
    2022} 
    2123$fileLogger = sfLogger::newInstance('sfFileLogger'); 
    22 $fileLogger->initialize(array('file' => $file)); 
     24$fileLogger->initialize($dispatcher, array('file' => $file)); 
    2325$consoleLogger = sfLogger::newInstance('sfConsoleLogger'); 
    2426 
     
    2628$t->diag('->initialize()'); 
    2729$logger = sfLogger::newInstance('sfAggregateLogger'); 
    28 $logger->initialize(array('loggers' => $fileLogger)); 
     30$logger->initialize($dispatcher, array('loggers' => $fileLogger)); 
    2931$t->is($logger->getLoggers(), array($fileLogger), '->initialize() can take a "loggers" parameter'); 
    3032 
    3133$logger = sfLogger::newInstance('sfAggregateLogger'); 
    32 $logger->initialize(array('loggers' => array($fileLogger, $consoleLogger))); 
     34$logger->initialize($dispatcher, array('loggers' => array($fileLogger, $consoleLogger))); 
    3335$t->is($logger->getLoggers(), array($fileLogger, $consoleLogger), '->initialize() can take a "loggers" parameter'); 
    3436 
  • trunk/test/unit/log/sfFileLoggerTest.php

    r4845 r4951  
    2020} 
    2121 
     22$dispatcher = new sfEventDispatcher(); 
     23 
    2224// ->initialize() 
    2325$t->diag('->initialize()'); 
     
    2527try 
    2628{ 
    27   $logger->initialize(); 
     29  $logger->initialize($dispatcher); 
    2830  $t->fail('->initialize() parameters must contains a "file" parameter'); 
    2931} 
     
    3537// ->log() 
    3638$t->diag('->log()'); 
    37 $logger->initialize(array('file' => $file)); 
     39$logger->initialize($dispatcher, array('file' => $file)); 
    3840$logger->log('foo'); 
    3941$lines = explode("\n", file_get_contents($file)); 
  • trunk/test/unit/log/sfLoggerTest.php

    r4845 r4951  
    2727} 
    2828 
     29$dispatcher = new sfEventDispatcher(); 
     30 
    2931// ->newInstance() 
    3032$t->diag('->newInstance()'); 
     
    5153// ->initialize() 
    5254$t->diag('->initialize()'); 
    53 $logger->initialize(array('level' => sfLogger::ERR)); 
    54 $t->is($logger->getLogLevel(), sfLogger::ERR, '->initialize() takes an array of parameters as its first argument'); 
     55$logger->initialize($dispatcher, array('level' => sfLogger::ERR)); 
     56$t->is($logger->getLogLevel(), sfLogger::ERR, '->initialize() takes an array of parameters as its second argument'); 
    5557 
    5658// ::getPriorityName() 
  • trunk/test/unit/request/sfRequestTest.php

    r4895 r4951  
    1313class myRequest extends sfRequest 
    1414{ 
    15   public function getRouting() 
     15  public function getEventDispatcher() 
    1616  { 
    17     return $this->routing
     17    return $this->dispatcher
    1818  } 
    1919} 
     
    2525$t = new lime_test(53, new lime_output_color()); 
    2626 
    27 $routing = new sfNoRouting(); 
    28 $routing->initialize(); 
     27$dispatcher = new sfEventDispatcher(); 
    2928 
    3029// ::newInstance() 
     
    4645$t->diag('->initialize()'); 
    4746$request = sfRequest::newInstance('myRequest'); 
    48 $request->initialize(null, $routing); 
    49 $t->is($routing, $request->getRouting(), '->initialize() takes a sfRouting object as its second argument'); 
    50 $request->initialize(null, $routing, array('foo' => 'bar')); 
     47$request->initialize($dispatcher); 
     48$t->is($dispatcher, $request->getEventDispatcher(), '->initialize() takes a sfEventDispatcher object as its first argument'); 
     49$request->initialize($dispatcher, array('foo' => 'bar')); 
    5150$t->is($request->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 
    5251 
     
    6867// ->extractParameters() 
    6968$t->diag('->extractParameters()'); 
    70 $request->initialize(null, $routing, array('foo' => 'foo', 'bar' => 'bar')); 
     69$request->initialize($dispatcher, array('foo' => 'foo', 'bar' => 'bar')); 
    7170$t->is($request->extractParameters(array()), array(), '->extractParameters() returns parameters'); 
    7271$t->is($request->extractParameters(array('foo')), array('foo' => 'foo'), '->extractParameters() returns parameters for keys in its first parameter'); 
     
    7473 
    7574$request = sfRequest::newInstance('myRequest'); 
    76 $request->initialize(null, $routing); 
     75$request->initialize($dispatcher); 
    7776 
    7877// ->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames 
     
    121120$pht->launchTests($request, 'attribute'); 
    122121 
    123 // mixins 
    124 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    125 $mixert = new sfMixerTest($t); 
    126 $mixert->launchTests($request, 'sfRequest'); 
     122// new methods via sfEventDispatcher 
     123require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     124$dispatcherTest = new sfEventDispatcherTest($t); 
     125$dispatcherTest->launchTests($dispatcher, $request, 'request'); 
  • trunk/test/unit/response/sfResponseTest.php

    r4895 r4951  
    2323$t = new lime_test(23, new lime_output_color()); 
    2424 
     25$dispatcher = new sfEventDispatcher(); 
     26 
    2527// ::newInstance() 
    2628$t->diag('::newInstance()'); 
     
    4143$t->diag('->initialize()'); 
    4244$response = sfResponse::newInstance('myResponse'); 
    43 $response->initialize(null, array('foo' => 'bar')); 
     45$response->initialize($dispatcher, array('foo' => 'bar')); 
    4446$t->is($response->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 
    4547 
     
    6466require_once($_test_dir.'/unit/sfParameterHolderTest.class.php'); 
    6567$response = sfResponse::newInstance('myResponse'); 
    66 $response->initialize(); 
     68$response->initialize($dispatcher); 
    6769$pht = new sfParameterHolderProxyTest($t); 
    6870$pht->launchTests($response, 'parameter'); 
    6971 
    70 // mixins 
    71 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    72 $mixert = new sfMixerTest($t); 
    73 $mixert->launchTests($response, 'sfResponse'); 
     72// new methods via sfEventDispatcher 
     73require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     74$dispatcherTest = new sfEventDispatcherTest($t); 
     75$dispatcherTest->launchTests($dispatcher, $response, 'response'); 
  • trunk/test/unit/response/sfWebResponseTest.php

    r4895 r4951  
    2626} 
    2727 
     28$dispatcher = new sfEventDispatcher(); 
     29 
    2830$response = new myWebResponse(); 
    29 $response->initialize(); 
     31$response->initialize($dispatcher); 
    3032 
    3133// ->getStatusCode() ->setStatusCode() 
     
    161163$t->diag('->mergeProperties()'); 
    162164$response1 = sfResponse::newInstance('myWebResponse'); 
    163 $response1->initialize(); 
     165$response1->initialize($dispatcher); 
    164166$response2 = sfResponse::newInstance('myWebResponse'); 
    165 $response2->initialize(); 
     167$response2->initialize($dispatcher); 
    166168 
    167169$response1->setHttpHeader('symfony', 'foo'); 
     
    177179$t->diag('->addStylesheet()'); 
    178180$response = sfResponse::newInstance('myWebResponse'); 
    179 $response->initialize(); 
     181$response->initialize($dispatcher); 
    180182$response->addStylesheet('test'); 
    181183$t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/stylesheet'), '->addStylesheet() adds a new stylesheet for the response'); 
     
    198200$t->diag('->addJavascript()'); 
    199201$response = sfResponse::newInstance('myWebResponse'); 
    200 $response->initialize(); 
     202$response->initialize($dispatcher); 
    201203$response->addJavascript('test'); 
    202204$t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/javascript'), '->addJavascript() adds a new javascript for the response'); 
     
    222224$t->diag('->setHeaderOnly() ->isHeaderOnly()'); 
    223225$response = sfResponse::newInstance('myWebResponse'); 
    224 $response->initialize(); 
     226$response->initialize($dispatcher); 
    225227$t->is($response->isHeaderOnly(), false, '->isHeaderOnly() returns false if the content must be send to the client'); 
    226228$response->setHeaderOnly(true); 
     
    243245// ->serialize() ->unserialize() 
    244246$t->diag('->serialize() ->unserialize()'); 
    245 $t->ok($response == unserialize(serialize($response)), 'sfWebResponse implements the Serializable interface'); 
     247$resp = unserialize(serialize($response)); 
     248$resp->initialize($dispatcher); 
     249$t->ok($response == $resp, 'sfWebResponse implements the Serializable interface'); 
  • trunk/test/unit/routing/sfNoRoutingTest.php

    r4892 r4951  
    1414 
    1515$routing = new sfNoRouting(); 
    16 $routing->initialize(); 
     16$routing->initialize(new sfEventDispatcher()); 
    1717 
    1818// ->getCurrentInternalUri() 
  • trunk/test/unit/routing/sfPathInfoRoutingTest.php

    r4892 r4951  
    1414 
    1515$routing = new sfPathInfoRouting(); 
    16 $routing->initialize(); 
     16$routing->initialize(new sfEventDispatcher()); 
    1717 
    1818// ->getCurrentInternalUri() 
  • trunk/test/unit/routing/sfPatternRoutingTest.php

    r4899 r4951  
    2323// public methods 
    2424$r = new sfPatternRoutingTest(); 
    25 $r->initialize(); 
     25$r->initialize(new sfEventDispatcher()); 
    2626foreach (array('clearRoutes', 'connect', 'generate', 'getCurrentInternalUri', 'getCurrentRouteName', 'getRoutes', 'hasRoutes', 'parse', 'setRoutes') as $method) 
    2727{ 
     
    270270$r->connect('test',  '/:module', array('action' => 'index')); 
    271271$r->connect('test1', '/:module/:action/*', array()); 
     272$r->connect('test3', '/', array()); 
    272273$r->parse('/'); 
    273274$t->is($r->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); 
  • trunk/test/unit/sfContextMock.class.php

    r4932 r4951  
    3131      self::$instance->storage->initialize(array('session_path' => sfConfig::get('sf_test_cache_dir').'/sessions')); 
    3232 
     33      self::$instance->dispatcher = new sfEventDispatcher(); 
     34 
    3335      foreach ($factories as $type => $class) 
    3436      { 
     
    3840 
    3941    return self::$instance; 
     42  } 
     43 
     44  public function getEventDispatcher() 
     45  { 
     46    return self::$instance->dispatcher; 
    4047  } 
    4148 
     
    8996        case 'routing': 
    9097        case 'response': 
    91           $object->initialize(null, $parameters); 
     98          $object->initialize($this->dispatcher, $parameters); 
    9299          break; 
    93100        case 'request': 
    94           $object->initialize(null, $this->routing, $parameters); 
     101          $object->initialize($this->dispatcher, $this->routing, $parameters); 
    95102          break; 
    96103        default: 
  • trunk/test/unit/user/sfBasicSecurityUserTest.php

    r4892 r4951  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    1413$t = new lime_test(39, new lime_output_color()); 
    1514 
    16 class myRequest 
    17 
    18   public function getParameter($key) 
    19   { 
    20     if ($key == 'sf_culture') 
    21     { 
    22       return 'en'; 
    23     } 
    24   } 
    25 
     15$dispatcher = new sfEventDispatcher(); 
     16$storage = sfStorage::newInstance('sfSessionTestStorage'); 
     17$storage->initialize(array('session_path' => sfConfig::get('sf_test_cache_dir').'/sessions')); 
    2618 
    27 $context = sfContext::getInstance(array( 
    28   'routing' => 'sfPatternRouting', 
    29   'request' => 'myRequest', 
    30   'user'    => 'sfBasicSecurityUser', 
    31 )); 
    32 $user = $context->user; 
     19$user = new sfBasicSecurityUser(); 
     20$user->initialize($dispatcher, $storage); 
    3321 
    3422// ->initialize() 
     
    5947sfConfig::set('sf_timeout', 86400); 
    6048$user = new sfBasicSecurityUser(); 
    61 $user->initialize($context); 
    62 $context->user = $user; 
     49$user->initialize($dispatcher, $storage); 
    6350$t->diag('->setTimedOut() ->isTimedOut()'); 
    6451$t->is($user->isTimedOut(), false, '->isTimedOut() returns false if the session is not timed out'); 
  • trunk/test/unit/user/sfUserTest.php

    r4934 r4951  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    1413$t = new lime_test(39, new lime_output_color()); 
     
    1716sfConfig::set('sf_test_cache_dir', sfToolkit::getTmpDir()); 
    1817 
    19 $context = sfContext::getInstance(array( 
    20   'routing' => 'sfNoRouting', 
    21   'request' => 'sfWebRequest', 
    22   'user' => 'sfUser', 
    23 )); 
    24 $user = $context->user; 
    25 $storage = $context->storage; 
     18$dispatcher = new sfEventDispatcher(); 
     19$storage = sfStorage::newInstance('sfSessionTestStorage'); 
     20$storage->initialize(array('session_path' => sfConfig::get('sf_test_cache_dir').'/sessions')); 
     21 
     22$user = new sfUser(); 
     23$user->initialize($dispatcher, $storage); 
    2624 
    2725// ->initialize() 
     
    2927$t->is($user->getCulture(), 'en', '->initialize() sets the culture to "en" by default'); 
    3028 
    31 sfConfig::set('sf_i18n_default_culture', 'de'); 
    3229$user->setCulture(null); 
    33 user_flush($context); 
     30$user->initialize($dispatcher, $storage, array('default_culture' => 'de')); 
    3431 
    35 $t->is($user->getCulture(), 'de', '->initialize() sets the culture to the value of sf_i18n_default_culture if available'); 
     32user_flush($dispatcher, $user, $storage); 
     33 
     34$t->is($user->getCulture(), 'de', '->initialize() sets the culture to the value of default_culture if available'); 
    3635 
    3736sfConfig::set('sf_i18n_default_culture', 'fr'); 
    38 user_flush($context); 
     37user_flush($dispatcher, $user, $storage); 
    3938$t->is($user->getCulture(), 'de', '->initialize() reads the culture from the session data if available'); 
    4039 
    4140$userBis = new sfUser(); 
    42 $userBis->initialize($context); 
     41$userBis->initialize($dispatcher, $storage); 
    4342$t->is($userBis->getCulture(), 'de', '->initialize() serializes the culture to the session data'); 
    4443 
     
    5049// ->setFlash() ->getFlash() ->hasFlash() 
    5150$t->diag('->setFlash() ->getFlash() ->hasFlash()'); 
    52 $user->initialize($context, array('use_flash' => true)); 
     51$user->initialize($dispatcher, $storage, array('use_flash' => true)); 
    5352$user->setFlash('foo', 'bar'); 
    5453$t->is($user->getFlash('foo'), 'bar', '->setFlash() sets a flash variable'); 
    5554$t->is($user->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); 
    56 user_flush($context, array('use_flash' => true)); 
     55user_flush($dispatcher, $user, $storage, array('use_flash' => true)); 
    5756 
    5857$userBis = new sfUser(); 
    59 $userBis->initialize($context, array('use_flash' => true)); 
     58$userBis->initialize($dispatcher, $storage, array('use_flash' => true)); 
    6059$t->is($userBis->getFlash('foo'), 'bar', '->getFlash() returns a flash previously set'); 
    6160$t->is($userBis->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); 
    62 user_flush($context, array('use_flash' => true)); 
     61user_flush($dispatcher, $user, $storage, array('use_flash' => true)); 
    6362 
    6463$userBis = new sfUser(); 
    65 $userBis->initialize($context, array('use_flash' => true)); 
     64$userBis->initialize($dispatcher, $storage, array('use_flash' => true)); 
    6665$t->is($userBis->getFlash('foo'), null, 'Flashes are automatically removed after the next request'); 
    6766$t->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists'); 
     
    7776$pht->launchTests($user, 'attribute'); 
    7877 
    79 // mixins 
    80 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    81 $mixert = new sfMixerTest($t); 
    82 $mixert->launchTests($user, 'sfUser'); 
     78// new methods via sfEventDispatcher 
     79require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     80$dispatcherTest = new sfEventDispatcherTest($t); 
     81$dispatcherTest->launchTests($dispatcher, $user, 'user'); 
    8382 
    8483$storage->clear(); 
    8584 
    86 function user_flush($context, $parameters = array()) 
     85function user_flush($dispatcher, $user, $storage, $parameters = array()) 
    8786{ 
    88   $context->getUser()->shutdown(); 
    89   $context->getUser()->initialize($context, $parameters); 
    90   $parameters = $context->getStorage()->getParameterHolder()->getAll(); 
    91   $context->getStorage()->shutdown(); 
    92   $context->getStorage()->initialize($parameters); 
     87  $user->shutdown(); 
     88  $user->initialize($dispatcher, $storage, $parameters); 
     89  $parameters = $storage->getParameterHolder()->getAll(); 
     90  $storage->shutdown(); 
     91  $storage->initialize($parameters); 
    9392} 
  • trunk/test/unit/view/sfViewTest.php

    r4562 r4951  
    1212require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1313 
    14 $t = new lime_test(18, new lime_output_color()); 
     14$t = new lime_test(17, new lime_output_color()); 
    1515 
    1616class myView extends sfView 
     
    4040$view->initialize($context, '', '', ''); 
    4141 
    42 // ->getContext() 
    43 $t->diag('->getContext()'); 
    44 $view->initialize($context, '', '', ''); 
    45 $t->is($view->getContext(), $context, '->getContext() returns the current context'); 
    46  
    4742// ->isDecorator() ->setDecorator() 
    4843$t->diag('->isDecorator() ->setDecorator()'); 
     
    5651$pht->launchTests($view, 'parameter'); 
    5752 
    58 // mixins 
    59 require_once($_test_dir.'/unit/sfMixerTest.class.php'); 
    60 $mixert = new sfMixerTest($t); 
    61 $mixert->launchTests($view, 'sfView'); 
     53// new methods via sfEventDispatcher 
     54require_once($_test_dir.'/unit/sfEventDispatcherTest.class.php'); 
     55$dispatcherTest = new sfEventDispatcherTest($t); 
     56$dispatcherTest->launchTests($context->getEventDispatcher(), $view, 'view'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.