DateTimeFormats.php
1 year ago
IriFormats.php
1 year ago
MiscFormats.php
1 year ago
UriFormats.php
1 year ago
MiscFormats.php
59 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\Formats; |
| 19 | |
| 20 | class MiscFormats |
| 21 | { |
| 22 | const UUID_REGEX = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i'; |
| 23 | |
| 24 | /** |
| 25 | * @param string $value |
| 26 | * @return bool |
| 27 | */ |
| 28 | public static function ipv4(string $value): bool |
| 29 | { |
| 30 | return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param string $value |
| 35 | * @return bool |
| 36 | */ |
| 37 | public static function ipv6(string $value): bool |
| 38 | { |
| 39 | return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param string $value |
| 44 | * @return bool |
| 45 | */ |
| 46 | public static function email(string $value): bool |
| 47 | { |
| 48 | return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param string $value |
| 53 | * @return bool |
| 54 | */ |
| 55 | public static function uuid(string $value): bool |
| 56 | { |
| 57 | return (bool) preg_match(self::UUID_REGEX, $value); |
| 58 | } |
| 59 | } |