array_flip example

/** * {@inheritdoc} * * The IDs can collide in two different scenarios: * * 1. Because one component is overriding another one via "weight". * 2. Because the same component exists in different themes. */
  protected function getIdentifier($file, array $data): string {
    $id = $this->fileSystem->basename($file, '.component.yml');
    $provider_paths = array_flip($this->directories);
    $provider = $this->findProvider($file$provider_paths);
    // We use the provider to dedupe components because it does not make sense     // for a single provider to fork itself.     return sprintf('%s:%s', $provider$id);
  }

  /** * Finds the provider of the discovered file. * * The approach here is suboptimal because the provider is actually set in * the plugin definition after the getIdentifier is called. So we either do * this, or we forego the base class. * * @param string $file * The discovered file. * @param array $provider_paths * The associative array of the path to the provider. * * @return string * The provider */
'active',
            'esdActive',
            'mobileInactive',
            'hideProspect',
            'action',
            'pluginId',
            'countries',
            'shops',
            'attribute',
        ];

        $params = array_intersect_key($paramsarray_flip($paymentWhiteList));

        if (isset($params['countries'])) {
            foreach ($params['countries'] as &$country) {
                $countryModel = $this->getContainer()->get(\Shopware\Components\Model\ModelManager::class)->find(CountryModel::class$country['countryId']);
                if (!$countryModel) {
                    throw new ApiException\NotFoundException(sprintf('Country by id %d not found', $country['countryId']));
                }

                $country = $countryModel;

                unset($country);
            }

    public function addRow()
    {
        $tmpRow = $this->_prepArgs(func_get_args());

        if ($this->syncRowsWithHeading && ! empty($this->heading)) {
            // each key has an index             $keyIndex = array_flip(array_keys($this->heading));

            // figure out which keys need to be added             $missingKeys = array_diff_key($keyIndex$tmpRow);

            // Remove all keys which don't exist in $keyIndex             $tmpRow = array_filter($tmpRowstatic fn ($k) => array_key_exists($k$keyIndex), ARRAY_FILTER_USE_KEY);

            // add missing keys to row, but use $this->emptyCells             $tmpRow = array_merge($tmpRowarray_map(fn ($v) => ['data' => $this->emptyCells]$missingKeys));

            // order keys by $keyIndex values
$entity_type_id = $resource_type->getEntityTypeId();
    $entity_type_definition = $this->entityTypeManager->getDefinition($entity_type_id);
    $bundle_key = $entity_type_definition->getKey('bundle');
    $uuid_key = $entity_type_definition->getKey('uuid');

    // User resource objects contain a read-only attribute that is not a real     // field on the user entity type.     // @see \Drupal\jsonapi\JsonApiResource\ResourceObject::extractContentEntityFields()     // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.     if ($entity_type_id === 'user') {
      $data = array_diff_key($dataarray_flip([$resource_type->getPublicName('display_name')]));
    }

    // Translate the public fields into the entity fields.     foreach ($data as $public_field_name => $field_value) {
      $internal_name = $resource_type->getInternalName($public_field_name);

      // Skip any disabled field, except the always required bundle key and       // required-in-case-of-PATCHing uuid key.       // @see \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getFieldMapping()       if ($resource_type->hasField($internal_name) && !$resource_type->isFieldEnabled($internal_name) && $bundle_key !== $internal_name && $uuid_key !== $internal_name) {
        continue;
      }


    /** * Sets values as environment variables (via putenv, $_ENV, and $_SERVER). * * @param array $values An array of env variables * @param bool $overrideExistingVars true when existing environment variables must be overridden */
    public function populate(array $values, bool $overrideExistingVars = false): void
    {
        $updateLoadedVars = false;
        $loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));

        foreach ($values as $name => $value) {
            $notHttpName = !str_starts_with($name, 'HTTP_');
            if (isset($_SERVER[$name]) && $notHttpName && !isset($_ENV[$name])) {
                $_ENV[$name] = $_SERVER[$name];
            }

            // don't check existence with getenv() because of thread safety issues             if (!isset($loadedVars[$name]) && !$overrideExistingVars && isset($_ENV[$name])) {
                continue;
            }

            
