<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace Intervention\HttpAuth;

class Directive
{
    /**
     * Type of directive (basic|digest)
     *
     * @var string
     */
    protected $type;

    /**
     * Array of parameters
     *
     * @var array
     */
    protected $parameters = [];

    /**
     * Create new instance
     *
     * @param string $type
     * @param array  $parameters
     */
    public function __construct($type, $parameters = [])
    {
        $this->type = $type;
        $this->parameters = $parameters;
    }

    /**
     * Format current instance
     *
     * @return string
     */
    public function format(): string
    {
        return sprintf(
            '%s %s',
            ucfirst(strtolower($this->type)),
            $this->getParametersString()
        );
    }

    /**
     * Return current type
     *
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * Return value of given key from all parameters, if existing
     *
     * @param  mixed $key
     * @return mixed
     */
    public function getParameter($key)
    {
        return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : null;
    }

    /**
     * Format current parameters as string
     *
     * @return string
     */
    privat