SimpleLogger::interpolate PHP Method

interpolate() public method

Interpolates context values into the message placeholders.
public interpolate ( string $message, array $context = [], array $row = null )
$message string
$context array
$row array Currently not always passed, because loggers need to be updated to support this...
    function interpolate($message, $context = array(), $row = null)
    {
        if (!is_array($context)) {
            return $message;
        }
        /**
         * Filter the context used to create the message from the message template
         *
         * @since 2.2.4
         */
        $context = apply_filters("simple_history/logger/interpolate/context", $context, $message, $row);
        // Build a replacement array with braces around the context keys
        $replace = array();
        foreach ($context as $key => $val) {
            // Both key and val must be strings or number (for vals)
            if (is_string($key) || is_numeric($key)) {
                // key ok
            }
            if (is_string($val) || is_numeric($val)) {
                // val ok
            } else {
                // not a value we can replace
                continue;
            }
            $replace['{' . $key . '}'] = $val;
        }
        // Interpolate replacement values into the message and return
        /*
        		if ( ! is_string( $message )) {
        			echo "message:";
        			var_dump($message);exit;
        		}
        		//*/
        /*
        		if ( ! is_string( $replace )) {
        			echo "replace: \n";
        			var_dump($replace);
        		}
        		// */
        return strtr($message, $replace);
    }