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

class ArrayParams extends Parameters
{
  private $paramObj;

  protected function __construct($paramObj)
  {
    $this->paramObj = $paramObj;
  }

  public static function getInstance($paramObj)
  {
    $classname = get_class($paramObj);
    static $instance = array();
    if (!isset($instance[$classname])) {
      $instance[$classname] = new ArrayParams($paramObj);
    }

    return $instance[$classname];
  }

  public function addParams($stringArray, $dboperation)
  {
    if (!is_array($stringArray) || empty($stringArray)) {
      throw new Exception('The passed value is not an array or it is empty.');
    }

    $sqlValues = array_map(function($singleValue) use ($dboperation) {
      return parent::addParams($singleValue, $dboperation);
    }, $stringArray);

    return implode(', ', $sqlValues);
  }

  public function is_valid_type($value)
  {
    return $this->paramObj->is_valid_type($value);
  }

  public function prepare_value($value, $dboperation)
  {
    return $this->paramObj->prepare_value($value, $dboperation);
  }
}