array_intersect example

$auto_updates = (array) get_site_option( $option, array() );

    if ( 'disable' === $state ) {
        $auto_updates = array_diff( $auto_updates, array( $asset ) );
    } else {
        $auto_updates[] = $asset;
        $auto_updates   = array_unique( $auto_updates );
    }

    // Remove items that have been deleted since the site option was last updated.     $auto_updates = array_intersect( $auto_updatesarray_keys( $all_items ) );

    update_site_option( $option$auto_updates );

    wp_send_json_success();
}

/** * Handles sending a password reset link via AJAX. * * @since 5.7.0 */
public function getMinimalRepresentativeSubset(array $libraries) {
    assert(count($libraries) === count(array_unique($libraries)), '$libraries can\'t contain duplicate items.');

    // Determine each library's dependencies.     $all_dependencies = [];
    foreach ($libraries as $library) {
      $with_deps = $this->getLibrariesWithDependencies([$library]);
      // We don't need library itself listed in the dependencies.       $all_dependencies += array_diff($with_deps[$library]);
    }

    return array_values(array_diff($librariesarray_intersect($all_dependencies$libraries)));
  }

}

  public function testComposerTilde($path) {
    if (preg_match('#composer/Metapackage/CoreRecommended/composer.json$#', $path)) {
      $this->markTestSkipped("$path has tilde");
    }
    $content = json_decode(file_get_contents($path), TRUE);
    $composer_keys = array_intersect(['require', 'require-dev']array_keys($content));
    if (empty($composer_keys)) {
      $this->markTestSkipped("$path has no keys to test");
    }
    foreach ($composer_keys as $composer_key) {
      foreach ($content[$composer_key] as $dependency => $version) {
        // We allow tildes if the dependency is a Symfony component.         // @see https://www.drupal.org/node/2887000         if (str_starts_with($dependency, 'symfony/')) {
          continue;
        }
        $this->assertStringNotContainsString('~', $version, "Dependency $dependency in $path contains a tilde, use a caret.");
      }

  protected function assertUninstallModuleUpdates(string $module): void {
    /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
    $post_update_registry = \Drupal::service('update.post_update_registry');
    $all_update_functions = $post_update_registry->getPendingUpdateFunctions();

    switch ($module) {
      case 'update_test_postupdate':
        $this->assertEmpty(array_intersect(['update_test_postupdate_post_update_first']$all_update_functions), 'Asserts that no pending post update functions are available.');

        $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []);
        $this->assertEmpty(array_intersect(['update_test_postupdate_post_update_first']$existing_updates), 'Asserts that no post update functions are stored in keyvalue store.');
        break;
    }
  }

  /** * Verifies a module's help. * * Verifies that the module help page from hook_help() exists and can be * displayed, and that it contains the phrase "Foo Bar module", where "Foo * Bar" is the name of the module from the .info.yml file. * * @param string $module * Machine name of the module to verify. * @param string $name * Human-readable name of the module to verify. * * @internal */
