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'))); }
public static function fromString(string $type, Types $types) : TypeInterface { $type = new Str($type); if (!$type->match(self::PATTERN)) { throw new InvalidArgumentException(); } return new self((string) $type->getMatches(self::PATTERN)->get('format')); }
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') : '')); }