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

class PrefixParams extends Parameters
{
  public static function getInstance()
  {
    static $instance = null;
    if (is_null($instance)) {
      $instance = new PrefixParams();
    }

    return $instance;
  }

  public function is_valid_type($value)
  {
    if ($value == '') {
      return true;
    }

    return $this->isPrefix($value);
  }

  public static function isPrefix($input)
  {
    return preg_match('/^[a-z][0-9a-z]*[.]?$/mi', $input) === 1;
  }

  public function prepare_value($value, $dboperation)
  {
    if ($value == '') {
      return '';
    }

    return StringOperations::setLastChar($value, '.');
  }
}