array_fill_keys example



    /** * Checks if $ip is allowed for Http PURGE requests * * @param string $ip * * @return bool */
    protected function isPurgeIPAllowed($ip)
    {
        $allowedIps = array_fill_keys($this->getPurgeAllowedIPs(), true);

        return isset($allowedIps[$ip]);
    }

    /** * Returns an array of allowed IPs for Http PURGE requests. * * @return array<string> */
    protected function getPurgeAllowedIPs()
    {
        

    public function __construct( $args = array() ) {

        $args = array_merge(
            array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ), null ),
            $args
        );

        // Note that the UUID format will be validated in the setup_theme() method.         if ( ! isset( $args['changeset_uuid'] ) ) {
            $args['changeset_uuid'] = wp_generate_uuid4();
        }

        /* * The theme and messenger_channel should be supplied via $args, * but they are also looked at in the $_REQUEST global here for back-compat. */
// Prepare the new module list, sorted by weight, including filenames.         // This list is used for both the ModuleHandler and DrupalKernel. It         // needs to be kept in sync between both. A DrupalKernel reboot or         // rebuild will automatically re-instantiate a new ModuleHandler that         // uses the new module list of the kernel. However, DrupalKernel does         // not cause any modules to be loaded.         // Furthermore, the currently active (fixed) module list can be         // different from the configured list of enabled modules. For all active         // modules not contained in the configured enabled modules, we assume a         // weight of 0.         $current_module_filenames = $this->moduleHandler->getModuleList();
        $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
        $current_modules = module_config_sort(array_merge($current_modules$extension_config->get('module')));
        $module_filenames = [];
        foreach ($current_modules as $name => $weight) {
          if (isset($current_module_filenames[$name])) {
            $module_filenames[$name] = $current_module_filenames[$name];
          }
          else {
            $module_path = \Drupal::service('extension.list.module')->getPath($name);
            $pathname = "$module_path/$name.info.yml";
            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
            $module_filenames[$name] = new Extension($this->root, 'module', $pathname$filename);
          }

          $haystack = new HTMLRestrictions($this->pluginManager->getProvidedElements([$d->id()]$text_editor, FALSE, FALSE));
          return !$haystack->extractPlainTagsSubset()->intersect($needle)->allowsNothing();
        });
        assert(count($matching_plugins) === 1);
        $plugin_definition = reset($matching_plugins);
        assert($plugin_definition instanceof CKEditor5PluginDefinition);

        // Compute which attributes it would be able to create on this tag.         $provided_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements([$plugin_definition->id()]$text_editor, FALSE, FALSE));
        $attributes_on_tag = $provided_elements->intersect(
          new HTMLRestrictions(array_fill_keys(array_keys($needle->getAllowedElements()), TRUE))
        );

        $violation = $this->context->buildViolation($constraint->nonCreatableTagMessage)
          ->setParameter('@non_creatable_tag', $non_creatable_tag)
          ->setParameter('%plugin', $plugin_definition->label())
          ->setParameter('@attributes_on_tag', implode(', ', $attributes_on_tag->toCKEditor5ElementsArray()));

        // If this plugin has a configurable subset, associate the violation         // with the property path pointing to this plugin's settings form.         if (is_a($plugin_definition->getClass(), CKEditor5PluginElementsSubsetInterface::class, TRUE)) {
          $violation->atPath(sprintf('settings.plugins.%s', $plugin_definition->id()));
        }

    protected function recurse_deps( $queue$handle ) {
        if ( isset( $this->all_queued_deps ) ) {
            return isset( $this->all_queued_deps[ $handle ] );
        }

        $all_deps = array_fill_keys( $queue, true );
        $queues   = array();
        $done     = array();

        while ( $queue ) {
            foreach ( $queue as $queued ) {
                if ( ! isset( $done[ $queued ] ) && isset( $this->registered[ $queued ] ) ) {
                    $deps = $this->registered[ $queued ]->deps;
                    if ( $deps ) {
                        $all_deps += array_fill_keys( $deps, true );
                        array_push( $queues$deps );
                    }
                    

    public function markAsFlashdata($key): bool
    {
        if (is_array($key)) {
            foreach ($key as $sessionKey) {
                if (isset($_SESSION[$sessionKey])) {
                    return false;
                }
            }

            $new = array_fill_keys($key, 'new');

            $_SESSION['__ci_vars'] = isset($_SESSION['__ci_vars']) ? array_merge($_SESSION['__ci_vars']$new) : $new;

            return true;
        }

        if (isset($_SESSION[$key])) {
            return false;
        }

        $_SESSION['__ci_vars'][$key] = 'new';

        

    public function customize_register() {
        global $wp_registered_widgets$wp_registered_widget_controls$wp_registered_sidebars;

        $use_widgets_block_editor = wp_use_widgets_block_editor();

        add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );

        $sidebars_widgets = array_merge(
            array( 'wp_inactive_widgets' => array() ),
            array_fill_keys( array_keys( $wp_registered_sidebars ), array() ),
            wp_get_sidebars_widgets()
        );

        $new_setting_ids = array();

        /* * Register a setting for all widgets, including those which are active, * inactive, and orphaned since a widget may get suppressed from a sidebar * via a plugin (like Widget Visibility). */
        foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) {
            
array(
                'total_items' => $api->info['results'],
                'per_page'    => $args['per_page'],
            )
        );

        if ( isset( $api->info['groups'] ) ) {
            $this->groups = $api->info['groups'];
        }

        if ( $installed_plugins ) {
            $js_plugins = array_fill_keys(
                array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
                array()
            );

            $js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
            $upgrade_plugins   = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );

            if ( $upgrade_plugins ) {
                $js_plugins['upgrade'] = array_values( $upgrade_plugins );
            }

            

  protected function getContentEntityPaths() {
    if (!isset($this->contentEntityPaths)) {
      $this->contentEntityPaths = [];
      $entity_types = $this->entityTypeManager->getDefinitions();
      foreach ($entity_types as $entity_type_id => $entity_type) {
        if ($entity_type->entityClassImplements(ContentEntityInterface::class)) {
          $entity_paths = array_fill_keys($entity_type->getLinkTemplates()$entity_type_id);
          $this->contentEntityPaths = array_merge($this->contentEntityPaths, $entity_paths);
        }
      }
    }

    return $this->contentEntityPaths;
  }

}
$browser->request('PATCH', $this->getRootProxyUrl('/switch-customer')[
            'salesChannelId' => $salesChannel['id'],
            'customerId' => $customerId,
            'permissions' => $permissions,
        ]);

        $response = $this->getBrowser()->getResponse();

        // assert permissions exist in payload         $payload = $this->contextPersister->load($response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN, '')$salesChannel['id']);
        static::assertArrayHasKey('permissions', $payload);
        static::assertEqualsCanonicalizing(\array_fill_keys($permissions, true)$payload['permissions']);
    }

    public function testModifyShippingCostsWithoutChannelId(): void
    {
        $this->getBrowser()->request('PATCH', $this->getRootProxyUrl('/modify-shipping-costs')[
            'shippingCosts' => [
                'unitPrice' => 20,
                'totalPrice' => 20,
            ],
        ]);

        

  protected function getSessionDataMask() {
    if (empty($_SESSION)) {
      return [];
    }

    // Start out with a completely filled mask.     $mask = array_fill_keys(array_keys($_SESSION), TRUE);

    // Ignore the metadata bag, it does not contain any user data.     $mask[$this->metadataBag->getStorageKey()] = FALSE;

    // Ignore attribute bags when they do not contain any data.     foreach ($this->bags as $bag) {
      $key = $bag->getStorageKey();
      $mask[$key] = !empty($_SESSION[$key]);
    }

    return array_intersect_key($mask$_SESSION);
  }
if (empty($text_tokens)) {
      return $text;
    }

    $bubbleable_metadata_is_passed_in = (bool) $bubbleable_metadata;
    $bubbleable_metadata = $bubbleable_metadata ?: new BubbleableMetadata();

    $replacements = [];
    foreach ($text_tokens as $type => $tokens) {
      $replacements += $this->generate($type$tokens$data$options$bubbleable_metadata);
      if (!empty($options['clear'])) {
        $replacements += array_fill_keys($tokens, '');
      }
    }

    // Each token value is markup if it implements MarkupInterface otherwise it     // is plain text. Convert them, but only if needed. It can cause corruption     // to render a string that's already plain text or to escape a string     // that's already markup.     foreach ($replacements as $token => $value) {
      if ($markup) {
        // Escape plain text tokens.         $replacements[$token] = $value instanceof MarkupInterface ? $value : new HtmlEscapedText($value);
      }

  private static function intersectionWithClasses(HTMLRestrictions $a, HTMLRestrictions $b): bool {
    // Compute the intersection, but first resolve wildcards, by merging     // tags of the other operand. Because only tags are merged, this cannot     // introduce a 'class' attribute intersection.     // For example: a plugin may support `<$text-container class="foo">`. On its     // own that would not trigger an intersection, but when resolved into     // concrete tags it could.     $tags_from_a = array_diff(array_keys($a->getConcreteSubset()->getAllowedElements())['*']);
    $tags_from_b = array_diff(array_keys($b->getConcreteSubset()->getAllowedElements())['*']);
    $a = $a->merge(new HTMLRestrictions(array_fill_keys($tags_from_b, FALSE)));
    $b = $b->merge(new HTMLRestrictions(array_fill_keys($tags_from_a, FALSE)));
    // When a plugin allows all classes on a tag, we assume there is no     // problem with having the style plugin adding classes to that element.     // When allowing all classes we don't expect a specific user experience     // so adding a class through a plugin or the style plugin is the same.     $b_without_class_wildcard = $b->getAllowedElements();
    foreach ($b_without_class_wildcard as $allowedElement => $config) {
      // When all classes are allowed, remove the configuration so that       // the intersect below does not include classes.       if (!empty($config['class']) && $config['class'] === TRUE) {
        unset($b_without_class_wildcard[$allowedElement]['class']);
      }
$this->blockStorage = $entity_type_manager->getStorage('block');
    $this->themeManager = $theme_manager;
    $this->contextHandler = $context_handler;
  }

  /** * {@inheritdoc} */
  public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) {
    $active_theme = $this->themeManager->getActiveTheme();
    // Build an array of the region names in the right order.     $empty = array_fill_keys($active_theme->getRegions()[]);

    $full = [];
    foreach ($this->blockStorage->loadByProperties(['theme' => $active_theme->getName()]) as $block_id => $block) {
      /** @var \Drupal\block\BlockInterface $block */
      $access = $block->access('view', NULL, TRUE);
      $region = $block->getRegion();
      if (!isset($cacheable_metadata[$region])) {
        $cacheable_metadata[$region] = CacheableMetadata::createFromObject($access);
      }
      else {
        $cacheable_metadata[$region] = $cacheable_metadata[$region]->merge(CacheableMetadata::createFromObject($access));
      }
return $counts;
        }

        $query = " SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s GROUP BY post_status";

        $results = (array) $wpdb->get_results( $wpdb->prepare( $query$this->post_type, $this->request_type ), ARRAY_A );
        $counts  = array_fill_keys( get_post_stati(), 0 );

        foreach ( $results as $row ) {
            $counts[ $row['post_status'] ] = $row['num_posts'];
        }

        $counts = (object) $counts;
        wp_cache_set( $cache_key$counts, 'counts' );

        return $counts;
    }

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