public function resolveString($value, array $resolving = array())
    {
        // we do this to deal with non string values (Boolean, integer, ...)
        // as the preg_replace_callback throw an exception when trying
        // a non-string in a parameter value
        if (preg_match('/^%([^%\s]+)%$/', $value, $match)) {
            $key = $match[1];
            $lcKey = strtolower($key); // strtolower() to be removed in 4.0

            if (isset($resolving[$lcKey])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolving[$lcKey] = true;

            return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
        }

        return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($resolving, $value) {
            // skip %%
            if (!isset($match[1])) {
                return '%%';
            }

            $key = $match[1];
            $lcKey = strtolower($key); // strtolower() to be removed in 4.0
            if (isset($resolving[$lcKey])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolved = $this->get($key);

            if (!is_string($resolved) && !is_numeric($resolved)) {
                throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".', $key, gettype($resolved), $value));
            }

            $resolved = (string) $resolved;
            $resolving[$lcKey] = true;

            return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving);
        }, $value);
    }
public function resolveString($value, array $resolving = array())
    {
        // we do this to deal with non string values (Boolean, integer, ...)
        // as the preg_replace_callback throw an exception when trying
        // a non-string in a parameter value
        if (preg_match('/^%([^%\s]+)%$/', $value, $match)) {
            $key = $match[1];
            $lcKey = strtolower($key); // strtolower() to be removed in 4.0

            if (isset($resolving[$lcKey])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolving[$lcKey] = true;

            return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
        }

        return preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($resolving, $value) {
            // skip %%
            if (!isset($match[1])) {
                return '%%';
            }

            $key = $match[1];
            $lcKey = strtolower($key); // strtolower() to be removed in 4.0
            if (isset($resolving[$lcKey])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolved = $this->get($key);

            if (!is_string($resolved) && !is_numeric($resolved)) {
                throw new RuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".', $key, gettype($resolved), $value));
            }

            $resolved = (string) $resolved;
            $resolving[$lcKey] = true;

            return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving);
        }, $value);
    }
public function resolveString ( $ value , array $ resolving = array ( ) ) { // we do this to deal with non string values (Boolean, integer, ...) // as the preg_replace_callback throw an exception when trying // a non-string in a parameter value if ( preg_match ( '/^%([^%\s]+)%$/' , $ value , $ match ) ) { $ key = $ match [ 1 ] ; $ lcKey = strtolower ( $ key ) ; // strtolower() to be removed in 4.0 if ( isset ( $ resolving [ $ lcKey ] ) ) { throw new ParameterCircularReferenceException ( array_keys ( $ resolving ) ) ; } $ resolving [ $ lcKey ] = true ; return $ this -> resolved ? $ this -> get ( $ key ) : $ this -> resolveValue ( $ this -> get ( $ key ) , $ resolving ) ; } return preg_replace_callback ( '/%%|%([^%\s]+)%/' , function ( $ match ) use ( $ resolving , $ value ) { // skip %% if ( ! isset ( $ match [ 1 ] ) ) { return '%%' ; } $ key = $ match [ 1 ] ; $ lcKey = strtolower ( $ key ) ; // strtolower() to be removed in 4.0 if ( isset ( $ resolving [ $ lcKey ] ) ) { throw new ParameterCircularReferenceException ( array_keys ( $ resolving ) ) ; } $ resolved = $ this -> get ( $ key ) ; if ( ! is_string ( $ resolved ) && ! is_numeric ( $ resolved ) ) { throw new RuntimeException ( sprintf ( 'A string value must be composed of strings and/or numbers, but found parameter "%s" of type %s inside string value "%s".' , $ key , gettype ( $ resolved ) , $ value ) ) ; } $ resolved = ( string ) $ resolved ; $ resolving [ $ lcKey ] = true ; return $ this -> isResolved ( ) ? $ resolved : $ this -> resolveString ( $ resolved , $ resolving ) ; } , $ value ) ; }
Resolves parameters inside a string.

@param string $value     The string to resolve
@param array  $resolving An array of keys that are being resolved (used internally to detect circular references)

@return string The resolved string

@throws ParameterNotFoundException          if a placeholder references a parameter that does not exist
@throws ParameterCircularReferenceException if a circular reference if detected
@throws RuntimeException                    when a given parameter has a type problem
Resolves parameters inside a string .