Beispiel #1
0
 public function __construct(string $range)
 {
     if (!(new Str($range))->match('~^\\w+$~')) {
         throw new InvalidArgumentException();
     }
     parent::__construct($range);
 }
Beispiel #2
0
 public function __construct(string $value)
 {
     if (!defined(MethodInterface::class . '::' . $value)) {
         throw new InvalidArgumentException();
     }
     parent::__construct($value);
 }
Beispiel #3
0
 public function __construct(int $age)
 {
     if ($age < 0) {
         throw new InvalidArgumentException();
     }
     parent::__construct((string) $age);
 }
Beispiel #4
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);
 }
Beispiel #5
0
 public function __construct(string $coding)
 {
     $coding = new Str($coding);
     if (!$coding->match('~^[\\w\\-]+$~')) {
         throw new InvalidArgumentException();
     }
     parent::__construct((string) $coding);
 }
Beispiel #6
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));
 }
Beispiel #7
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));
 }
Beispiel #8
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));
 }
Beispiel #9
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());
 }
Beispiel #10
0
 public function __construct(string $unit, int $firstPosition, int $lastPosition, int $length = null)
 {
     if (!(new Str($unit))->match('~^\\w+$~') || $firstPosition < 0 || $lastPosition < 0 || $length !== null && $length < 0 || $firstPosition > $lastPosition || $length !== null && $lastPosition > $length) {
         throw new InvalidArgumentException();
     }
     $this->unit = $unit;
     $this->firstPosition = $firstPosition;
     $this->lastPosition = $lastPosition;
     $this->length = $length;
     parent::__construct(sprintf('%s %s-%s/%s', $unit, $firstPosition, $lastPosition, $length ?? '*'));
 }
Beispiel #11
0
 public function __construct(UrlInterface $url, string $rel, MapInterface $parameters)
 {
     if (empty($rel) || (string) $parameters->keyType() !== 'string' || (string) $parameters->valueType() !== ParameterInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->url = $url;
     $this->rel = $rel;
     $this->parameters = $parameters;
     $parameters = $parameters->values()->join(';');
     $parameters = $parameters->length() > 0 ? $parameters->prepend(';') : $parameters;
     $link = (new Str('<%s>; rel="%s"'))->sprintf((string) $url, $rel);
     parent::__construct((string) $link->append((string) $parameters));
 }
Beispiel #12
0
 public function __construct(string $type, string $subType, MapInterface $parameters)
 {
     $media = (new Str('%s/%s'))->sprintf($type, $subType);
     if (!$media->match('~^\\*/\\*$~') && !$media->match('~^[\\w\\-.]+/\\*$~') && !$media->match('~^[\\w\\-.]+/[\\w\\-.]+$~')) {
         throw new InvalidArgumentException();
     }
     if ((string) $parameters->keyType() !== 'string' || (string) $parameters->valueType() !== ParameterInterface::class) {
         throw new InvalidArgumentException();
     }
     $this->type = $type;
     $this->subType = $subType;
     $this->parameters = $parameters;
     $parameters = $parameters->values()->join(';');
     $parameters = $parameters->length() > 0 ? $parameters->prepend(';') : $parameters;
     parent::__construct((string) $media->append((string) $parameters));
 }
Beispiel #13
0
 public function __construct(UrlInterface $url)
 {
     parent::__construct((string) $url);
 }