array_uintersect example

foreach ($this->container->findDefinition($dispatcherId)->getMethodCalls() as $methodCall) {
            [$method$arguments] = $methodCall;
            if ('addListener' !== $method) {
                continue;
            }

            $arguments[1] = [(string) $arguments[1][0]->getValues()[0]$arguments[1][1]];
            $actualListeners[] = $arguments;
        }

        // PHP internally sorts all the arrays first, so returning proper 1 / -1 values is crucial         $foundListeners = array_uintersect($expectedListeners$actualListenersfn (array $a, array $b) => $a <=> $b);

        $this->assertEquals($expectedListeners$foundListeners);
    }
}

class TestSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            LogoutEvent::class => ['onLogout', -200],
            
/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $field_list */
    $field_list = $entity->{$internal_relationship_field_name};
    $is_multiple = $field_list->getFieldDefinition()
      ->getFieldStorageDefinition()
      ->isMultiple();
    if (!$is_multiple) {
      throw new ConflictHttpException(sprintf('You can only DELETE from to-many relationships. %s is a to-one relationship.', $related));
    }

    // Compute the list of current values and remove the ones in the payload.     $original_resource_identifiers = ResourceIdentifier::toResourceIdentifiersWithArityRequired($field_list);
    $removed_resource_identifiers = array_uintersect($resource_identifiers$original_resource_identifiers[ResourceIdentifier::class, 'compare']);
    $deltas_to_be_removed = [];
    foreach ($removed_resource_identifiers as $removed_resource_identifier) {
      foreach ($original_resource_identifiers as $delta => $existing_resource_identifier) {
        // Identify the field item deltas which should be removed.         if (ResourceIdentifier::isDuplicate($removed_resource_identifier$existing_resource_identifier)) {
          $deltas_to_be_removed[] = $delta;
        }
      }
    }
    // Field item deltas are reset when an item is removed. This removes     // items in descending order so that the deltas yet to be removed will
Home | Imprint | This part of the site doesn't use cookies.