connect() public method

Connects a listener to a given event name.
public connect ( string $name, mixed $listener, integer $priority )
$name string An event name
$listener mixed A PHP callable
$priority integer The priority (between -10 and 10 -- defaults to 0)
Example #1
0
 /**
  * @see     FormatterInterface
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     $this->dispatcher = $dispatcher;
     $dispatcher->connect('step.run.after', array($this, 'handleStep'), 10);
     $dispatcher->connect('outline.sub.run.after', array($this, 'printScenario'), 10);
     $dispatcher->connect('scenario.run.after', array($this, 'printScenario'), 10);
     $dispatcher->connect('feature.run.after', array($this, 'flushFeatureXML'), 10);
 }
Example #2
0
 public function testFilter()
 {
     $listener = new Listener();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('-*foo*-', $ret, '->filter() returns the filtered value');
     $listener->reset();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $ret = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('*-foo-*', $ret, '->filter() returns the filtered value');
 }
Example #3
0
 /**
  * Register Hooks Event Listeners. 
  * 
  * @param   EventDispatcher $dispatcher event dispatcher
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     if (!count($this->hooks)) {
         $this->loadHooks();
     }
     $dispatcher->connect('suite.run.before', array($this, 'fireSuiteHooks'));
     $dispatcher->connect('suite.run.after', array($this, 'fireSuiteHooks'));
     $dispatcher->connect('feature.run.before', array($this, 'fireFeatureHooks'));
     $dispatcher->connect('feature.run.after', array($this, 'fireFeatureHooks'));
     $dispatcher->connect('scenario.run.before', array($this, 'fireScenarioHooks'));
     $dispatcher->connect('scenario.run.after', array($this, 'fireScenarioHooks'));
     $dispatcher->connect('outline.sub.run.before', array($this, 'fireScenarioHooks'));
     $dispatcher->connect('outline.sub.run.after', array($this, 'fireScenarioHooks'));
     $dispatcher->connect('step.run.before', array($this, 'fireStepHooks'));
     $dispatcher->connect('step.run.after', array($this, 'fireStepHooks'));
 }
 public function testFilter()
 {
     $listener = new Listener();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('-*foo*-', $e->getReturnValue(), '->filter() filters a value');
     $this->assertEquals($event, $e, '->filter() returns the event object');
     $listener->reset();
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('foo', array($listener, 'filterFooBis'));
     $dispatcher->connect('foo', array($listener, 'filterFoo'));
     $e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
     $this->assertEquals('*-foo-*', $e->getReturnValue(), '->filter() filters a value');
 }
Example #5
0
 protected function getDispatcher()
 {
     $dispatcher = new EventDispatcher();
     $listener = new ResponseListener('UTF-8');
     $dispatcher->connect('core.response', array($listener, 'filter'));
     return $dispatcher;
 }
Example #6
0
 public function testFilterWhenThereIsNoEsiIncludes()
 {
     $dispatcher = new EventDispatcher();
     $listener = new EsiListener(new Esi());
     $dispatcher->connect('core.response', array($listener, 'filter'));
     $event = new Event(null, 'core.response', array('request_type' => HttpKernelInterface::MASTER_REQUEST));
     $dispatcher->filter($event, $response = new Response('foo'));
     $this->assertEquals('', $response->headers->get('Surrogate-Control'));
 }
Example #7
0
 /**
  * @see     Everzet\Behat\Formatter\FormatterInterface
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     $this->dispatcher = $dispatcher;
     $dispatcher->connect('step.run.after', array($this, 'printStep'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printEmptyLine'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printFailedSteps'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printPendingSteps'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printStatistics'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printSnippets'), 10);
 }
Example #8
0
 public function __construct($map)
 {
     $this->routes = new RouteCollection();
     foreach ($map as $pattern => $to) {
         if (false !== strpos($pattern, ' ')) {
             list($method, $pattern) = explode(' ', $pattern, 2);
             $requirements = array('_method' => $method);
         } else {
             $requirements = array();
         }
         $route = new Route($pattern, array('_controller' => $to), $requirements);
         $this->routes->add(str_replace(array('/', ':'), '_', $pattern), $route);
     }
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('core.request', array($this, 'parseRequest'));
     $resolver = new ControllerResolver();
     parent::__construct($dispatcher, $resolver);
 }
Example #9
0
 /**
  * @see     Everzet\Behat\Filter\FilterInterface
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('feature.run.filter_scenarios', array($this, 'filterScenarios'));
 }
Example #10
0
 /**
  * Registers a core.request listener to enforce security.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     $dispatcher->connect('core.request', array($this, 'handle'), $priority);
     $this->dispatcher = $dispatcher;
 }
 /**
  * Registers a core.response listener.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  */
 public function register(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('core.response', array($this, 'handle'));
 }
 /**
  * Registers a core.security listener to load the SecurityContext from the
  * session.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('core.security', array($this, 'read'), 0);
     $dispatcher->connect('core.response', array($this, 'write'), 0);
 }
Example #13
0
 public function testHandleWithAResponseListener()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->connect('core.response', function ($event, $response) {
         return new Response('foo');
     });
     $kernel = new BaseHttpKernel($dispatcher, $this->getResolver());
     $this->assertEquals('foo', $kernel->handle(new Request())->getContent());
 }
Example #14
0
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     $dispatcher->connect('form.contact_submission', array($this, 'process'));
 }
 /**
  * 
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     $dispatcher->connect('core.security', array($this, 'handle'), $priority);
 }
Example #16
0
 /**
  * Registers a core.response and core.exception listeners.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     $dispatcher->connect('core.exception', array($this, 'handleException'), $priority);
     $dispatcher->connect('core.response', array($this, 'handleResponse'), $priority);
 }
Example #17
0
 /**
  * Registers a core.exception listener to take care of security exceptions.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('core.exception', array($this, 'handleException'), 0);
 }
 /**
  * @param EventDispatcher $dispatcher
  * @param integer         $priority = 0
  */
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     $dispatcher->connect('core.controller', array($this, 'filterController'), $priority);
 }
