- md5
- 3af1aa7bdf9dd38373472c47f07ba70d
- sha1
- 889a0040c59362d752b0ae6976b6741d6a9b6cee
- sha256
- c63d6ce8dc43d876e2a6f9050f6f9b319ba65e46c414bb3b3ae21ee978497c0f
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
<?php
namespace Negotiation;
abstract class BaseAccept
{
/**
* @var float
*/
private $quality = 1.0;
/**
* @var string
*/
private $normalized;
/**
* @var string
*/
private $value;
/**
* @var array
*/
private $parameters;
/**
* @var string
*/
protected $type;
/**
* @param string $value
*/
public function __construct($value)
{
list($type, $parameters) = $this->parseParameters($value);
if (isset($parameters['q'])) {
$this->quality = (float) $parameters['q'];
unset($parameters['q']);
}
$type = trim(strtolower($type));
$this->value = $value;
$this->normalized = $type . ($parameters ? "; " . $this->buildParametersString($parameters) : '');
$this->type = $type;
$this->parameters = $parameters;
}
/**
* @return string
*/
public function getNormalizedValue()
{
return $this->normalized;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return float
*/
public function getQuality()
{
return $this->quality;
}
/**
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* @param string $key
* @param mixed $default
*
* @return string|null
*/
public function getParameter($key, $default = null)
{
return isset($this->parameters[$key]) ? $this->parameters[$key] : $default;
}
/**
* @param string $key
*
* @return boolean
*/
public function hasParameter($key)
{
return isset($this->parameters[$key]);
}
/**
*
* @param string $acceptPart
* @return array
*/
private function parseParameters($acceptPart)
{
$parts = explode(';', $acceptPart);
$type = array_shift($parts);
$parameters = [];
foreach ($parts as $part) {
$part = explode('=', $part);
if (2 !== count($part)) {
continue; // TODO: throw exception here?
}
$key = strtolower(trim($part[0])); // TODO: technically not allowed space around "=". throw exception?
$parameters[$key] = trim($part[1], ' "');
}
return [ $type, $parameters ];
}
/**
* @param string $parameters
*
* @return string
*/
private function buildParametersString($parameters)
{
$parts = [];
ksort($parameters);
foreach ($parameters as $key => $val) {
$parts[] = sprintf('%s=%s', $key, $val);
}
return implode('; ', $parts);
}
}
The same content is in 59 releases, Joomla 4.0.0-alpha7 to 4.2.0-alpha2. See them all, or every version of this file.