array_replace example

foreach ($result as $role) {
        $this->items[$role->uid][$role->rid]['role'] = $roles[$role->rid]->label();
        $this->items[$role->uid][$role->rid]['rid'] = $role->rid;
      }
      // Sort the roles for each user by role weight.       $ordered_roles = array_flip(array_keys($roles));
      foreach ($this->items as &$user_roles) {
        // Create an array of rids that the user has in the role weight order.         $sorted_keys = array_intersect_key($ordered_roles$user_roles);
        // Merge with the unsorted array of role information which has the         // effect of sorting it.         $user_roles = array_replace($sorted_keys$user_roles);
      }
    }
  }

  public function render_item($count$item) {
    return $item['role'];
  }

  protected function documentSelfTokens(&$tokens) {
    $tokens['{{ ' . $this->options['id'] . '__role' . ' }}'] = $this->t('The name of the role.');
    $tokens['{{ ' . $this->options['id'] . '__rid' . ' }}'] = $this->t('The role machine-name of the role.');
  }

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $vars = [
            'widget' => $options['widget'],
            'with_invert' => $options['with_invert'],
        ];
        foreach (self::TIME_PARTS as $part) {
            $vars['with_'.$part] = $options['with_'.$part];
        }
        $view->vars = array_replace($view->vars, $vars);
    }

    /** * @return void */
    public function configureOptions(OptionsResolver $resolver)
    {
        $compound = static fn (Options $options) => 'single_text' !== $options['widget'];
        $emptyData = static fn (Options $options) => 'single_text' === $options['widget'] ? '' : [];

        $placeholderDefault = static fn (Options $options) => $options['required'] ? null : '';

        
return [
                'year' => $placeholder,
                'week' => $placeholder,
            ];
        };

        $choiceTranslationDomainNormalizer = static function DOptions $options$choiceTranslationDomain) {
            if (\is_array($choiceTranslationDomain)) {
                $default = false;

                return array_replace(
                    ['year' => $default, 'week' => $default],
                    $choiceTranslationDomain
                );
            }

            return [
                'year' => $choiceTranslationDomain,
                'week' => $choiceTranslationDomain,
            ];
        };

        
$name = $annot->getName() ?? $this->getDefaultRouteName($class$method);
        $name = $globals['name'].$name;

        $requirements = $annot->getRequirements();

        foreach ($requirements as $placeholder => $requirement) {
            if (\is_int($placeholder)) {
                throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder$requirement$name$class->getName()$method->getName()));
            }
        }

        $defaults = array_replace($globals['defaults']$annot->getDefaults());
        $requirements = array_replace($globals['requirements']$requirements);
        $options = array_replace($globals['options']$annot->getOptions());
        $schemes = array_merge($globals['schemes']$annot->getSchemes());
        $methods = array_merge($globals['methods']$annot->getMethods());

        $host = $annot->getHost() ?? $globals['host'];
        $condition = $annot->getCondition() ?? $globals['condition'];
        $priority = $annot->getPriority() ?? $globals['priority'];

        $path = $annot->getLocalizedPaths() ?: $annot->getPath();
        $prefix = $globals['localized_paths'] ?: $globals['path'];
        
