/usr/share/php/kohana3.1/system/classes/kohana/http/header/value.php is in libkohana3.1-core-php 3.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | <?php defined('SYSPATH') or die('No direct script access.');
/**
* 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,
*
* @package Kohana
* @category HTTP
* @author Kohana Team
* @since 3.1.0
* @copyright (c) 2008-2011 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_HTTP_Header_Value {
/**
* @var float The default quality header property value
*/
public static $default_quality = 1.0;
/**
* Detects and returns key/value pairs
*
* @param string $string String to parse
* @param string $separator
* @return array
*/
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]);
}
}
/**
* @var array
*/
public $properties = array();
/**
* @var void|string
*/
public $key;
/**
* @var array
*/
public $value = array();
/**
* Builds the header field
*
* @param mixed value configuration array passed
* @param boolean no_parse skip parsing of the string (i.e. user-agent)
* @throws Kohana_HTTP_Exception
*/
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)));
}
}
/**
* Provides direct access to the key of this header value
*
* @param string $key Key value to set
* @return mixed
*/
public function key($key = NULL)
{
if ($key === NULL)
{
return $this->key;
}
else
{
$this->key = $key;
return $this;
}
}
/**
* Provides direct access to the value of this header value
*
* @param string $value Value to set
* @return mixed
*/
public function value($value = NULL)
{
if ($value === NULL)
{
return $this->value;
}
else
{
$this->value = $value;
return $this;
}
}
/**
* Provides direct access to the properties of this header value
*
* @param array $properties Properties to set to this value
* @return mixed
*/
public function properties(array $properties = array())
{
if ( ! $properties)
{
return $this->properties;
}
else
{
$this->properties = $properties;
return $this;
}
}
/**
* Magic method to handle object being cast to
* string. Produces the following header value syntax
*
* [key=]value[; property[=property_value][; ... ]]
*
* @return 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;
}
} // End Kohana_HTTP_Header_Value
|