Пример #1
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'date') {
         throw new InvalidArgumentException();
     }
     return new Date(new DateValue(\DateTimeImmutable::createFromFormat(\DateTime::RFC1123, (string) $value)));
 }
Пример #2
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'content-length') {
         throw new InvalidArgumentException();
     }
     return new ContentLength(new ContentLengthValue((int) (string) $value));
 }
Пример #3
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'location') {
         throw new InvalidArgumentException();
     }
     return new Location(new LocationValue(Url::fromString((string) $value)));
 }
Пример #4
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'content-encoding') {
         throw new InvalidArgumentException();
     }
     return new ContentEncoding(new ContentEncodingValue((string) $value));
 }
Пример #5
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'accept-ranges') {
         throw new InvalidArgumentException();
     }
     return new AcceptRanges(new AcceptRangesValue((string) $value));
 }
Пример #6
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'age') {
         throw new InvalidArgumentException();
     }
     return new Age(new AgeValue((int) (string) $value));
 }
Пример #7
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'host') {
         throw new InvalidArgumentException();
     }
     $url = Url::fromString((string) $value);
     return new Host(new HostValue($url->authority()->host(), $url->authority()->port()));
 }
Пример #8
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'range') {
         throw new InvalidArgumentException();
     }
     $matches = $value->getMatches('~^(?<unit>\\w+)=(?<first>\\d+)-(?<last>\\d+)$~');
     return new Range(new RangeValue((string) $matches->get('unit'), (int) (string) $matches->get('first'), (int) (string) $matches->get('last')));
 }
Пример #9
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'authorization') {
         throw new InvalidArgumentException();
     }
     $matches = $value->getMatches('~^"?(?<scheme>\\w+)"? ?(?<param>.+)?$~');
     return new Authorization(new AuthorizationValue((string) $matches->get('scheme'), $matches->hasKey('param') ? (string) $matches->get('param') : ''));
 }
Пример #10
0
 public function make(Str $name, Str $value) : HeaderInterface
 {
     if ((string) $name->toLower() !== 'content-range') {
         throw new InvalidArgumentException();
     }
     $matches = $value->trim()->getMatches('~^(?<unit>\\w+) (?<first>\\d+)-(?<last>\\d+)/(?<length>\\d+|\\*)$~');
     $length = (string) $matches->get('length');
     return new ContentRange(new ContentRangeValue((string) $matches->get('unit'), (int) (string) $matches->get('first'), (int) (string) $matches->get('last'), $length === '*' ? null : (int) $length));
 }