Development

Changeset 9165

You must first sign up to be able to contribute.

Changeset 9165

Show
Ignore:
Timestamp:
05/22/08 08:02:24 (5 years ago)
Author:
dwhittle
Message:

1.1: fixed sfBrowser has duplicate listeners (closes #3612)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/event/sfEventDispatcher.class.php

    r8146 r9165  
    44 * This file is part of the symfony package. 
    55 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    155155    return $this->listeners[$name]; 
    156156  } 
     157 
     158  /** 
     159   * Get the entire listeners stack. 
     160   * 
     161   * @return array The complete array of event names and listeners 
     162   */ 
     163  public function getListenerStack() 
     164  { 
     165    return $this->listeners; 
     166  } 
    157167} 
  • branches/1.1/lib/util/sfBrowser.class.php

    r9074 r9165  
    405405      { 
    406406        $currentConfiguration = $this->context->getConfiguration(); 
    407         $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug(), $currentConfiguration->getRootDir(), $currentConfiguration->getEventDispatcher()); 
     407        $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug(), $currentConfiguration->getRootDir()); 
    408408        $this->context = sfContext::createInstance($configuration); 
     409         
     410        // copy in any missing listeners 
     411        $dispatcher = $configuration->getEventDispatcher(); 
     412        foreach ($currentConfiguration->getEventDispatcher()->getListenerStack() as $name => $listeners) 
     413        { 
     414          foreach (array_diff($listeners, $dispatcher->getListeners($name)) as $listener) 
     415          { 
     416            $dispatcher->connect($name, $listener); 
     417          } 
     418        } 
    409419      } 
    410420      else 
     
    412422        $this->context = sfContext::getInstance(); 
    413423        $this->context->initialize($this->context->getConfiguration()); 
    414       } 
    415  
    416       $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException')); 
     424        $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException')); 
     425      } 
     426 
    417427      unset($currentConfiguration); 
    418428    } 
  • branches/1.1/test/functional/sfTestBrowserTest.php

    r9074 r9165  
    108108$b->get('/browser'); 
    109109$b->test()->ok($b->getContext()->getEventDispatcher()->hasListeners('my_event'), 'event listeners persist across multiple requests'); 
     110 
     111// check consistency of number of listeners 
     112$nb = count($b->getContext()->getEventDispatcher()->getListeners('application.throw_exception')); 
     113$b->get('/browser'); 
     114$b->test()->is(count($b->getContext()->getEventDispatcher()->getListeners('application.throw_exception')), $nb, 'event listeners are not duplicated');