当前位置: 首页>>代码示例>>PHP>>正文


PHP EventDispatcher::addListener方法代码示例

本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcher::addListener方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcher::addListener方法的具体用法?PHP EventDispatcher::addListener怎么用?PHP EventDispatcher::addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\EventDispatcher\EventDispatcher的用法示例。


在下文中一共展示了EventDispatcher::addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct(EventDispatcher $dispatcher)
 {
     $this->stdErr = fopen('php://stderr', 'w');
     $this->output = new StreamOutput($this->stdErr);
     $this->eventDispatcher = $dispatcher;
     $this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, array($this, 'onFixerFileProcessed'));
 }
开发者ID:cryode,项目名称:PHP-CS-Fixer,代码行数:7,代码来源:ProcessOutput.php

示例2: __construct

 public function __construct()
 {
     parent::__construct(Berk::NAME, Berk::VERSION);
     $time = time();
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
         $output = $event->getOutput();
         $directory = Git::getWorkingDirectory();
         chdir($directory);
         $output->writeln('<info>Changed current directory to: ' . $directory . '</info>');
         $output->writeln('');
         $command = $event->getCommand();
         if ($command instanceof Command) {
             $command->setBerk(new Berk());
         }
     });
     $dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) use($time) {
         $output = $event->getOutput();
         $time = time() - $time;
         $output->writeln('');
         $output->writeln('<info>Command completed in ' . $time . ' seconds. Bye.</info>');
     });
     $this->setDispatcher($dispatcher);
     $this->add(new ServerCommand());
     $this->add(new ExportCommand());
     $this->add(new DeployCommand());
 }
开发者ID:yrizos,项目名称:berk,代码行数:27,代码来源:Application.php

示例3: configureSingleState

 /**
  * @inheritdoc
  */
 public function configureSingleState(EventDispatcher $dispatcher)
 {
     $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
         /** @var ConsoleCommand $command */
         $command = $event->getCommand();
         if (!$command instanceof ConsoleCommand or $command->isSingleInstance() == false) {
             return;
         }
         $commandState = new CommandState($command);
         if ($commandState->isAlive()) {
             $event->getOutput()->writeln('Already running: ' . $command->getName() . ' Pid:' . $commandState->getPid());
             $event->disableCommand();
         } else {
             $commandState->setPid(getmypid());
         }
     });
     $dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) {
         /** @var ConsoleCommand $command */
         $command = $event->getCommand();
         if (!$command instanceof ConsoleCommand or $command->isSingleInstance() == false) {
             return;
         }
         if ($event->getExitCode() === 0) {
             (new CommandState($command))->unlink();
         }
     });
     return $dispatcher;
 }
开发者ID:funivan,项目名称:console,代码行数:31,代码来源:SingleStateConfigurator.php

示例4: __construct

 public function __construct()
 {
     $this->dispatcher = new EventDispatcher();
     $this->dispatcher->addListener(Events::TRANSFER_PRE, array(new Listener\Transfer\PreEventListener(), 'onPreAction'));
     $this->dispatcher->addListener(Events::TRANSFER_POST, array(new Listener\Transfer\PostEventListener(), 'onPostAction'));
     $this->dispatcher->addListener(Events::TRANSFER_TOTAL_TIMEOUT, array(new Listener\Transfer\TotalTimeoutEventListener(), 'onTimeoutAction'));
 }
开发者ID:webignition,项目名称:website-sitemap-retriever,代码行数:7,代码来源:WebsiteSitemapRetriever.php

示例5: testRecursiveMessage

 public function testRecursiveMessage()
 {
     $dispatcher = new EventDispatcher();
     $backend = new PostponeRuntimeBackend($dispatcher, true);
     $dispatcher->addListener('kernel.terminate', array($backend, 'onEvent'));
     $message1 = $backend->create('notification.demo1', array());
     $message2 = $backend->create('notification.demo2', array());
     $backend->publish($message1);
     $phpunit = $this;
     $phpunit->passed1 = false;
     $phpunit->passed2 = false;
     $dispatcher->addListener('notification.demo1', function (ConsumerEventInterface $event) use($phpunit, $message1, $message2, $backend, $dispatcher) {
         $phpunit->assertSame($message1, $event->getMessage());
         $phpunit->passed1 = true;
         $backend->publish($message2);
     });
     $dispatcher->addListener('notification.demo2', function (ConsumerEventInterface $event) use($phpunit, $message2) {
         $phpunit->assertSame($message2, $event->getMessage());
         $phpunit->passed2 = true;
     });
     $dispatcher->dispatch('kernel.terminate');
     $this->assertTrue($phpunit->passed1);
     $this->assertTrue($phpunit->passed2);
     $this->assertEquals(MessageInterface::STATE_DONE, $message1->getState());
     $this->assertEquals(MessageInterface::STATE_DONE, $message2->getState());
 }
