Kohana_HTTP_Header_Value represents a value assigned to an HTTP header, i.e.
Accept: [key=]value[; property[=property_value][; ...]]
Values are either single values,
Class declared in SYSPATH/classes/kohana/http/header/value.php on line 16.
float
$default_qualityThe default quality header property value
float 1
void|string
$keyarray
$propertiesarray
$valueBuilds the header field
mixed
$value
required - Value configuration array passedboolean
$no_parse
= bool FALSE - No_parse skip parsing of the string (i.e. user-agent)public function __construct($value, $no_parse = FALSE)
{
// If no parse is set, set the value and get out of here (user-agent)
if ($no_parse)
{
$this->key = NULL;
$this->value = $value;
return;
}
// If configuration array passed
if (is_array($value))
{
// Parse each value
foreach ($value as $k => $v)
{
// If the key is a property
if (property_exists($this, $k))
{
// Map values
$this->$k = $v;
}
}
}
// If value is a string
elseif (is_string($value))
{
// Detect properties
if (strpos($value, ';') !== FALSE)
{
// Remove properties from the string
$parts = explode(';', $value);
$value = array_shift($parts);
// Parse the properties
$properties = array();
// Foreach part
foreach ($parts as $part)
{
// Merge the parsed values
$properties = array_merge(HTTP_Header_Value::parse_key_value($part), $properties);
}
// Apply the parsed values
$this->properties = $properties;
}
// Parse the value and get key
$value = HTTP_Header_Value::parse_key_value($value);
$key = key($value);
// If the key is a string
if (is_string($key))
{
// Apply the key as a property
$this->key = $key;
}
// Apply the value
$this->value = current($value);
}
// Unrecognised value type
else
{
throw new HTTP_Exception_500(__METHOD__.' unknown header value type: :type. array or string allowed.', array(':type' => gettype($value)));
}
}
Magic method to handle object being cast to string. Produces the following header value syntax
[key=]value[; property[=property_value][; ... ]]
string
public function __toString()
{
$string = ($this->key !== NULL) ? ($this->key.'='.$this->value) : $this->value;
if ($this->properties)
{
$props = array($string);
foreach ($this->properties as $k => $v)
{
$props[] = is_int($k) ? $v : ($k.'='.$v);
}
$string = implode('; ', $props);
}
return $string;
}
Provides direct access to the key of this header value
string
$key
= NULL - Key value to setmixed
public function key($key = NULL)
{
if ($key === NULL)
{
return $this->key;
}
else
{
$this->key = $key;
return $this;
}
}
Detects and returns key/value pairs
string
$string
required - String to parsestring
$separator
= string(1) "=" - $separatorarray
public static function parse_key_value($string, $separator = '=')
{
$parts = explode($separator, trim($string), 2);
if (count($parts) == 1)
{
return $parts;
}
else
{
return array($parts[0] => $parts[1]);
}
}
Provides direct access to the properties of this header value
array
$properties
= array(0) - Properties to set to this valuemixed
public function properties(array $properties = array())
{
if ( ! $properties)
{
return $this->properties;
}
else
{
$this->properties = $properties;
return $this;
}
}
Provides direct access to the value of this header value
string
$value
= NULL - Value to setmixed
public function value($value = NULL)
{
if ($value === NULL)
{
return $this->value;
}
else
{
$this->value = $value;
return $this;
}
}