Open Journal Systems  3.3.0
vendor/symfony/http-foundation/AcceptHeaderItem.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
19 class AcceptHeaderItem
20 {
21  private $value;
22  private $quality = 1.0;
23  private $index = 0;
24  private $attributes = [];
25 
26  public function __construct(string $value, array $attributes = [])
27  {
28  $this->value = $value;
29  foreach ($attributes as $name => $value) {
30  $this->setAttribute($name, $value);
31  }
32  }
33 
41  public static function fromString($itemValue)
42  {
43  $parts = HeaderUtils::split($itemValue, ';=');
44 
45  $part = array_shift($parts);
46  $attributes = HeaderUtils::combine($parts);
47 
48  return new self($part[0], $attributes);
49  }
50 
56  public function __toString()
57  {
58  $string = $this->value.($this->quality < 1 ? ';q='.$this->quality : '');
59  if (\count($this->attributes) > 0) {
60  $string .= '; '.HeaderUtils::toString($this->attributes, ';');
61  }
62 
63  return $string;
64  }
65 
73  public function setValue($value)
74  {
75  $this->value = $value;
76 
77  return $this;
78  }
79 
85  public function getValue()
86  {
87  return $this->value;
88  }
89 
97  public function setQuality($quality)
98  {
99  $this->quality = $quality;
100 
101  return $this;
102  }
103 
109  public function getQuality()
110  {
111  return $this->quality;
112  }
113 
121  public function setIndex($index)
122  {
123  $this->index = $index;
124 
125  return $this;
126  }
127 
133  public function getIndex()
134  {
135  return $this->index;
136  }
137 
145  public function hasAttribute($name)
146  {
147  return isset($this->attributes[$name]);
148  }
149 
158  public function getAttribute($name, $default = null)
159  {
160  return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
161  }
162 
168  public function getAttributes()
169  {
170  return $this->attributes;
171  }
172 
181  public function setAttribute($name, $value)
182  {
183  if ('q' === $name) {
184  $this->quality = (float) $value;
185  } else {
186  $this->attributes[$name] = (string) $value;
187  }
188 
189  return $this;
190  }
191 }
Symfony\Component\HttpFoundation\AcceptHeaderItem\getIndex
getIndex()
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:133
Symfony\Component\HttpFoundation\AcceptHeaderItem\getAttribute
getAttribute($name, $default=null)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:158
Symfony\Component\HttpFoundation\HeaderUtils\combine
static combine(array $parts)
Definition: HeaderUtils.php:83
Symfony\Component\HttpFoundation\AcceptHeaderItem\getAttributes
getAttributes()
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:168
Symfony\Component\HttpFoundation\AcceptHeaderItem\setAttribute
setAttribute($name, $value)
Definition: lib/vendor/symfony/http-foundation/AcceptHeaderItem.php:228
Symfony\Component\HttpFoundation\AcceptHeaderItem\hasAttribute
hasAttribute($name)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:145
Symfony\Component\HttpFoundation\AcceptHeaderItem\fromString
static fromString($itemValue)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:41
Symfony\Component\HttpFoundation\AcceptHeaderItem\getQuality
getQuality()
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:109
Symfony\Component\HttpFoundation\AcceptHeaderItem\__toString
__toString()
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:56
Symfony\Component\HttpFoundation\AcceptHeaderItem\setValue
setValue($value)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:73
Symfony\Component\HttpFoundation
Definition: lib/vendor/symfony/http-foundation/AcceptHeader.php:12
Symfony\Component\HttpFoundation\AcceptHeaderItem\setIndex
setIndex($index)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:121
Symfony\Component\HttpFoundation\HeaderUtils\split
static split(string $header, string $separators)
Definition: HeaderUtils.php:45
Symfony\Component\HttpFoundation\AcceptHeaderItem\getValue
getValue()
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:85
Symfony\Component\HttpFoundation\AcceptHeaderItem\__construct
__construct(string $value, array $attributes=[])
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:26
Symfony\Component\HttpFoundation\AcceptHeaderItem\setQuality
setQuality($quality)
Definition: vendor/symfony/http-foundation/AcceptHeaderItem.php:97