Example #1
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)));
 }
Example #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));
 }
Example #3
0
 private function isValidProperty(string $property, EntityInterface $meta) : bool
 {
     if ($meta->properties()->contains($property)) {
         return true;
     }
     $property = new Str($property);
     if (!$property->match('/[a-zA-Z]+(\\.[a-zA-Z]+)+/')) {
         return false;
     }
     $pieces = $property->split('.');
     $piece = (string) $pieces->get(0);
     if (!$meta->children()->contains($piece)) {
         return false;
     }
     $child = $meta->children()->get($piece);
     $relationship = $child->relationship();
     switch ($pieces->count()) {
         case 2:
             return $relationship->properties()->contains((string) $pieces->get(1));
         case 3:
             $subPiece = (string) $pieces->get(1);
             if (!$relationship->childProperty() === $subPiece) {
                 return false;
             }
             return $child->properties()->contains((string) $pieces->get(2));
     }
     return false;
 }
Example #4
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)));
 }
Example #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));
 }
Example #6
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));
 }
Example #7
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));
 }
Example #8
0
 public function __construct(string $coding)
 {
     $coding = new Str($coding);
     if (!$coding->match('~^[\\w\\-]+$~')) {
         throw new InvalidArgumentException();
     }
     parent::__construct((string) $coding);
 }
Example #9
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')));
 }
Example #10
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') : ''));
 }
Example #11
0
 public function __construct(string $language)
 {
     $language = new Str($language);
     if (!$language->match('~^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$~')) {
         throw new InvalidArgumentException();
     }
     parent::__construct((string) $language);
 }
Example #12
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()));
 }
Example #13
0
 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'));
 }
Example #14
0
 public function __construct(string $language, Quality $quality)
 {
     $language = new Str($language);
     if ((string) $language !== '*' && !$language->match('~^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$~')) {
         throw new InvalidArgumentException();
     }
     $this->quality = $quality;
     parent::__construct((string) $language->append(';')->append((string) $quality));
 }
Example #15
0
 public function __construct(string $coding, Quality $quality)
 {
     $coding = new Str($coding);
     if ((string) $coding !== '*' && !$coding->match('~^\\w+$~')) {
         throw new InvalidArgumentException();
     }
     $this->quality = $quality;
     parent::__construct((string) $coding->append(';')->append((string) $quality));
 }
Example #16
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));
 }
Example #17
0
 public function __construct(string $charset, Quality $quality)
 {
     $charset = new Str($charset);
     if ((string) $charset !== '*' && !$charset->match('~^[a-zA-Z0-9\\-_:\\(\\)]+$~')) {
         throw new InvalidArgumentException();
     }
     $this->quality = $quality;
     parent::__construct((string) $charset->append(';')->append((string) $quality));
 }
Example #18
0
 public function __construct(string $scheme, string $parameter)
 {
     $scheme = new Str($scheme);
     if (!$scheme->match('~^\\w+$~')) {
         throw new InvalidArgumentException();
     }
     $this->scheme = (string) $scheme;
     $this->parameter = $parameter;
     parent::__construct((string) $scheme->prepend('"')->append('" ')->append($parameter)->trim());
 }
Example #19
0
 public function __construct(string $value)
 {
     if (!(new AbsolutePath())->isSatisfiedBy(new Url($value))) {
         throw new InvalidArgumentException(sprintf('The value "%s" is not a valid path', $value));
     }
     parent::__construct($value);
 }
Example #20
0
 public function __construct(string $value)
 {
     parent::__construct($value);
     if (!$this->match('/^[a-z]+$/')) {
         throw new InvalidArgumentException(sprintf('The value "%s" is not a valid scheme', $value));
     }
 }
Example #21
0
 public function __construct(string $value)
 {
     if (!(new FragmentSpecification())->isSatisfiedBy(new Url($value))) {
         throw new InvalidArgumentException(sprintf('The value "%s" is not a valid fragment', $value));
     }
     parent::__construct($value);
 }