// Ensure that the weights are integers.     $enabled_methods = array_map('intval', $enabled_methods);

    // Order the language negotiation method list by weight.     asort($enabled_methods);
    foreach ($enabled_methods as $method_id => $weight) {
      if (isset($definitions[$method_id])) {
        $method = $definitions[$method_id];
        // If the language negotiation method does not express any preference         // about types, make it available for any configurable type.         $types = array_flip(!empty($method['types']) ? $method['types'] : $default_types);
        // Check whether the method is defined and has the right type.         if (!isset($types[$type])) {
          unset($enabled_methods[$method_id]);
        }
      }
      else {
        unset($enabled_methods[$method_id]);
      }
    }
    $this->configFactory->getEditable('language.types')->set('negotiation.' . $type . '.enabled', $enabled_methods)->save(TRUE);
  }

  

    private function mapCategories(array $mapping): array
    {
        $categoryIds = array_filter(explode('|', (string) $mapping['ids']));
        $categoryIds = array_merge(
            explode('|', (string) $mapping['paths']),
            $categoryIds
        );

        $categoryIds = array_map('strtolower', $categoryIds);

        return array_keys(array_flip(array_filter($categoryIds)));
    }
}

        return $this->ids[$key];
    }

    public function create(string $key): string
    {
        return $this->ids[$key] = Uuid::randomHex();
    }

    public function getList(array $keys): array
    {
        $keys = array_flip($keys);

        return array_intersect_key($this->ids, $keys);
    }

    public function getAll(): array
    {
        return $this->ids;
    }
}

