public static function AcceptHeaderItem::fromString in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-foundation/AcceptHeaderItem.php \Symfony\Component\HttpFoundation\AcceptHeaderItem::fromString()
Builds an AcceptHeaderInstance instance from a string.
Parameters
string $itemValue:
Return value
2 calls to AcceptHeaderItem::fromString()
- AcceptHeader::fromString in vendor/
symfony/ http-foundation/ AcceptHeader.php - Builds an AcceptHeader instance from a string.
- AcceptHeaderItemTest::testFromString in vendor/
symfony/ http-foundation/ Tests/ AcceptHeaderItemTest.php - @dataProvider provideFromStringData
File
- vendor/
symfony/ http-foundation/ AcceptHeaderItem.php, line 62
Class
- AcceptHeaderItem
- Represents an Accept-* header item.
Namespace
Symfony\Component\HttpFoundationCode
public static function fromString($itemValue) {
$bits = preg_split('/\\s*(?:;*("[^"]+");*|;*(\'[^\']+\');*|;+)\\s*/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$value = array_shift($bits);
$attributes = array();
$lastNullAttribute = null;
foreach ($bits as $bit) {
if (($start = substr($bit, 0, 1)) === ($end = substr($bit, -1)) && ($start === '"' || $start === '\'')) {
$attributes[$lastNullAttribute] = substr($bit, 1, -1);
}
elseif ('=' === $end) {
$lastNullAttribute = $bit = substr($bit, 0, -1);
$attributes[$bit] = null;
}
else {
$parts = explode('=', $bit);
$attributes[$parts[0]] = isset($parts[1]) && strlen($parts[1]) > 0 ? $parts[1] : '';
}
}
return new self(($start = substr($value, 0, 1)) === ($end = substr($value, -1)) && ($start === '"' || $start === '\'') ? substr($value, 1, -1) : $value, $attributes);
}