Errors
1 year ago
Exceptions
1 year ago
Filters
1 year ago
Formats
1 year ago
Info
1 year ago
KeywordValidators
1 year ago
Keywords
1 year ago
Parsers
1 year ago
Pragmas
1 year ago
Resolvers
1 year ago
Schemas
1 year ago
Variables
1 year ago
CompliantValidator.php
1 year ago
ContentEncoding.php
1 year ago
ContentMediaType.php
1 year ago
Filter.php
1 year ago
Format.php
1 year ago
Helper.php
1 year ago
JsonPointer.php
1 year ago
Keyword.php
1 year ago
KeywordValidator.php
1 year ago
Pragma.php
1 year ago
Schema.php
1 year ago
SchemaLoader.php
7 months ago
SchemaValidator.php
1 year ago
Uri.php
1 year ago
ValidationContext.php
7 months ago
ValidationResult.php
1 year ago
Validator.php
1 year ago
Variables.php
1 year ago
Uri.php
95 lines
| 1 | <?php |
| 2 | /* ============================================================================ |
| 3 | * Copyright 2020 Zindex Software |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * ============================================================================ */ |
| 17 | |
| 18 | namespace Opis\JsonSchema; |
| 19 | |
| 20 | use JsonSerializable; |
| 21 | use Opis\Uri\Uri as BaseUri; |
| 22 | |
| 23 | class Uri extends BaseUri implements JsonSerializable |
| 24 | { |
| 25 | /** |
| 26 | * @var bool Set this to true and the qs will always be sorted |
| 27 | */ |
| 28 | protected static bool $useNormalizedComponents = false; |
| 29 | |
| 30 | public function __construct(array $components) |
| 31 | { |
| 32 | if (static::$useNormalizedComponents) { |
| 33 | $components = self::normalizeComponents($components); |
| 34 | } |
| 35 | parent::__construct($components); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @inheritDoc |
| 40 | */ |
| 41 | public function jsonSerialize(): string |
| 42 | { |
| 43 | return $this->__toString(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param string $uri |
| 48 | * @param bool $ensure_fragment |
| 49 | * @return static|null |
| 50 | */ |
| 51 | public static function parse(string $uri, bool $ensure_fragment = false): ?self |
| 52 | { |
| 53 | if ($ensure_fragment && strpos($uri, '#') === false) { |
| 54 | $uri .= '#'; |
| 55 | } |
| 56 | |
| 57 | return self::create($uri); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param string|array|static $uri |
| 62 | * @param string|array|static $base |
| 63 | * @param bool $ensure_fragment |
| 64 | * @return static|null |
| 65 | */ |
| 66 | public static function merge($uri, $base, bool $ensure_fragment = false): ?self |
| 67 | { |
| 68 | $uri = self::resolveComponents($uri); |
| 69 | |
| 70 | if ($uri === null) { |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | if ($ensure_fragment && !isset($uri['fragment'])) { |
| 75 | $uri['fragment'] = ''; |
| 76 | } |
| 77 | |
| 78 | $base = self::resolveComponents($base); |
| 79 | |
| 80 | if (!$base) { |
| 81 | return new self($uri); |
| 82 | } |
| 83 | |
| 84 | return new self(self::mergeComponents($uri, $base)); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @param bool $value |
| 89 | */ |
| 90 | public static function useNormalizedComponents(bool $value): void |
| 91 | { |
| 92 | self::$useNormalizedComponents = $value; |
| 93 | } |
| 94 | } |
| 95 |