PHP Classes

File: src/Generics/Util/Interpolator.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   src/Generics/Util/Interpolator.php   Download  
File: src/Generics/Util/Interpolator.php
Role: Class source
Content type: text/plain
Description: Trait for interpolating
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of src/Generics/Util/Interpolator.php
Date: 7 months ago
Size: 850 bytes
 

Contents

Class file image Download
<?php

/**
 * This file is part of the PHP Generics package.
 *
 * @package Generics
 */
namespace Generics\Util;

/**
 *
 * @author Maik Greubel <greubel@nkey.de>
 */
trait Interpolator
{

   
/**
     * Interpolates context values into the message placeholders.
     *
     * @param string $message
     * The message containing placeholders
     * @param array $context
     * The context array containing the replacers
     *
     * @return string The interpolated message
     */
   
private static function interpolate($message, array $context = array()): string
   
{
       
$replace = array();
       
        if (
$context !== null) {
            foreach (
$context as $key => $val) {
               
$replace['{' . $key . '}'] = $val;
            }
        }
       
        return
strtr($message, $replace);
    }
}