Example #19
0
 /**
  * @see     FormatterInterface
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     $this->dispatcher = $dispatcher;
     $dispatcher->connect('feature.run.before', array($this, 'printFeatureHeader'), 10);
     $dispatcher->connect('outline.run.before', array($this, 'printOutlineHeader'), 10);
     $dispatcher->connect('outline.sub.run.after', array($this, 'printOutlineSubResult'), 10);
     $dispatcher->connect('outline.run.after', array($this, 'printOutlineFooter'), 10);
     $dispatcher->connect('scenario.run.before', array($this, 'printScenarioHeader'), 10);
     $dispatcher->connect('scenario.run.after', array($this, 'printScenarioFooter'), 10);
     $dispatcher->connect('background.run.before', array($this, 'printBackgroundHeader'), 10);
     $dispatcher->connect('background.run.after', array($this, 'printBackgroundFooter'), 10);
     $dispatcher->connect('step.run.after', array($this, 'printStep'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printStatistics'), 10);
     $dispatcher->connect('suite.run.after', array($this, 'printSnippets'), 10);
 }
Example #20
0
 /**
  * Registers a core.response listener to add the Surrogate-Control header to a Response when needed.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  * @param integer         $priority   The priority
  */
 public function register(EventDispatcher $dispatcher, $priority = 0)
 {
     if (null !== $this->esi) {
         $dispatcher->connect('core.response', array($this, 'filter'), $priority);
     }
 }
 /**
  * Registers a core.request listener.
  *
  * @param EventDispatcher $dispatcher An EventDispatcher instance
  */
 public function register(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('core.request', array($this, 'resolve'));
 }
Example #22
0
 /**
  * Register output manager event listeners. 
  * 
  * @param   EventDispatcher $dispatcher event dispatcher
  */
 public function registerListeners(EventDispatcher $dispatcher)
 {
     $dispatcher->connect('behat.output.write', array($this, 'write'));
     $formatter = $this->formatters[$this->formatter];
     $formatter->registerListeners($dispatcher);
     $formatter->setSupportPath($this->supportPath);
     if (is_file($this->supportPath)) {
         unlink($this->supportPath);
     }
     if ($formatter instanceof TimableFormatterInterface) {
         $formatter->showTimer($this->timer);
     }
     if ($formatter instanceof ContainerAwareFormatterInterface) {
         $formatter->setContainer($this->container);
     }
     if ($formatter instanceof TranslatableFormatterInterface) {
         $translator = $this->container->get('gherkin.translator');
         $translator->setLocale($this->locale);
         $formatter->setTranslator($translator);
     }
     if ($formatter instanceof ColorableFormatterInterface) {
         $formatter->showColors($this->hasColorSupport());
     }
     if ($formatter instanceof VerbosableFormatterInterface) {
         $formatter->beVerbose($this->verbose);
     }
 }