From 5006c754c42a09f5b88b258c2da4b9eff7508357 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 24 Jul 2022 14:03:04 +0300 Subject: readability: add missing dependencies --- .../league/uri/src/UriTemplate/VarSpecifier.php | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 plugins/af_readability/vendor/league/uri/src/UriTemplate/VarSpecifier.php (limited to 'plugins/af_readability/vendor/league/uri/src/UriTemplate/VarSpecifier.php') diff --git a/plugins/af_readability/vendor/league/uri/src/UriTemplate/VarSpecifier.php b/plugins/af_readability/vendor/league/uri/src/UriTemplate/VarSpecifier.php new file mode 100644 index 000000000..ac49efb53 --- /dev/null +++ b/plugins/af_readability/vendor/league/uri/src/UriTemplate/VarSpecifier.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\Uri\UriTemplate; + +use League\Uri\Exceptions\SyntaxError; +use function preg_match; + +final class VarSpecifier +{ + /** + * Variables specification regular expression pattern. + * + * @link https://tools.ietf.org/html/rfc6570#section-2.3 + */ + private const REGEXP_VARSPEC = '/^ + (?(?:[A-z0-9_\.]|%[0-9a-fA-F]{2})+) + (?\:(?\d+)|\*)? + $/x'; + + private string $name; + private string $modifier; + private int $position; + + private function __construct(string $name, string $modifier, int $position) + { + $this->name = $name; + $this->modifier = $modifier; + $this->position = $position; + } + + /** + * {@inheritDoc} + */ + public static function __set_state(array $properties): self + { + return new self($properties['name'], $properties['modifier'], $properties['position']); + } + + public static function createFromString(string $specification): self + { + if (1 !== preg_match(self::REGEXP_VARSPEC, $specification, $parsed)) { + throw new SyntaxError('The variable specification "'.$specification.'" is invalid.'); + } + + $parsed += ['modifier' => '', 'position' => '']; + if ('' !== $parsed['position']) { + $parsed['position'] = (int) $parsed['position']; + $parsed['modifier'] = ':'; + } + + if ('' === $parsed['position']) { + $parsed['position'] = 0; + } + + if (10000 <= $parsed['position']) { + throw new SyntaxError('The variable specification "'.$specification.'" is invalid the position modifier must be lower than 10000.'); + } + + return new self($parsed['name'], $parsed['modifier'], $parsed['position']); + } + + public function toString(): string + { + if (0 < $this->position) { + return $this->name.$this->modifier.$this->position; + } + + return $this->name.$this->modifier; + } + + public function name(): string + { + return $this->name; + } + + public function modifier(): string + { + return $this->modifier; + } + + public function position(): int + { + return $this->position; + } +} -- cgit v1.2.3