本文整理匯總了PHP中Symfony\Component\EventDispatcher\Event::getResourceIdList方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::getResourceIdList方法的具體用法?PHP Event::getResourceIdList怎麽用?PHP Event::getResourceIdList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\EventDispatcher\Event
的用法示例。
在下文中一共展示了Event::getResourceIdList方法的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.
}
}