@param array $target
@param array $placeholders

@api
544273
public static function transform(array &$target, array $placeholders)
    {
        $wrap = function (string & $value) {
            $value = sprintf('/%s/', $value);
        };
        array_walk_recursive($target, function (&$param) use ($wrap, $placeholders) {
            if (!\is_string($param)) { return; }
            if (preg_match('/^const\((.*)\)$/', $param, $matches)) {
                $param = \constant($matches[1]);
            } elseif (preg_match_all('/%(.+?)%/', $param, $matches)) {
                array_walk($matches[0], $wrap);
                $pattern = $matches[0];
                $replacement = array_intersect_key($placeholders, array_flip($matches[1]));
                $param = preg_replace($pattern, $replacement, $param);
            }
        });
    }
997164
public function replaceAll($targets) {
    if ($targets instanceof Node) {
      $targets->replaceWith($this->nodes);
    }
    elseif ($targets instanceof NodeCollection || is_array($targets)) {
      $first = TRUE;
      /** @var Node $target */
      foreach ($targets as $target) {
        $target->replaceWith($first ? $this->nodes : clone $this);
        $first = FALSE;
      }
    }
    return $this;
  }
602267
private function mergeUnmodifiedPartial(array &$target, array $source)
    {
        foreach ($source as $key => $value) {
            if (is_array($value) && isset($target[$key])) {
                $this->mergeUnmodifiedPartial($target[$key], $value);
            } else {
                $target[$key] = $value;
            }
        }
    }
1062081
protected static function addMissingParts($source, $target)
    {
        $pattern = '/'.preg_replace('/[0-9]+/', '[0-9]+', preg_quote($target, '/')).'$/';

        $result = preg_replace($pattern, $target, $source, 1, $count);

        return $count ? $result : $target;
    }
823692
protected function handleTargets(array $targets, Request $request)
    {
        $responses = array();

        foreach ($targets as $target) {
            $responses[] = $this->handleTarget($target, $request);
        }

        return $responses;
    }
52597
function replacePlaceholders(array $symbols, array $replacements = array()) {
    parent::replacePlaceholders($symbols, array(self::SYMBOL_SPECIAL_PERCENT, self::SYMBOL_SPECIAL_PERMILLE));
  }
547609
public function writeTaskLine($message, array $placeholders = [])
    {
        $this->writeBadgeLine(
            $message, $placeholders, 'badge_task', Color::BLUE, false, false
        );
    }
138089
public static function replaceTpl($content, array $placeholders = null, Template $template)
    {
        $template = clone $template;
        $template->removeAllPlaceholders();

        return $template->replace($content, $placeholders);
    }
372949
public static function debug(array $strings, array $placeholders = [])
    {
        // Initialize messages storage.
        if (!isset($_SESSION[__TRAIT__])) {
            $_SESSION[__TRAIT__] = [];
        }

        // Mark debug message.
        array_unshift($strings, '<question>DEBUG:</question>');

        $_SESSION[__TRAIT__][] = new Message('comment', 4, $strings, $placeholders, (bool) getenv('BEHAT_DEBUG'));
    }
1288098
private function callHydrator($target, array $args)
    {
        $callback = array($this, 'toEntity');
        return call_user_func_array($callback, array_merge(array($target), $args));
    }
396103
private function createBlock(Block $targetBlock, string $placeholder, array $blockData): Block
    {
        $blockCreateStruct = $this->buildBlockCreateStruct($blockData);
        $block = $this->blockService->createBlock($blockCreateStruct, $targetBlock, $placeholder);

        $this->updateBlockTranslations($block, $blockData['parameters']);
        $this->processPlaceholderBlocks($block, $blockData['placeholders']);
        $this->processCollections($block, $blockData['collections']);

        return $block;
    }
