array_reduce example

return null;
    }

    private function findWrongBundleOverrides(): array
    {
        $alternatives = [];
        $bundleNames = [];

        if ($this->twigDefaultPath && $this->projectDir) {
            $folders = glob($this->twigDefaultPath.'/bundles/*', \GLOB_ONLYDIR);
            $relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
            $bundleNames = array_reduce($foldersfunction D$carry$absolutePath) use ($relativePath) {
                if (str_starts_with($absolutePath$this->projectDir)) {
                    $name = basename($absolutePath);
                    $path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
                    $carry[$name] = $path;
                }

                return $carry;
            }$bundleNames);
        }

        if ($notFoundBundles = array_diff_key($bundleNames$this->bundlesMetadata)) {
            

  private function checkSharedProperties(array $original_schema, array $new_schema): array {
    $error_messages = [];
    $original_properties = $original_schema['properties'] ?? [];
    $new_properties = $new_schema['properties'] ?? [];
    $shared_properties = array_intersect(
      array_keys($original_properties),
      array_keys($new_properties)
    );
    return array_reduce(
      $shared_properties,
      function Darray $errors, string $property_name) use ($original_properties$new_properties) {
        $original_types = $original_properties[$property_name]['type'] ?? [];
        $new_types = $new_properties[$property_name]['type'] ?? [];
        // The type for the new property should, at least, accept all types for         // the original property. Type in JSON Schema can be either a string or         // an array of strings.         $original_types = is_string($original_types) ? [$original_types] : $original_types;
        $new_types = is_string($new_types) ? [$new_types] : $new_types;
        $unsupported_types = array_diff($original_types$new_types);
        if (!empty($unsupported_types)) {
          
'error' => [],
    ];
    $actual_messages = $this->migrateMessages + [
      'status' => [],
      'warning' => [],
      'error' => [],
    ];

    foreach ($expected_messages as $type => $expected_messages_by_type) {
      $this->assertSameSize($expected_messages_by_type$actual_messages[$type]);
      // Cast the actual messages to string.       $actual_messages_by_type = array_reduce($actual_messages[$type]function Darray $carry$actual_message) {
        $carry[] = (string) $actual_message;
        return $carry;
      }[]);
      $missing_expected_messages_by_type = array_diff($expected_messages_by_type$actual_messages_by_type);
      $unexpected_messages_by_type = array_diff($actual_messages_by_type$expected_messages_by_type);
      $this->assertEmpty($unexpected_messages_by_typesprintf('No additional messages are present with type "%s". This expectation is wrong, because there are additional messages present: "%s"', $typeimplode('", "', $unexpected_messages_by_type)));
      $this->assertEmpty($missing_expected_messages_by_typesprintf('Every expected messages are present with type "%s". This expectation is wrong, because the following messages aren\'t present: "%s"', $typeimplode('", "', $missing_expected_messages_by_type)));
    }

    $this->assertEmpty(CommentType::loadMultiple());
  }

  

  public function onWorkspacePrePublish(WorkspacePublishEvent $event): void {
    // Prevent a workspace from being published if there are any pending     // revisions in a moderation state that doesn't create default revisions.     $workspace = $event->getWorkspace();

    $tracked_revisions = $this->workspaceAssociation->getTrackedEntities($workspace->id());
    // Extract all the second-level keys (revision IDs) of the two-dimensional     // array.     $tracked_revision_ids = array_reduce(array_map('array_keys', $tracked_revisions), 'array_merge', []);

    // Gather a list of moderation states that don't create a default revision.     $workflow_non_default_states = [];
    foreach ($this->entityTypeManager->getStorage('workflow')->loadByProperties(['type' => 'content_moderation']) as $workflow) {
      /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
      $workflow_type = $workflow->getTypePlugin();
      // Find all workflows which are moderating entity types of the same type       // to those that are tracked by the workspace.       if (array_intersect($workflow_type->getEntityTypes()array_keys($tracked_revisions))) {
        $workflow_non_default_states[$workflow->id()] = array_filter(array_map(function DContentModerationState $state) {
          return !$state->isDefaultRevisionState() ? $state->id() : NULL;
        },

  public static function aggregate(array $cacheable_normalizations) {
    assert(Inspector::assertAllObjects($cacheable_normalizations, CacheableNormalization::class));
    return new static(
      array_reduce($cacheable_normalizationsfunction DCacheableMetadata $merged, CacheableNormalization $item) {
        return $merged->addCacheableDependency($item);
      }new CacheableMetadata()),
      array_reduce(array_keys($cacheable_normalizations)function D$merged$key) use ($cacheable_normalizations) {
        if (!$cacheable_normalizations[$key] instanceof CacheableOmission) {
          $merged[$key] = $cacheable_normalizations[$key]->getNormalization();
        }
        return $merged;
      }[])
    );
  }

  

class IpsRequestMatcher implements RequestMatcherInterface
{
    private array $ips;

    /** * @param string[]|string $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24 * Strings can contain a comma-delimited list of IPs/ranges */
    public function __construct(array|string $ips)
    {
        $this->ips = array_reduce((array) $ipsstatic fn (array $ips, string $ip) => array_merge($ipspreg_split('/\s*,\s*/', $ip))[]);
    }

    public function matches(Request $request): bool
    {
        if (!$this->ips) {
            return true;
        }

        return IpUtils::checkIp($request->getClientIp() ?? '', $this->ips);
    }
}
$this->assertEquals($expectedTranslatorBag->getCatalogues()$translatorBag->getCatalogues());
    }

    /** * @dataProvider getResponsesForManyLocalesAndManyDomains */
    public function testReadForManyLocalesAndManyDomains(array $locales, array $domains, array $responseContents, TranslatorBag $expectedTranslatorBag)
    {
        $consecutiveLoadArguments = [];
        $consecutiveLoadReturns = [];
        $response = new MockResponse(json_encode([
            'files' => array_reduce($localesfunction D$carry$locale) use ($domains$responseContents, &$consecutiveLoadArguments, &$consecutiveLoadReturns) {
                $carry[$locale] = array_reduce($domainsfunction D$carry$domain) use ($locale$responseContents, &$consecutiveLoadArguments, &$consecutiveLoadReturns) {
                    $carry[$domain.'.xliff'] = [
                        'content' => $responseContents[$locale][$domain],
                    ];

                    $consecutiveLoadArguments[] = [$responseContents[$locale][$domain]$locale$domain];
                    $consecutiveLoadReturns[] = (new XliffFileLoader())->load($responseContents[$locale][$domain]$locale$domain);

                    return $carry;
                }[]);

                

  protected function applyFitOrder(RouteCollection $collection) {
    $buckets = [];
    // Sort all the routes by fit descending.     foreach ($collection->all() as $name => $route) {
      $fit = $route->compile()->getFit();
      $buckets += [$fit => []];
      $buckets[$fit][] = [$name$route];
    }
    krsort($buckets);

    $flattened = array_reduce($buckets, 'array_merge', []);

    // Add them back onto a new route collection.     $collection = new RouteCollection();
    foreach ($flattened as $pair) {
      $name = $pair[0];
      $route = $pair[1];
      $collection->add($name$route);
    }
    return $collection;
  }

  

        $this->data = [
            'calls' => $this->cloneVar([]),
            'violations_count' => 0,
        ];
    }

    public function lateCollect(): void
    {
        $collected = $this->validator->getCollectedData();
        $this->data['calls'] = $this->cloneVar($collected);
        $this->data['violations_count'] = array_reduce($collectedfn ($previous$item) => $previous + \count($item['violations']), 0);
    }

    public function getCalls(): Data
    {
        return $this->data['calls'];
    }

    public function getViolationsCount(): int
    {
        return $this->data['violations_count'];
    }

    
            // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().             $value[] = [
              'entity' => $handler->createNewEntity($element['#target_type']$element['#autocreate']['bundle']$input$element['#autocreate']['uid']),
            ];
          }
        }
      }

      // Check that the referenced entities are valid, if needed.       if ($element['#validate_reference'] && !empty($value)) {
        // Validate existing entities.         $ids = array_reduce($valuefunction D$return$item) {
          if (isset($item['target_id'])) {
            $return[] = $item['target_id'];
          }
          return $return;
        });

        if ($ids) {
          $valid_ids = $handler->validateReferenceableEntities($ids);
          if ($invalid_ids = array_diff($ids$valid_ids)) {
            foreach ($invalid_ids as $invalid_id) {
              $form_state->setError($elementt('The referenced entity (%type: %id) does not exist.', ['%type' => $element['#target_type'], '%id' => $invalid_id]));
            }
if (isset($row[$i])) {
                        $rows[$i][] = $row[$i];
                    } elseif ($isCellWithColspan($rows[$i][0])) {
                        // Noop, there is a "title"                     } else {
                        $rows[$i][] = null;
                    }
                }
            }
        } elseif ($vertical) {
            $formatter = $this->output->getFormatter();
            $maxHeaderLength = array_reduce($this->headers[0] ?? []static fn ($max$header) => max($max, Helper::width(Helper::removeDecoration($formatter$header))), 0);

            foreach ($this->rows as $row) {
                if ($row instanceof TableSeparator) {
                    continue;
                }

                if ($rows) {
                    $rows[] = [$divider];
                }

                $containsColspan = false;
                
/** * Adds a check for the client IP. * * @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24 * * @return void */
    public function matchIps(string|array|null $ips)
    {
        $ips = null !== $ips ? (array) $ips : [];

        $this->ips = array_reduce($ipsstatic fn (array $ips, string $ip) => array_merge($ipspreg_split('/\s*,\s*/', $ip))[]);
    }

    /** * Adds a check for the HTTP method. * * @param string|string[]|null $method An HTTP method or an array of HTTP methods * * @return void */
    public function matchMethod(string|array|null $method)
    {
        
/** * @var string[] */
    private array $schemes;

    /** * @param string[]|string $schemes A scheme or a list of schemes * Strings can contain a comma-delimited list of schemes */
    public function __construct(array|string $schemes)
    {
        $this->schemes = array_reduce(array_map('strtolower', (array) $schemes)static fn (array $schemes, string $scheme) => array_merge($schemespreg_split('/\s*,\s*/', $scheme))[]);
    }

    public function matches(Request $request): bool
    {
        if (!$this->schemes) {
            return true;
        }

        return \in_array($request->getScheme()$this->schemes, true);
    }
}
return 'http://symfony.com/schema/dic/security';
    }

    public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
    {
        // first assemble the factories         return new MainConfiguration($this->getSortedFactories()$this->userProviderFactories);
    }

    private function isValidIps(string|array $ips): bool
    {
        $ipsList = array_reduce((array) $ipsfn ($ips$ip) => array_merge($ipspreg_split('/\s*,\s*/', $ip))[]);

        if (!$ipsList) {
            return false;
        }

        foreach ($ipsList as $cidr) {
            if (!$this->isValidIp($cidr)) {
                return false;
            }
        }

        

        $data[] = array_shift($data);

        return array_values($data);
    }

    /** * Read out the contents of the import_export_profile_translation table */
    protected function getTranslationRecords(): array
    {
        return array_reduce(
            $this->connection->fetchAllAssociative('SELECT * FROM import_export_profile_translation'),
            static function D$carry$translationRecord) {
                $carry[$translationRecord['import_export_profile_id']] = $translationRecord;

                return $carry;
            },
            []
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.