Get or set replacements

@param mixed $replacements
@return array
176344
public function replacements($replacements = null)
    {
        if (!is_null($replacements)) {
            $this->replacements = $replacements;
        }

        return $this->replacements;
    }
141519
public function replace(array $placeholders = [])
    {
        if (empty($placeholders)) {
            return $this;
        }
        $callback = function ($value) use ($placeholders) {
            return StringHelper::replace($value, $placeholders, false);
        };
        $this->data = ArrayHelper::map($this->data, $callback, true);
        return $this;
    }
695955
protected function extractIntoReplacements(array $replacements, array $size)
    {
        $replacements['%image-width%'] = $size[0];
        $replacements['%image-height%'] = $size[1];
        if (isset($size['channels'])) {
            $replacements['%image-channels%'] = $size['channels'];
        }
        if (isset($size['mime'])) {
            $replacements['%image-mime%'] = $replacements['%composed-title%'] = $size['mime'];
        }

        return $replacements;
    }
240836
public function findOneAndReplace(array $filter, $replacement, array $options = [])
    {
        if (!is_array($replacement) && !is_object($replacement)) {
            throw new InvalidArgumentException(
                sprintf(
                    '$replacement must be an array or an object, "%s" given.',
                    \Tequila\MongoDB\getType($replacement)
                )
            );
        }

        try {
            ensureValidDocument($replacement);
        } catch (InvalidArgumentException $e) {
            throw new InvalidArgumentException(
                sprintf('Invalid $replacement document: %s', $e->getMessage())
            );
        }

        $options = ['update' => (object) $replacement] + FindOneAndUpdateResolver::resolveStatic($options);

        return $this->findAndModify($filter, $options);
    }
632906
public function format(Collection $replacement)
    {
        $replacement = $this->prepare($replacement);
        $messageLines = explode(PHP_EOL, $replacement['message']);
        
        foreach ($messageLines as &$messageLine) {
            $replacement['message'] = $messageLine;
            $messageLine = $this->replace($this->getFormat(), $replacement);
        }
        
        return implode(PHP_EOL, $messageLines);
    }
1078203
private function replaceTokens(array $originalTokens, array $replacements)
    {
        $tokens = [];
        foreach ($originalTokens as $key => $token) {
            if (! array_key_exists($key, $replacements)) {
                $tokens[] = $token;
                continue;
            }

            foreach ($replacements[$key] as $replacementToken) {
                $tokens[] = $replacementToken;
            }
        }
        return $tokens;
    }
912331
protected function obtainReplacements()
    {
        return [
            'ROUTE_LINK' => $link = $this->getReplacements()[0],
            'ROUTE_CONTROLLER' => $this->controller($this->getReplacements()[1]),
            'ROUTE_METHOD' => $this->getReplacements()[2],
            'ROUTE_NAME' => dot_path($link),
        ];
    }
881806
public function replaceOneValue($search, $replacement = ''): self
    {
        $array = $this->getArray();
        $key = \array_search($search, $array, true);

        if ($key !== false) {
            $array[$key] = $replacement;
        }

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
47200
protected function replaceDefaults(array $parameters)
    {
        foreach ($parameters as $key => &$value) {
            if (! isset($value)) {
                $value = Arr::get($this->defaults, $key);
            }
        }

        return $parameters;
    }
1054070
protected function expandPatterns(array $patterns, $search, array $replacements)
    {
        if ($replacements === []) {
            return $patterns;
        }
        $patternsWithReplacements = [];
        foreach ($patterns as $pattern) {
            foreach ($replacements as $replacement) {
                $patternsWithReplacements[] = Files::getUnixStylePath(str_replace($search, $replacement, $pattern));
            }
        }

        return $patternsWithReplacements;
    }
744604
protected function recursiveReplace($base, $replacement)
    {
        $replace_values_recursive = function (array $array, array $order) use (&$replace_values_recursive) {
            $array = array_replace($order, array_replace($array, $order));

            foreach ($array as $key => &$value) {
                if (is_array($value)) {
                    $value = (array_key_exists($key, $order) && is_array($order[$key]))
                        ? $replace_values_recursive($value, $order[$key])
                        : $value
                    ;
                }
            }
            return $array;
        };

        return $replace_values_recursive($base, $replacement);
    }
1005198
protected function replace($translation, $replacement = []) {
        foreach ($replacement as $key => $value) {
            $translation = str_replace(':'.$key, $value, $translation);
        }

        return $translation;
    }
647091
public function setWriteTranslations(array $replacements)
    {
        foreach ($this->translations as $search => $replace) {
            if (!isset($replacements[$search])) {
                $this->removeFilter($search);
                unset($this->translations[$search]);
            }
        }

        foreach ($replacements as $search => $replace) {
            if (!isset($this->translations[$search])) {
                $this->addFilter(
                    $this->replacementFactory->createFilter($search, $replace), $search
                    );
                $this->translations[$search] = true;
            }
        }
    }
1113658
public function getReplaceValuesFromArgument($argValues)
    {
        $replaceValues = array();

        $argValues = explode(',', $argValues);
        foreach ($argValues as $argValue) {
            $argValue = explode(':', $argValue);
            if (count($argValue) != 2) {
                $msg = 'Command argument "--replace" must follow the format: --replace="{SEARCH}:{REPLACE},..."';
                throw new \ErrorException($msg);
            }

            $search = trim($argValue[0]);
            $replace = trim($argValue[1]);
            if ($this->isMagicVariable($replace)) {
                // Is magic variable, so, replace by the magic value.
                $replace = $this->getMagicVariableValue($replace);
            }

            $replaceValues[$search] = $replace;
        }

        return $replaceValues;
    }
826547
protected function buildModelReplacements(array $replace)
    {
        $modelClass = $this->parseModel($this->option('model'));

        if (! class_exists($modelClass)) {
            if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) {
                $this->call('make:model', ['name' => $modelClass]);
            }
        }

        return array_merge($replace, [
            'DummyFullModelClass' => $modelClass,
            'DummyModelClass' => class_basename($modelClass),
            'DummyModelVariable' => lcfirst(class_basename($modelClass)),
        ]);
    }
1164809
public function extract(array $replacements, UrlInterface $url)
    {
        $size = @\getimagesize('data://application/octet-stream;base64,'  . base64_encode($url->getBody()));
        if ($size) {
            $replacements = $this->extractIntoReplacements($replacements, $size);
        }

        return $replacements;
    }
1322271
protected function sortReplacements(array $replace)
    {
        $results = array();

        $callback = function ($value, $key) {
            return mb_strlen($key) * -1;
        };

        foreach ($replace as $key => $value) {
            $results[$key] = $callback($value, $key);
        }

        asort($results, SORT_REGULAR);

        foreach (array_keys($results) as $key) {
            $results[$key] = $replace[$key];
        }

        return $results;
    }