本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcher::removeListener方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcher::removeListener方法的具体用法?PHP EventDispatcher::removeListener怎么用?PHP EventDispatcher::removeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcher
的用法示例。
在下文中一共展示了EventDispatcher::removeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeSignalListener
public function removeSignalListener($signal, $callable)
{
$this->dispatcher->removeListener('morker.signal.' . $signal, $callable);
if (!$this->dispatcher->hasListeners('morker.signal.' . $signal)) {
pcntl_signal($signal, SIG_DFL);
}
}
示例2: testGetListenersWhenAddedCallbackListenerIsRemoved
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {
};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertSame(array(), $this->dispatcher->getListeners());
}
示例3: removeListeners
/**
* Removes all registered event listeners.
*/
private function removeListeners()
{
$listeners = $this->dispatcher->getListeners();
foreach ($listeners as $event => $list) {
foreach ($list as $listener) {
$this->dispatcher->removeListener($event, $listener);
}
}
}
示例4: process
/**
* @param Message $message
*/
public function process(Message $message)
{
$email = $message->getFrom()->getEmail();
$diamanteUser = $this->diamanteUserRepository->findUserByEmail($email);
$type = User::TYPE_DIAMANTE;
if (is_null($diamanteUser)) {
$sender = $message->getFrom();
$diamanteUser = $this->diamanteUserFactory->create($email, $sender->getFirstName(), $sender->getLastName());
$this->diamanteUserRepository->store($diamanteUser);
}
$reporterId = $diamanteUser->getId();
$reporter = new User($reporterId, $type);
$attachments = $message->getAttachments();
if (!$message->getReference()) {
$branchId = $this->getAppropriateBranch($message->getFrom()->getEmail(), $message->getTo());
$assigneeId = $this->branchEmailConfigurationService->getBranchDefaultAssignee($branchId);
$ticket = $this->messageReferenceService->createTicket($message->getMessageId(), $branchId, $message->getSubject(), $message->getContent(), $reporter, $assigneeId, $attachments);
} else {
$this->eventDispatcher->removeListener('commentWasAddedToTicket', array($this->ticketNotificationsSubscriber, 'processEvent'));
$ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), $reporter, $message->getReference(), $attachments);
}
$this->processWatchers($message, $ticket);
}
示例5: lazyLoad
/**
* Lazily loads listeners for this event from the dependency injection
* container.
*
* @param string $eventName The name of the event to dispatch. The name of
* the event is the name of the method that is
* invoked on listeners.
*/
protected function lazyLoad($eventName)
{
if (isset($this->listenerIds[$eventName])) {
foreach ($this->listenerIds[$eventName] as $args) {
list($serviceId, $method, $priority) = $args;
$listener = $this->container->get($serviceId);
$key = $serviceId . '.' . $method;
if (!isset($this->listeners[$eventName][$key])) {
$this->addListener($eventName, array($listener, $method), $priority);
} elseif ($listener !== $this->listeners[$eventName][$key]) {
parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
$this->addListener($eventName, array($listener, $method), $priority);
}
$this->listeners[$eventName][$key] = $listener;
}
}
}
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:25,代码来源:ContainerAwareEventDispatcher.php
示例6: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getArgument('path');
$stdin = false;
if ('-' === $path) {
$stdin = true;
// Can't write to STDIN
$input->setOption('dry-run', true);
}
if (null !== $path) {
$filesystem = new Filesystem();
if (!$filesystem->isAbsolutePath($path)) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
}
$configFile = $input->getOption('config-file');
if (null === $configFile) {
if (is_file($path) && ($dirName = pathinfo($path, PATHINFO_DIRNAME))) {
$configDir = $dirName;
} elseif ($stdin || null === $path) {
$configDir = getcwd();
// path is directory
} else {
$configDir = $path;
}
$configFile = $configDir . DIRECTORY_SEPARATOR . '.php_cs';
}
if ($input->getOption('config')) {
$config = null;
foreach ($this->fixer->getConfigs() as $c) {
if ($c->getName() === $input->getOption('config')) {
$config = $c;
break;
}
}
if (null === $config) {
throw new \InvalidArgumentException(sprintf('The configuration "%s" is not defined', $input->getOption('config')));
}
} elseif (file_exists($configFile)) {
$config = (include $configFile);
// verify that the config has an instance of Config
if (!$config instanceof Config) {
throw new \UnexpectedValueException(sprintf('The config file "%s" does not return an instance of Symfony\\CS\\Config\\Config', $configFile));
}
if ('txt' === $input->getOption('format')) {
$output->writeln(sprintf('Loaded config from "%s"', $configFile));
}
} else {
$config = $this->defaultConfig;
}
if ($config->usingLinter()) {
$this->fixer->setLintManager(new LintManager());
}
if (is_file($path)) {
$config->finder(new \ArrayIterator(array(new \SplFileInfo($path))));
} elseif ($stdin) {
$config->finder(new \ArrayIterator(array(new StdinFileInfo())));
} elseif (null !== $path) {
$config->setDir($path);
}
// register custom fixers from config
$this->fixer->registerCustomFixers($config->getCustomFixers());
$resolver = new ConfigurationResolver();
$resolver->setAllFixers($this->fixer->getFixers())->setConfig($config)->setOptions(array('level' => $input->getOption('level'), 'fixers' => $input->getOption('fixers'), 'progress' => $output->isVerbose() && 'txt' === $input->getOption('format')))->resolve();
$config->fixers($resolver->getFixers());
$showProgress = $resolver->getProgress();
if ($showProgress) {
$fileProcessedEventListener = function (FixerFileProcessedEvent $event) use($output) {
$output->write($event->getStatusAsString());
};
$this->fixer->setEventDispatcher($this->eventDispatcher);
$this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
}
$this->stopwatch->start('fixFiles');
$changed = $this->fixer->fix($config, $input->getOption('dry-run'), $input->getOption('diff'));
$this->stopwatch->stop('fixFiles');
if ($showProgress) {
$this->fixer->setEventDispatcher(null);
$this->eventDispatcher->removeListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
$output->writeln('');
$legend = array();
foreach (FixerFileProcessedEvent::getStatusMap() as $status) {
if ($status['symbol'] && $status['description']) {
$legend[] = $status['symbol'] . '-' . $status['description'];
}
}
$output->writeln('Legend: ' . implode(', ', array_unique($legend)));
}
$verbosity = $output->getVerbosity();
$i = 1;
switch ($input->getOption('format')) {
case 'txt':
foreach ($changed as $file => $fixResult) {
$output->write(sprintf('%4d) %s', $i++, $file));
if (OutputInterface::VERBOSITY_VERBOSE <= $verbosity) {
$output->write(sprintf(' (<comment>%s</comment>)', implode(', ', $fixResult['appliedFixers'])));
}
//.........这里部分代码省略.........
示例7: it_removes_listeners_from_the_symfony_dispathcer
/** @test */
public function it_removes_listeners_from_the_symfony_dispathcer()
{
$this->dispatcher->removeListener(static::EVENT, 'listener');
$this->symfony->removeListener(static::EVENT, 'listener')->shouldHaveBeenCalled();
}
示例8: __destruct
public function __destruct()
{
fclose($this->stdErr);
$this->eventDispatcher->removeListener(FixerFileProcessedEvent::NAME, array($this, 'onFixerFileProcessed'));
}
示例9: testWorkaroundForPhpBug62976
/**
* @see https://bugs.php.net/bug.php?id=62976
*
* This bug affects:
* - The PHP 5.3 branch for versions < 5.3.18
* - The PHP 5.4 branch for versions < 5.4.8
* - The PHP 5.5 branch is not affected
*/
public function testWorkaroundForPhpBug62976()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener('bug.62976', new CallableClass());
$dispatcher->removeListener('bug.62976', function () {
});
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
}
示例10: removeListener
/**
* Removes the callbacks assigned to database driver PubSub mechanism.
*
* @param string $channel
* @param callable $callback
*
* @return PubSubManager
*/
public function removeListener($channel, callable $callback)
{
$this->event_dispatcher->removeListener(static::generateEventName($channel), $callback);
return $this;
}
示例11: removeListener
/**
* @see EventDispatcher::removeListener
* @param string $eventName
* @param callable $listener
*/
public function removeListener($eventName, $listener)
{
$listenerName = "";
if (!empty($listener[0]) && is_object($listener[0])) {
$listenerName = get_class($listener[0]);
}
LoggerSphring::getInstance()->debug(sprintf("Remove listener '%s on event '%s'", $listenerName, $eventName));
parent::removeListener($eventName, $listener);
}
示例12: remove
/**
* @see AbstractDispatcherAdapter::remove
*/
public function remove($name, callable $listener)
{
$this->dispatcher->removeListener($name, $listener);
return $this;
}
示例13: execute
//.........这里部分代码省略.........
}
// remove/add fixers based on the fixers option
if (preg_match('{(^|,)-}', $input->getOption('fixers'))) {
foreach ($fixers as $key => $fixer) {
if (preg_match('{(^|,)-' . preg_quote($fixer->getName()) . '}', $input->getOption('fixers'))) {
unset($fixers[$key]);
}
}
} elseif ($input->getOption('fixers')) {
$names = array_map('trim', explode(',', $input->getOption('fixers')));
foreach ($allFixers as $fixer) {
if (in_array($fixer->getName(), $names, true) && !in_array($fixer, $fixers, true)) {
$fixers[] = $fixer;
}
}
}
$config->fixers($fixers);
$verbosity = $output->getVerbosity();
$listenForFixerFileProcessedEvent = OutputInterface::VERBOSITY_VERY_VERBOSE <= $verbosity;
if ($listenForFixerFileProcessedEvent) {
$fileProcessedEventListener = function (FixerFileProcessedEvent $event) use($output) {
$output->write($event->getStatusAsString());
};
}
if ($listenForFixerFileProcessedEvent) {
$this->fixer->setEventDispatcher($this->eventDispatcher);
$this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
}
$this->stopwatch->start('fixFiles');
$changed = $this->fixer->fix($config, $input->getOption('dry-run'), $input->getOption('diff'));
$this->stopwatch->stop('fixFiles');
if ($listenForFixerFileProcessedEvent) {
$this->fixer->setEventDispatcher(null);
$this->eventDispatcher->removeListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
$output->writeln('');
}
$i = 1;
switch ($input->getOption('format')) {
case 'txt':
foreach ($changed as $file => $fixResult) {
$output->write(sprintf('%4d) %s', $i++, $file));
if (OutputInterface::VERBOSITY_VERBOSE <= $verbosity) {
$output->write(sprintf(' (<comment>%s</comment>)', implode(', ', $fixResult['appliedFixers'])));
if ($input->getOption('diff')) {
$output->writeln('');
$output->writeln('<comment> ---------- begin diff ----------</comment>');
$output->writeln($fixResult['diff']);
$output->writeln('<comment> ---------- end diff ----------</comment>');
}
}
$output->writeln('');
}
if (OutputInterface::VERBOSITY_DEBUG <= $verbosity) {
$output->writeln('Fixing time per file:');
foreach ($this->stopwatch->getSectionEvents('fixFile') as $file => $event) {
if ('__section__' === $file) {
continue;
}
$output->writeln(sprintf('[%.3f s] %s', $event->getDuration() / 1000, $file));
}
$output->writeln('');
}
$fixEvent = $this->stopwatch->getEvent('fixFiles');
$output->writeln(sprintf('Fixed all files in %.3f seconds, %.3f MB memory used', $fixEvent->getDuration() / 1000, $fixEvent->getMemory() / 1024 / 1024));
break;
case 'xml':
示例14: removeListener
public function removeListener($eventName, $listener)
{
return $this->eventDispatcher->removeListener($eventName, $listener);
}
示例15: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// setup output
$stdErr = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : ('txt' === $input->getOption('format') ? $output : null);
if (null !== $stdErr && extension_loaded('xdebug')) {
$stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'You are running php-cs-fixer with xdebug enabled. This has a major impact on runtime performance.'));
}
$verbosity = $output->getVerbosity();
// setup input
$path = $input->getArgument('path');
$stdin = false;
if ('-' === $path) {
$stdin = true;
// Can't write to STDIN
$input->setOption('dry-run', true);
}
if (null !== $path) {
$filesystem = new Filesystem();
if (!$filesystem->isAbsolutePath($path)) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
}
// setup configuration location
$configFile = $input->getOption('config-file');
if (null === $configFile) {
$configDir = $path;
if (is_file($path) && ($dirName = pathinfo($path, PATHINFO_DIRNAME))) {
$configDir = $dirName;
} elseif ($stdin || null === $path) {
$configDir = getcwd();
// path is directory
}
$configFile = $configDir . DIRECTORY_SEPARATOR . '.php_cs';
}
if ($input->getOption('config')) {
$config = null;
foreach ($this->fixer->getConfigs() as $c) {
if ($c->getName() === $input->getOption('config')) {
$config = $c;
break;
}
}
if (null === $config) {
throw new InvalidConfigurationException(sprintf('The configuration "%s" is not defined.', $input->getOption('config')));
}
} elseif (file_exists($configFile)) {
$config = (include $configFile);
// verify that the config has an instance of Config
if (!$config instanceof ConfigInterface) {
throw new InvalidConfigurationException(sprintf('The config file "%s" does not return a "Symfony\\CS\\ConfigInterface" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config)));
}
if (null !== $stdErr && $configFile) {
$stdErr->writeln(sprintf('Loaded config from "%s".', $configFile));
}
} else {
$config = $this->defaultConfig;
}
// setup location of source(s) to fix
if (is_file($path)) {
$config->finder(new \ArrayIterator(array(new \SplFileInfo($path))));
} elseif ($stdin) {
$config->finder(new \ArrayIterator(array(new StdinFileInfo())));
} elseif (null !== $path) {
$config->setDir($path);
}
// setup Linter
if ($config->usingLinter()) {
$this->fixer->setLintManager(new LintManager());
}
// register custom fixers from config
$this->fixer->registerCustomFixers($config->getCustomFixers());
$resolver = new ConfigurationResolver();
$resolver->setAllFixers($this->fixer->getFixers())->setConfig($config)->setOptions(array('level' => $input->getOption('level'), 'fixers' => $input->getOption('fixers'), 'progress' => OutputInterface::VERBOSITY_VERBOSE <= $verbosity && 'txt' === $input->getOption('format'), 'format' => $input->getOption('format')))->resolve();
$config->fixers($resolver->getFixers());
$showProgress = null !== $stdErr && $resolver->getProgress();
if ($showProgress) {
$fileProcessedEventListener = function (FixerFileProcessedEvent $event) use($stdErr) {
$stdErr->write($event->getStatusAsString());
};
$this->fixer->setEventDispatcher($this->eventDispatcher);
$this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
}
$isDiff = $input->getOption('diff');
$this->stopwatch->start('fixFiles');
$changed = $this->fixer->fix($config, $input->getOption('dry-run'), $isDiff);
$this->stopwatch->stop('fixFiles');
if ($showProgress) {
$this->fixer->setEventDispatcher(null);
$this->eventDispatcher->removeListener(FixerFileProcessedEvent::NAME, $fileProcessedEventListener);
$stdErr->writeln('');
$legend = array();
foreach (FixerFileProcessedEvent::getStatusMap() as $status) {
if ($status['symbol'] && $status['description']) {
$legend[] = $status['symbol'] . '-' . $status['description'];
}
}
$stdErr->writeln('Legend: ' . implode(', ', array_unique($legend)));
//.........这里部分代码省略.........