开发者ID:BookWorld1,项目名称:nom,代码行数:26,代码来源:PostponeRuntimeBackendTest.php

示例6: addCookieResponseListener

 /**
  * Method to add the ResponseListener which sets the cookie. Should only be called once
  *
  * @see also http://slides.seld.be/?file=2011-10-20+High+Performance+Websites+with+Symfony2.html#45
  *
  * @return void
  */
 public function addCookieResponseListener()
 {
     if ($this->cookieListenerisAdded !== true) {
         $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onResponse'));
     }
     $this->cookieListenerisAdded = true;
 }
开发者ID:rdohms,项目名称:LocaleBundle,代码行数:14,代码来源:LocaleDetectorListener.php

示例7: test

 public function test()
 {
     $eventDispatcher = new EventDispatcher();
     $eventDispatcher->addListener(ImportItemEvent::AFTER_READ, array($this, 'onAfterRead'));
     $eventDispatcher->addListener(ImportItemEvent::AFTER_FILTER, array($this, 'onAfterFilter'));
     $eventDispatcher->addListener(ImportItemEvent::AFTER_CONVERSION, array($this, 'onAfterConversion'));
     $eventDispatcher->addListener(ImportItemEvent::AFTER_CONVERSIONFILTER, array($this, 'onAfterConversionFilter'));
     $eventDispatcher->addListener(ImportItemEvent::AFTER_WRITE, array($this, 'onAfterWrite'));
     $fileDir = __DIR__ . '/../../../../../metadata/testfiles';
     $finder = Finder::create()->in($fileDir)->name('*');
     $lfsp = new FinderFileStorageProvider($finder);
     $lfsp->setStorageFactory(new FormatDiscoverLocalFileStorageFactory(new MimeTypeDiscoverStrategy(array('text/plain' => new CsvAutoDelimiterFormatFactory()))));
     $storageLocator = new StorageLocator();
     $storageLocator->register('defaultProvider', $lfsp);
     $array = array();
     $targetStorage = new ArrayStorage($array);
     $importer = Importer::build($targetStorage);
     $importRepository = new ImporterRepository();
     $importRepository->register('defaultImporter', $importer);
     $importRequest = new ImportRequest($fileDir . '/100.csv', 'defaultProvider', 'defaultImporter');
     $importBuilder = new ImportBuilder($importRepository, $storageLocator);
     $import = $importBuilder->buildFromRequest($importRequest);
     $import->mappings()->add('prefix', 'Anrede', 'upperCase')->add('name', 'Name', 'lowerCase');
     $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
     $expectedResult = array('Name' => 'jennie abernathy', 'Anrede' => 'MS.', 'street' => '866 Hyatt Isle Apt. 888', 'zip' => '65982', 'city' => 'East Laurie', 'phone' => '(551)436-0391', 'email' => 'runolfsson.moriah@yahoo.com');
     $previewResult = $importRunner->preview($import, 0);
     $this->assertEquals($expectedResult, $previewResult['to']);
 }
开发者ID:mathielen,项目名称:import-engine,代码行数:28,代码来源:ImportRunnerTest.php

示例8: addListener

 /**
  * Add a callback to a channel which will get triggered when channel receives a message via a publisher.
  *
  * @param string   $channel
  * @param callable $callback
  * @param int      $priority  Default: 0
  *
  * @return PubSubManager
  * @throws InvalidArgumentException
  */
 public function addListener($channel, callable $callback, $priority = 0)
 {
     if (empty($channel)) {
         throw new InvalidArgumentException('Empty event channel name supplied.');
     }
     $this->event_dispatcher->addListener(static::generateEventName($channel), $callback, $priority);
     return $this;
 }
开发者ID:bravo3,项目名称:orm,代码行数:18,代码来源:PubSubManager.php

