class HttpHeader in RESTful 7.2
Hierarchy
- class \Drupal\restful\Http\HttpHeader implements HttpHeaderInterface
Expanded class hierarchy of HttpHeader
6 files declare their use of HttpHeader
- CacheDecoratedResource.php in src/
Plugin/ resource/ Decorators/ CacheDecoratedResource.php - Contains \Drupal\restful\Plugin\resource\Decorators\CacheDecoratedResource
- DataProvider.php in src/
Plugin/ resource/ DataProvider/ DataProvider.php - Contains \Drupal\restful\Plugin\resource\DataProvider\DataProvider.
- FormatterManager.php in src/
Formatter/ FormatterManager.php - Contains \Drupal\restful\Formatter\FormatterManager
- RateLimitManager.php in src/
RateLimit/ RateLimitManager.php - Contains \Drupal\restful\RateLimit\RateLimitManager
- Resource.php in src/
Plugin/ resource/ Resource.php - Contains \Drupal\restful\Plugin\resource\Resource.
File
- src/
Http/ HttpHeader.php, line 10 - Contains \Drupal\restful\Http\HttpHeader
Namespace
Drupal\restful\HttpView source
class HttpHeader implements HttpHeaderInterface {
/**
* Header ID.
*
* @var string
*/
protected $id;
/**
* Header name.
*
* @var string
*/
protected $name;
/**
* Header values.
*
* @var array
*/
protected $values = array();
/**
* Header extras.
*
* @var string
*/
protected $extras;
/**
* Constructor.
*/
public function __construct($name, array $values, $extras) {
$this->name = $name;
$this->id = static::generateId($name);
$this->values = $values;
$this->extras = $extras;
}
/**
* {@inheritdoc}
*/
public static function create($key, $value) {
list($extras, $values) = self::parseHeaderValue($value);
return new static($key, $values, $extras);
}
/**
* {@inheritdoc}
*/
public function get() {
return $this->values;
}
/**
* {@inheritdoc}
*/
public function getValueString() {
$parts = array();
$parts[] = implode(', ', $this->values);
$parts[] = $this->extras;
return implode('; ', array_filter($parts));
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* Returns the string version of the header.
*
* @return string
*/
public function __toString() {
return $this->name . ': ' . $this
->getValueString();
}
/**
* {@inheritdoc}
*/
public function set($values) {
$this->values = $values;
}
/**
* {@inheritdoc}
*/
public function append($value) {
// Ignore the extras.
list(, $values) = static::parseHeaderValue($value);
foreach ($values as $value) {
$this->values[] = $value;
}
}
/**
* {@inheritdoc}
*/
public function getId() {
return $this->id;
}
/**
* {@inheritdoc}
*/
public static function generateId($name) {
return strtolower($name);
}
/**
* Parses the values and extras from a header value string.
*
* @param string $value
*
* @return array
* The $extras and $values.
*/
protected static function parseHeaderValue($value) {
$extras = NULL;
$parts = explode(';', $value);
if (count($parts) > 1) {
// Only consider the last element.
$extras = array_pop($parts);
$extras = trim($extras);
// In case there were more than one ';' then put everything back.
$value = implode(';', $parts);
}
$values = array_map('trim', explode(',', $value));
return array(
$extras,
$values,
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HttpHeader:: |
protected | property | Header extras. | |
HttpHeader:: |
protected | property | Header ID. | |
HttpHeader:: |
protected | property | Header name. | |
HttpHeader:: |
protected | property | Header values. | |
HttpHeader:: |
public | function |
Appends a value into a header. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public static | function |
Creates a header object from the key and value strings. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public static | function |
Generates the header ID based on the header name. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public | function |
Gets the values of the header. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public | function |
Gets the header id. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public | function |
Gets the header name. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public | function |
Gets the contents of the header. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
protected static | function | Parses the values and extras from a header value string. | |
HttpHeader:: |
public | function |
Sets the values. Overrides HttpHeaderInterface:: |
|
HttpHeader:: |
public | function | Constructor. | |
HttpHeader:: |
public | function | Returns the string version of the header. |