1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 
<?php
/**
 * RKD Banklink.
 *
 * @link https://github.com/renekorss/Banklink/
 *
 * @author Rene Korss <rene.korss@gmail.com>
 * @copyright 2016-2019 Rene Korss
 * @license MIT
 */
namespace RKD\Banklink\Request;

use UnexpectedValueException;

/**
 * Abstract request class.
 *
 * @author Rene Korss <rene.korss@gmail.com>
 */
abstract class Request implements RequestInterface
{
    /**
     * Request url.
     *
     * @var string
     */
    protected $requestUrl;

    /**
     * Request data.
     *
     * @var array
     */
    protected $requestData;

    /**
     * Constructor.
     *
     * @param string $requestUrl  Request URL
     * @param array  $requestData Request array
     */
    public function __construct(string $requestUrl, array $requestData)
    {
        $this->requestUrl = $requestUrl;
        $this->requestData = $requestData;
    }

    /**
     * Get request hidden inputs.
     *
     * @return string HTML of hidden request inputs
     */
    public function getRequestInputs() : string
    {
        if (empty($this->requestData)) {
            throw new UnexpectedValueException('Can\'t generate inputs. Request data is empty.');
        }

        $html = '';

        foreach ($this->requestData as $key => $value) {
            $html .= vsprintf(
                '<input type="hidden" id="%s" name="%s" value="%s" />',
                [strtolower($key), $key, $value]
            )."\n";
        }

        return $html;
    }

    /**
     * Get request URL.
     *
     * @return string Request URL
     */
    public function getRequestUrl() : string
    {
        return $this->requestUrl;
    }

    /**
     * Get request data.
     *
     * @return array Request data
     */
    public function getRequestData() : array
    {
        return $this->requestData;
    }
}