271407
private static function fix(&$target, $source, $keep=false) {
    if (!$source) {
      return;
    }
    $keys = [];

    $source = preg_replace_callback(
      '/
      # Match at start of string or &
      (?:^|(?<=&))
      # Exclude cases where the period is in brackets, e.g. foo[bar.blarg]
      [^=&\[]*
      # Affected cases: periods and spaces
      (?:\.|%20)
      # Keep matching until assignment, next variable, end of string or
      # start of an array
      [^=&\[]*
      /x',
      function ($key) use (&$keys) {
        $keys[] = $key = base64_encode(urldecode($key[0]));
        return urlencode($key);
    },
      $source
    );

    if (!$keep) {
      $target = [];
    }

    parse_str($source, $data);
    foreach ($data as $key => $val) {
      // Only unprocess encoded keys
      if (!in_array($key, $keys)) {
        $target[$key] = $val;
        continue;
      }

      $key = base64_decode($key);
      $target[$key] = $val;

      if ($keep) {
        // Keep a copy in the underscore key version
        $key = preg_replace('/(\.| )/', '_', $key);
        $target[$key] = $val;
      }
    }
  }
31213
public static function copy($array, $target)
    {
        foreach ($array as $key => $element) {
            self::add($target, $element, $key);
        }
    }
406030
private function applyOperations($operations, &$target)
    {
        foreach ($operations as $key => $operation)
        {
            $oldValue = (isset($target[$key]) ? $target[$key] : null);
            $newValue = $operation->_apply($oldValue, $this, $key);
            if (empty($newValue) && !is_array($newValue) && $newValue !== null && !is_scalar($newValue)
            )
            {
                unset($target[$key]);
                unset($this->dataAvailability[$key]);
            } else
            {
                $target[$key] = $newValue;
                $this->dataAvailability[$key] = true;
            }
        }
    }
647776
private function tryToEncodeTargetsAsSwitch(array $targets): ?array
    {
        $result = count($targets) > 1;

        $contextKey  = null;
        $valueRuleIdMap = [];

        foreach ($targets as $ruleId => $nullableTarget) {
            if ($result === true &&
                $nullableTarget !== null &&
                count($allOfs = $nullableTarget->getAnyOf()->getAllOfs()) === 1 &&
                count($pairs = reset($allOfs)->getPairs()) === 1
            ) {
                $value = reset($pairs);
                $key   = key($pairs);
                assert($key !== null);
                if ($contextKey === null) {
                    $contextKey = $key;
                }
                if ($key !== $contextKey) {
                    $result = false;
                    break;
                }
                $valueRuleIdMap[$value] = $ruleId;
            } else {
                $result = false;
                break;
            }
        }

        $result = $result === true && count($valueRuleIdMap) === count($targets);

        // if result === true we know the following
        // - we have more than one target
        // - every target is a really one key, value pair
        // - in every such pair key is identical and every value is unique
        //
        // if so
        // $contextKey - will have that identical key and $valueRuleIdMap will be an array of [unique_value => true]
        // so later we can check if target matched by simply taking value from context by $contextKey and
        // checking that value in $valueRuleIdMap (key existence).

        return $result === true ? [$contextKey, $valueRuleIdMap] : null;
    }
555136
public function translate($template, $placeholders = null)
    {
        $context = $this->_context;

        $locale = $context->locale ?: $this->getLocale();

        if ($pos = strpos($locale, '-')) {
            $fallback = substr($locale, 0, $pos);
        } else {
            $fallback = null;
        }

        if ($this->_messages === null) {
            foreach ($this->_files as $file) {
                $messages = [];
                $file = $this->alias->resolve("$file/$locale.php");
                if (is_file($file)) {
                    /** @noinspection PhpIncludeInspection */
                    $messages = require $file;
                } elseif ($fallback) {
                    $file = $this->alias->resolve("$file/$fallback.php");
                    if (is_file($file)) {
                        /** @noinspection PhpIncludeInspection */
                        $messages = require $file;
                    }
                }

                if ($messages) {
                    if ($this->_messages) {
                        /** @noinspection SlowArrayOperationsInLoopInspection */
                        $this->_messages = array_merge($this->_messages, $messages);
                    } else {
                        $this->_messages = $messages;
                    }
                }
            }
        }

        $message = isset($this->_messages[$template]) ? $this->_messages[$template] : $template;

        if ($placeholders) {
            $replaces = [];

            if (strpos($message, ':') !== false) {
                foreach ($placeholders as $k => $v) {
                    $replaces[':' . $k] = $v;
                }
            }

            if (strpos($message, '{') !== false) {
                foreach ($placeholders as $k => $v) {
                    $replaces['{' . $k . '}'] = $v;
                }
            }

            return strtr($message, $replaces);
        } else {
            return $message;
        }
    }
1303921
public function applyActions(array $actions, $source, $target)
    {
        $applied = 0;
        foreach ($actions as $action_id => $data) {

            $handler = $this->getActionHandler($action_id);

            if (empty($handler)) {
                continue;
            }

            $result = $this->applyAction($source, $target, $handler, $data);

            if ($result === true) {
                $applied++;
            }
        }

        return $applied;
    }