<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class EncodeCharset4KuferToolsWss extends EncodingCharset
{
  protected $fromencoding;

  
  public function __construct($fromencoding = null)
  {
    $this->fromencoding = $fromencoding;
  }

  
  public function getFromEncoding()
  {
    return \is_null($this->fromencoding) ? \CodingOperations::getKuferToolsWssEncoding() : $this->fromencoding;
  }

  public function encodeWssAry($wssAry)
  {
    return $this->codeArray($wssAry, array($this, 'encode'));
  }

  public function decodeWssAry($wssAry)
  {
    return $this->codeArray($wssAry, array($this, 'decode'));
  }

  private function codeArray($wssAry, $codingFunction)
  {
    return array_map(function($wss) use ($codingFunction) {
      $wss->title = call_user_func($codingFunction, $wss->title ?? '');
      $wss->wenn_leer = call_user_func($codingFunction, $wss->wenn_leer ?? '');

      return $wss;
    }, $wssAry);
  }
}