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: Test enhancement
Date: 1 year 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);
    }
}


For more information send a message to info at phpclasses dot org.