public static function AcceptHeaderItem::fromString

Builds an AcceptHeaderInstance instance from a string.

Parameters

string $itemValue:

Return value

AcceptHeaderItem

2 calls to AcceptHeaderItem::fromString()
AcceptHeader::fromString in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/AcceptHeader.php
Builds an AcceptHeader instance from a string.
AcceptHeaderItemTest::testFromString in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/AcceptHeaderItemTest.php
@dataProvider provideFromStringData

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/AcceptHeaderItem.php, line 62

Class

AcceptHeaderItem
Represents an Accept-* header item.

Namespace

Symfony\Component\HttpFoundation

Code

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);
}