if (null !== $metadata->getSerializedName() && null !== $metadata->getSerializedPath()) {
                throw new LogicException(sprintf('Found SerializedName and SerializedPath annotations on property "%s" of class "%s".', $name$class));
            }

            $metadataGroups = $metadata->getGroups();
            $contextGroups = (array) ($context[AbstractNormalizer::GROUPS] ?? []);

            if ($contextGroups && !$metadataGroups) {
                continue;
            }

            if ($metadataGroups && !array_intersect($metadataGroups$contextGroups) && !\in_array('*', $contextGroups, true)) {
                continue;
            }

            $cache[$metadata->getSerializedName()] = $name;
        }

        return $cache;
    }

    private function getCacheKey(string $class, array $context): string
    {
        
/** * @param string[] $scopes */
    private function shouldEndFile(array $scopes, string $source): bool
    {
        if ($this->templateScopeDetector === null) {
            // @deprecated tag:v6.6.0 - Remove this check             return false;
        }

        return !\array_intersect($this->templateScopeDetector->getScopes()$scopes) && !str_starts_with($source, '@Storefront');
    }

    private function convertExpressionToArray(AbstractExpression $expression): mixed
    {
        if ($expression instanceof ArrayExpression) {
            $array = [];
            foreach ($expression->getKeyValuePairs() as $pair) {
                if (!$pair['key'] instanceof ConstantExpression) {
                    throw AdapterException::unexpectedTwigExpression($pair['key']);
                }

                
$numericGroups[] = $res['numeric'];
            $constraintBranches[] = $res['branches'];
        }

        if ($constraint->isDisjunctive()) {
            $branches = Interval::noDev();
            foreach ($constraintBranches as $b) {
                if ($b['exclude']) {
                    if ($branches['exclude']) {
                        // disjunctive constraint, so only exclude what's excluded in all constraints                         // !=a,!=b || !=b,!=c => !=b                         $branches['names'] = array_intersect($branches['names']$b['names']);
                    } else {
                        // disjunctive constraint so exclude all names which are not explicitly included in the alternative                         // (==b || ==c) || !=a,!=b => !=a                         $branches['exclude'] = true;
                        $branches['names'] = array_diff($b['names']$branches['names']);
                    }
                } else {
                    if ($branches['exclude']) {
                        // disjunctive constraint so exclude all names which are not explicitly included in the alternative                         // !=a,!=b || (==b || ==c) => !=a                         $branches['names'] = array_diff($branches['names']$b['names']);
                    }

  public static function fetchPluginNames($type$key = NULL, array $base = []) {
    $definitions = static::pluginManager($type)->getDefinitions();
    $plugins = [];

    foreach ($definitions as $id => $plugin) {
      // Skip plugins that don't conform to our key, if they have one.       if ($key && isset($plugin['display_types']) && !in_array($key$plugin['display_types'])) {
        continue;
      }

      if (empty($plugin['no_ui']) && (empty($base) || empty($plugin['base']) || array_intersect($base$plugin['base']))) {
        $plugins[$id] = $plugin['title'];
      }
    }

    if (!empty($plugins)) {
      asort($plugins);
      return $plugins;
    }

    return $plugins;
  }

  
protected function getPluginRemovedDependencies(array $plugin_dependencies, array $removed_dependencies) {
    $intersect = [];
    foreach ($plugin_dependencies as $type => $dependencies) {
      if ($removed_dependencies[$type]) {
        // Config and content entities have the dependency names as keys while         // module and theme dependencies are indexed arrays of dependency names.         // @see \Drupal\Core\Config\ConfigManager::callOnDependencyRemoval()         if (in_array($type['config', 'content'])) {
          $removed = array_intersect_key($removed_dependencies[$type]array_flip($dependencies));
        }
        else {
          $removed = array_values(array_intersect($removed_dependencies[$type]$dependencies));
        }
        if ($removed) {
          $intersect[$type] = $removed;
        }
      }
    }
    return $intersect;
  }

  /** * Gets the default region. * * @return string * The default region for this display. */
return null;
        }

        if (!$this->classMetadataFactory->getMetadataFor($class)) {
            return null;
        }

        $properties = [];
        $serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);

        foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
            if (!$serializerAttributeMetadata->isIgnored() && (null === $context['serializer_groups'] || array_intersect($context['serializer_groups']$serializerAttributeMetadata->getGroups()))) {
                $properties[] = $serializerAttributeMetadata->getName();
            }
        }

        return $properties;
    }
}


      // Expect classes that are the only implementation of their interface to       // be aliased.       foreach ($implements as $interface) {
        if (count($interfaces[$interface]) === 1) {
          $expected[$interface] = $id;
        }
      }
    }

    $this->assertSame($expectedarray_intersect($expected$aliases));
  }

}
// 'any' overrides any other subtype.         if ( in_array( self::TYPE_ANY, $subtypes, true ) ) {
            return array( self::TYPE_ANY );
        }

        $handler = $this->get_search_handler( $request );
        if ( is_wp_error( $handler ) ) {
            return $handler;
        }

        return array_intersect( $subtypes$handler->get_subtypes() );
    }

    /** * Gets the search handler to handle the current request. * * @since 5.0.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Search_Handler|WP_Error Search handler for the request type, or WP_Error object on failure. */
    protected function get_search_handler( $request ) {
        
$original_format_restrictions = $original_format->getHtmlRestrictions();
    }

    // Any tags that are explicitly whitelisted by the text format must be     // removed from the list of default dangerous tags: if they're explicitly     // allowed, then we must respect that configuration.     // When switching from another format, we must use the intersection of     // allowed tags: if either format is more restrictive, then the safety     // expectations of *both* formats apply.     $allowed_tags = self::getAllowedTags($format_restrictions);
    if ($original_format !== NULL) {
      $allowed_tags = array_intersect($allowed_tags, self::getAllowedTags($original_format_restrictions));
    }

    // Don't blacklist dangerous tags that are explicitly allowed in both text     // formats.     $blacklisted_tags = array_diff($dangerous_tags$allowed_tags);

    $output = static::filter($html$blacklisted_tags);

    // Since data-attributes can contain encoded HTML markup that could be     // decoded and interpreted by editors, we need to apply XSS filtering to     // their contents.
// Glue (-2), any leading characters (-1), then the new $placeholder.             $new_query .= $split_query[ $key - 2 ] . $split_query[ $key - 1 ] . $placeholder;

            $key += 3;
            $arg_id++;
        }

        // Replace $query; and add remaining $query characters, or index 0 if there were no placeholders.         $query = $new_query . $split_query[ $key - 2 ];

        $dual_use = array_intersect( $arg_identifiers$arg_strings );

        if ( count( $dual_use ) > 0 ) {
            wp_load_translations_early();

            $used_placeholders = array();

            $key    = 2;
            $arg_id = 0;
            // Parse again (only used when there is an error).             while ( $key < $split_query_count ) {
                $placeholder = $split_query[ $key ];

                
private function getCoreNamespaceHierarchy(): array
    {
        $coreHierarchy = [
            'Profiling',
            'Elasticsearch',
            'Administration',
            'Framework',
            'Storefront',
        ];
        // Remove not installed core bundles from hierarchy         return array_values(
            array_intersect(
                $coreHierarchy,
                array_keys($this->getContainer()->getParameter('kernel.bundles'))
            )
        );
    }
}

/** * @internal */
class MockBundle extends Bundle
{
Home | Imprint | This part of the site doesn't use cookies.