$name = $annot->getName() ?? $this->getDefaultRouteName($class$method);
        $name = $globals['name'].$name;

        $requirements = $annot->getRequirements();

        foreach ($requirements as $placeholder => $requirement) {
            if (\is_int($placeholder)) {
                throw new \InvalidArgumentException(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?', $placeholder$requirement$name$class->getName()$method->getName()));
            }
        }

        $defaults = array_replace($globals['defaults']$annot->getDefaults());
        $requirements = array_replace($globals['requirements']$requirements);
        $options = array_replace($globals['options']$annot->getOptions());
        $schemes = array_unique(array_merge($globals['schemes']$annot->getSchemes()));
        $methods = array_unique(array_merge($globals['methods']$annot->getMethods()));

        $host = $annot->getHost() ?? $globals['host'];
        $condition = $annot->getCondition() ?? $globals['condition'];
        $priority = $annot->getPriority() ?? $globals['priority'];

        $path = $annot->getLocalizedPaths() ?: $annot->getPath();
        $prefix = $globals['localized_paths'] ?: $globals['path'];
        
$container->get('workspaces.repository'),
      $container->get('renderer')
    );
  }

  /** * {@inheritdoc} */
  public function load() {
    // Get all the workspace entities and sort them in tree order.     $workspace_tree = $this->workspaceRepository->loadTree();
    $entities = array_replace($workspace_tree$this->storage->loadMultiple());
    foreach ($entities as $id => $entity) {
      $entity->_depth = $workspace_tree[$id]['depth'];
    }

    return $entities;
  }

  /** * {@inheritdoc} */
  public function buildHeader() {
    
if (\array_key_exists('amount', $customParams)) {
            if (\is_float($customParams['amount'])) {
                $customParams['amount'] = new CalculatedPrice(
                    $customParams['amount'],
                    $customParams['amount'],
                    new CalculatedTaxCollection(),
                    new TaxRuleCollection()
                );
            }
        }

        $transaction = \array_replace([
            'id' => $this->ids->get($key),
            'orderId' => $this->id,
            'paymentMethodId' => $this->getValidPaymentMethodId(),
            'amount' => new CalculatedPrice(
                420.69,
                420.69,
                new CalculatedTaxCollection(),
                new TaxRuleCollection()
            ),
            'stateId' => $this->getStateMachineState(
                OrderTransactionStates::STATE_MACHINE,
                
return $this->doGenerate($variables$defaults$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }

    /** * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */
    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        // all params must be given         if ($diff = array_diff_key($variables$mergedParams)) {
            throw new MissingMandatoryParametersException($namearray_keys($diff));
        }

        $url = '';
        $optional = true;
        $message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
        foreach ($tokens as $token) {
            if ('variable' === $token[0]) {
                

    public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = []$content = null)static
    {
        $server = array_replace([
            'SERVER_NAME' => 'localhost',
            'SERVER_PORT' => 80,
            'HTTP_HOST' => 'localhost',
            'HTTP_USER_AGENT' => 'Symfony',
            'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
            'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
            'REMOTE_ADDR' => '127.0.0.1',
            'SCRIPT_NAME' => '',
            'SCRIPT_FILENAME' => '',
            'SERVER_PROTOCOL' => 'HTTP/1.1',
            

        $this->parameters = $parameters;
    }

    /** * Adds parameters. * * @return void */
    public function add(array $parameters = [])
    {
        $this->parameters = array_replace($this->parameters, $parameters);
    }

    public function get(string $key, mixed $default = null): mixed
    {
        return \array_key_exists($key$this->parameters) ? $this->parameters[$key] : $default;
    }

    /** * @return void */
    public function set(string $key, mixed $value)
    {
$choiceTranslationDomain = $view->vars['translation_domain'];
        }

        /** @var ChoiceListInterface $choiceList */
        $choiceList = $form->getConfig()->getAttribute('choice_list');

        /** @var ChoiceListView $choiceListView */
        $choiceListView = $form->getConfig()->hasAttribute('choice_list_view')
            ? $form->getConfig()->getAttribute('choice_list_view')
            : $this->createChoiceListView($choiceList$options);

        $view->vars = array_replace($view->vars, [
            'multiple' => $options['multiple'],
            'expanded' => $options['expanded'],
            'preferred_choices' => $choiceListView->preferredChoices,
            'choices' => $choiceListView->choices,
            'separator' => '-------------------',
            'placeholder' => null,
            'placeholder_attr' => [],
            'choice_translation_domain' => $choiceTranslationDomain,
            'choice_translation_parameters' => $options['choice_translation_parameters'],
        ]);

        
            // child.             // See also https://github.com/symfony/symfony/issues/4359             if ($childrenSynchronized) {
                $clientDataAsString = \is_scalar($form->getViewData())
                    ? (string) $form->getViewData()
                    : get_debug_type($form->getViewData());

                $failure = $form->getTransformationFailure();

                $this->context->setConstraint($formConstraint);
                $this->context->buildViolation($failure->getInvalidMessage() ?? $config->getOption('invalid_message'))
                    ->setParameters(array_replace(
                        ['{{ value }}' => $clientDataAsString],
                        $config->getOption('invalid_message_parameters'),
                        $failure->getInvalidMessageParameters()
                    ))
                    ->setInvalidValue($form->getViewData())
                    ->setCode(Form::NOT_SYNCHRONIZED_ERROR)
                    ->setCause($failure)
                    ->addViolation();
            }
        }

        
if ('' !== $server['QUERY_STRING']) {
                $server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
            }

            if ('https' === $uri->getScheme()) {
                $server['HTTPS'] = 'on';
            }
        }

        $server['REQUEST_METHOD'] = $psrRequest->getMethod();

        $server = array_replace($psrRequest->getServerParams()$server);

        $parsedBody = $psrRequest->getParsedBody();
        $parsedBody = \is_array($parsedBody) ? $parsedBody : [];

        $request = new Request(
            $psrRequest->getQueryParams(),
            $parsedBody,
            $psrRequest->getAttributes(),
            $psrRequest->getCookieParams(),
            $this->getFiles($psrRequest->getUploadedFiles()),
            $server,
            

    public function changeCustomFields(array $customFields): void
    {
        $this->customFields = \array_replace($this->customFields ?? []$customFields);
    }
}
return $this->doGenerate($variables$defaults$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }

    /** * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */
    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        // all params must be given         if ($diff = array_diff_key($variables$mergedParams)) {
            throw new MissingMandatoryParametersException($namearray_keys($diff));
        }

        $url = '';
        $optional = true;
        $message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
        foreach ($tokens as $token) {
            if ('variable' === $token[0]) {
                
Home | Imprint | This part of the site doesn't use cookies.