當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。