示例9: subscribe

 /**
  * Subscribes the message handler to the bus.
  * @param MessageHandlerInterface $messageHandler The message handler.
  */
 public function subscribe(MessageHandlerInterface $messageHandler)
 {
     foreach ($messageHandler->getMessageSubscriptions() as $subscription) {
         $this->eventDispatcher->addListener($subscription, function (GenericEvent $event) use($messageHandler) {
             $messageHandler->handle($event->getSubject());
         });
     }
 }
开发者ID:palya-framework,项目名称:palya,代码行数:12,代码来源:SymfonyEventDispatcherBus.php

示例10: addHooks

 /**
  * Set all hooks
  *
  * @return  void
  */
 protected function addHooks()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(ConsoleEvents::COMMAND, new Header());
     $dispatcher->addListener(ConsoleEvents::COMMAND, new ValidateDependencies());
     $dispatcher->addListener(ConsoleEvents::TERMINATE, new TotalTime($this->timeStart));
     $this->setDispatcher($dispatcher);
 }
开发者ID:mostofreddy,项目名称:phox,代码行数:13,代码来源:App.php

示例11: __construct

 public function __construct()
 {
     $this->repository = new InMemoryExpenseListRepository();
     $dispatcher = new EventDispatcher();
     $this->createExpenseListCase = new CreateExpenseList($this->repository, $dispatcher);
     $dispatcher->addListener(CreateExpenseList::SUCCESS, [$this, 'recordNotification']);
     $dispatcher->addListener(CreateExpenseList::FAILURE, [$this, 'recordNotification']);
 }
开发者ID:gobudgit,项目名称:gobudgit,代码行数:8,代码来源:ExpenseListContext.php

示例12: testTearDown

 public function testTearDown()
 {
     $events = array();
     $this->dispatcher->addListener('test.after', function ($e) use(&$events) {
         $events[] = $e->getName();
     });
     $this->testcase->tearDown();
     $this->assertEquals($events, array('test.after'));
 }
开发者ID:BatVane,项目名称:Codeception,代码行数:9,代码来源:TestCaseTest.php

示例13: monitorEvents

 /**
  * Add listeners to $this->dispatcher which record each invocation of $monitoredEvents
  * in $this->actualEventSequence.
  *
  * @param array $monitoredEvents
  *   List of event names.
  *
  */
 public function monitorEvents($monitoredEvents)
 {
     foreach ($monitoredEvents as $monitoredEvent) {
         $test = $this;
         $this->dispatcher->addListener($monitoredEvent, function ($event) use($monitoredEvent, &$test) {
             $test->actualEventSequence[] = array('name' => $monitoredEvent, 'class' => get_class($event));
         }, 2 * Events::W_EARLY);
     }
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:17,代码来源:KernelTest.php

示例14: attachListeners

 /**
  * Attach all event listeners to the $eventDispatcher.
  */
 private function attachListeners()
 {
     // Create the listeners.
     $logReferralReasonsListener = new LogReferralReasonsListener(new Datasource_Insurance_PolicyNotes());
     $dispatchReferralEmailListener = new DispatchReferralEmailListener($this->getContainer()->get('twig'), $this->_params, new Application_Core_Mail());
     // The above two listeners are both listening for the RRPEvents::POLICY_REFERRED event to be fired.
     $this->eventDispatcher->addListener(RRPEvents::POLICY_REFERRED, array($logReferralReasonsListener, 'onReferral'));
     $this->eventDispatcher->addListener(RRPEvents::POLICY_REFERRED, array($dispatchReferralEmailListener, 'onReferral'));
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:12,代码来源:RentguaranteeController.php

示例15: setUp

 public function setUp()
 {
     $this->dispatcher = new EventDispatcher('UTF-8');
     $listener = new RequestListener($this->dispatcher);
     $this->dispatcher->addListener(KernelEvents::REQUEST, [$listener, 'onKernelRequest']);
     $this->dispatcher->addListener(QPushEvents::Notification('ironmq-test'), [$this, 'IronMqOnNotificationReceived']);
     $this->dispatcher->addListener(QPushEvents::Notification('aws-test'), [$this, 'AwsOnNotificationReceived']);
     $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
 }
开发者ID:xabbuh,项目名称:qpush-bundle,代码行数:9,代码来源:RequestListenerTest.php


注:本文中的Symfony\Component\EventDispatcher\EventDispatcher::addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。