/** * @internal */
    // access the display name of a user. For example, this is useful when     // displaying the name of a node's author.     // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.     $entity_type = $entity->getEntityType();
    if ($entity_type->id() == 'user' && $resource_type->isFieldEnabled('display_name')) {
      assert($entity instanceof UserInterface);
      $display_name = $resource_type->getPublicName('display_name');
      $output[$display_name] = $entity->getDisplayName();
    }

    // Return a sub-array of $output containing the keys in $enabled_fields.     $input = array_intersect_key($fieldsarray_flip($enabled_field_names));
    foreach ($input as $field_name => $field_value) {
      $public_field_name = $resource_type->getPublicName($field_name);
      $output[$public_field_name] = $field_value;
    }

    return $output;
  }

  /** * Determines the entity type's (internal) label field name. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity from which fields should be extracted. * * @return string * The label field name. */

    $considered_themes = [$theme_name, ...$base_theme_names];
    // Only consider components in the theme hierarchy tree.     $candidates = array_filter(
      $candidates,
      static fn(array $definition) => $definition['extension_type'] === ExtensionType::Theme
        && in_array($definition['provider']$considered_themes, TRUE)
    );
    if (empty($candidates)) {
      return NULL;
    }
    $theme_weights = array_flip($considered_themes);
    $sort_by_theme_weight = static fn(array $definition_a, array $definition_b) =>
      $theme_weights[$definition_a['provider']] <=> $theme_weights[$definition_b['provider']];
    // Sort the candidates by weight and choose the one with the lowest weight.     uasort($candidates$sort_by_theme_weight);
    $definition = reset($candidates);
    return $definition['id'] ?? NULL;
  }

  /** * Negotiate the component from the list of candidates for a module. * * @param array[] $candidates * The candidate definitions. * * @return string|null * The negotiated plugin ID, or NULL if none found. */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->entityDefinitionUpdateManager = $this->container->get('entity.definition_update_manager');
    $this->entityFieldManager = $this->container->get('entity_field.manager');
    $this->database = $this->container->get('database');

    // Install every entity type's schema that wasn't installed in the parent     // method.     foreach (array_diff_key($this->entityTypeManager->getDefinitions()array_flip(['user', 'entity_test'])) as $entity_type_id => $entity_type) {
      $this->installEntitySchema($entity_type_id);
    }
  }

  /** * Tests that new entity type definitions are correctly handled. */
  public function testNewEntityType() {
    $entity_type_id = 'entity_test_new';
    $schema = $this->database->schema();

    


            if ("\n" === $proxyCode = "\n".$proxyDumper->getProxyCode($definition$id)) {
                continue;
            }

            if ($this->inlineRequires) {
                $lineage = [];
                $this->collectLineage($class$lineage);

                $code = '';
                foreach (array_diff_key(array_flip($lineage)$this->inlinedRequires) as $file => $class) {
                    if ($this->inlineFactories) {
                        $this->inlinedRequires[$file] = true;
                    }
                    $code .= sprintf("include_once %s;\n", $file);
                }

                $proxyCode = $code.$proxyCode;
            }

            if ($strip) {
                $proxyCode = "<?php\n".$proxyCode;
                
/** * Returns an array of info files information of installed extensions. * * This function returns the processed contents (with added defaults) of the * .info.yml files. * * @return array[] * An associative array of extension information arrays, keyed by extension * name. */
  public function getAllInstalledInfo() {
    return array_intersect_key($this->getAllAvailableInfo()array_flip($this->getInstalledExtensionNames()));
  }

  /** * Generates the information from .info.yml files for extensions of this type. * * @return array[] * An array of arrays of .info.yml entries keyed by the machine name. */
  protected function recalculateInfo() {
    return array_map(function DExtension $extension) {
      return $extension->info;
    },

  public function getCacheTags() {
    return [];
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    $formats = $this->getFormats();
    $providers = array_intersect_key($this->formatProviders, array_flip($formats));
    // The plugin always uses services from the serialization module.     $providers[] = 'serialization';

    $dependencies += ['module' => []];
    $dependencies['module'] = array_merge($dependencies['module']$providers);
    return $dependencies;
  }

  /** * Returns an array of format options. * * @return string[] * An array of format options. Both key and value are the same. */
    $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session']$expected_cacheability->getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';
    $this->assertResourceResponse(200, $expected_document$response$expected_cacheability->getCacheTags()$expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache);

    // If the response should vary by a user's authorizations, grant permissions     // for the included resources and execute another request.     $permission_related_cache_contexts = [
      'user',
      'user.permissions',
      'user.roles',
    ];
    if (!empty($relationship_field_names) && !empty(array_intersect($expected_cacheability->getCacheContexts()$permission_related_cache_contexts))) {
      $applicable_permissions = array_intersect_key(static::getIncludePermissions()array_flip($relationship_field_names));
      $flattened_permissions = array_unique(array_reduce($applicable_permissions, 'array_merge', []));
      $this->grantPermissionsToTestedRole($flattened_permissions);
      $expected_response = $this->getExpectedCollectionResponse($filtered_entity_collection$filtered_collection_include_url->toString()$request_options$relationship_field_names, TRUE);
      $expected_cacheability = $expected_response->getCacheableMetadata();
      $expected_document = $expected_response->getResponseData();
      $response = $this->request('GET', $filtered_collection_include_url$request_options);
      $requires_include_only_permissions = !empty($flattened_permissions);
      $uncacheable = $expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session']$expected_cacheability->getCacheContexts()));
      $dynamic_cache = !$uncacheable ? $requires_include_only_permissions ? 'MISS' : 'HIT' : 'UNCACHEABLE';
      $this->assertResourceResponse(200, $expected_document$response$expected_cacheability->getCacheTags()$expected_cacheability->getCacheContexts(), FALSE, $dynamic_cache);
    }

    
Home | Imprint | This part of the site doesn't use cookies.