本文整理汇总了PHP中Symfony\Component\EventDispatcher\Event::shouldKeepDefaultChan方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::shouldKeepDefaultChan方法的具体用法?PHP Event::shouldKeepDefaultChan怎么用?PHP Event::shouldKeepDefaultChan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\Event
的用法示例。
在下文中一共展示了Event::shouldKeepDefaultChan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEvent
/**
* Handle any event
*
* If this method does not fit to your need, you are advised to extend this
* class and modify this method to suit your own needs
*
* @param string $resourceType
* @param string $action
* @param Event $event
*/
protected function onEvent($resourceType, $action, Event $event)
{
$idList = null;
$data = null;
$key = $resourceType . ':' . $action;
$sendOnDefaultChan = true;
$additionalChanId = [];
if ($event instanceof ResourceEvent) {
$data = $event->getArguments();
$idList = $event->getResourceIdList();
$additionalChanId = $event->getChanIdList();
$sendOnDefaultChan = $event->shouldKeepDefaultChan();
} else {
if ($event instanceof GenericEvent) {
$data = $event->getArguments();
// Attempt to do a best guess at the resource identifier
if (isset($event['id'])) {
$idList = [$event['id']];
} else {
$subject = $event->getSubject();
if (is_scalar($subject)) {
$idList = [$subject];
} else {
if (method_exists($subject, 'getId')) {
$idList = [$subject->getId()];
} else {
if (property_exists($subject, 'id')) {
$idList = [$subject->id];
}
}
}
}
}
}
if (isset($idList)) {
// Proceed with pre-configured overrides
if ($sendOnDefaultChan && isset($this->chanBlockingOverrides[$key])) {
$additionalChanId = array_merge($additionalChanId, $this->chanBlockingOverrides[$key]);
// FIXME override should not be blocking default chans
// @TODO add a blocking boolean tag attribute (false by default)
// $sendOnDefaultChan = false;
}
if ($additionalChanId) {
foreach ($idList as $id) {
if ($sendOnDefaultChan) {
$additionalChanId[] = $this->service->getChanId($resourceType, $id);
}
$this->service->notifyChannel($additionalChanId, $resourceType, $id, $action, $data);
}
} else {
if ($sendOnDefaultChan) {
foreach ($idList as $id) {
$this->service->notify($resourceType, $id, $action, $data);
}
}
}
// We might end up sending nothing, as soon as any of the listeners
// explicitly forbid to send on the default chan, and we have no
// additional chans.
}
}