protected function _replaceTokens($input, $source, $tokenStart, $tokenEnd, $default = null)
    {
        $input   = $this->_normalizeString($input);
        $default = $default === null ? '' : $this->_normalizeString($default);

        $regexDelimiter = '/';
        $tokenStart     = $this->_quoteRegex($tokenStart, $regexDelimiter);
        $tokenEnd       = $this->_quoteRegex($tokenEnd, $regexDelimiter);

        $regex   = $regexDelimiter . $tokenStart . '(.*?)' . $tokenEnd . $regexDelimiter;
        $matches = $this->_getAllMatchesRegex($regex, $input);

        foreach ($matches[0] as $i => $token) {
            $key = $matches[1][$i];
            $key = $this->_normalizeTokenKey($key);

            try {
                $value = $this->_containerGet($source, $key);
            } catch (NotFoundExceptionInterface $e) {
                $value = $default;
            } catch (RootException $e) {
                $this->_createRuntimeException($this->__('Could not access reference value for key "%1$s"', [$key]), null, $e);
            }

            try {
                $input = $this->_stringableReplace($token, $value, $input);
            } catch (RootException $e) {
                $this->_createRuntimeException($this->__('Could not replace token with key "%1$s"', [$key]), null, $e);
            }
        }

        return $input;
    }
protected function _replaceTokens($input, $source, $tokenStart, $tokenEnd, $default = null)
    {
        $input   = $this->_normalizeString($input);
        $default = $default === null ? '' : $this->_normalizeString($default);

        $regexDelimiter = '/';
        $tokenStart     = $this->_quoteRegex($tokenStart, $regexDelimiter);
        $tokenEnd       = $this->_quoteRegex($tokenEnd, $regexDelimiter);

        $regex   = $regexDelimiter . $tokenStart . '(.*?)' . $tokenEnd . $regexDelimiter;
        $matches = $this->_getAllMatchesRegex($regex, $input);

        foreach ($matches[0] as $i => $token) {
            $key = $matches[1][$i];
            $key = $this->_normalizeTokenKey($key);

            try {
                $value = $this->_containerGet($source, $key);
            } catch (NotFoundExceptionInterface $e) {
                $value = $default;
            } catch (RootException $e) {
                $this->_createRuntimeException($this->__('Could not access reference value for key "%1$s"', [$key]), null, $e);
            }

            try {
                $input = $this->_stringableReplace($token, $value, $input);
            } catch (RootException $e) {
                $this->_createRuntimeException($this->__('Could not replace token with key "%1$s"', [$key]), null, $e);
            }
        }

        return $input;
    }
protected function _replaceTokens ( $ input , $ source , $ tokenStart , $ tokenEnd , $ default = null ) { $ input = $ this -> _normalizeString ( $ input ) ; $ default = $ default === null ? '' : $ this -> _normalizeString ( $ default ) ; $ regexDelimiter = '/' ; $ tokenStart = $ this -> _quoteRegex ( $ tokenStart , $ regexDelimiter ) ; $ tokenEnd = $ this -> _quoteRegex ( $ tokenEnd , $ regexDelimiter ) ; $ regex = $ regexDelimiter . $ tokenStart . '(.*?)' . $ tokenEnd . $ regexDelimiter ; $ matches = $ this -> _getAllMatchesRegex ( $ regex , $ input ) ; foreach ( $ matches [ 0 ] as $ i => $ token ) { $ key = $ matches [ 1 ] [ $ i ] ; $ key = $ this -> _normalizeTokenKey ( $ key ) ; try { $ value = $ this -> _containerGet ( $ source , $ key ) ; } catch ( NotFoundExceptionInterface $ e ) { $ value = $ default ; } catch ( RootException $ e ) { $ this -> _createRuntimeException ( $ this -> __ ( 'Could not access reference value for key "%1$s"' , [ $ key ] ) , null , $ e ) ; } try { $ input = $ this -> _stringableReplace ( $ token , $ value , $ input ) ; } catch ( RootException $ e ) { $ this -> _createRuntimeException ( $ this -> __ ( 'Could not replace token with key "%1$s"' , [ $ key ] ) , null , $ e ) ; } } return $ input ; }
Replaces all tokens in a string with corresponding values.

Use {@see _normalizeTokenKey()} to convert token keys into a format used in the container.

@since [*next-version*]

@param string|Stringable                                 $input      The string that may contain tokens.
@param BaseContainerInterface|array|ArrayAccess|stdClass $source     The source of values for replacement.
@param string|Stringable                                 $tokenStart Starting delimiter of token.
@param string|Stringable                                 $tokenEnd   Ending delimiter of token.
@param string|Stringable|null                            $default    Default replacement value. Used if a token does not correspond to known value.

@throws InvalidArgumentException If input, source, token start or end, or the default value are invalid.
@throws RuntimeException         If problem replacing tokens.

@return string The resulting string.
Replaces all tokens in a string with corresponding values .