| @@ 28-42 (lines=15) @@ | ||
| 25 | const USER_ID_PATTERN = '/^[a-zA-Z0-9-_.@]+$/'; |
|
| 26 | const DATE_PATTERN = '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/'; |
|
| 27 | ||
| 28 | public static function commonName($commonName, $isRequired) |
|
| 29 | { |
|
| 30 | $commonName = !empty($commonName) ? $commonName : null; |
|
| 31 | if (!$isRequired && is_null($commonName)) { |
|
| 32 | return; |
|
| 33 | } |
|
| 34 | if (0 === preg_match(self::COMMON_NAME_PATTERN, $commonName)) { |
|
| 35 | throw new BadRequestException('invalid value for "common_name"'); |
|
| 36 | } |
|
| 37 | if ('..' === $commonName) { |
|
| 38 | throw new BadRequestException('"common_name" cannot be ".."'); |
|
| 39 | } |
|
| 40 | ||
| 41 | return $commonName; |
|
| 42 | } |
|
| 43 | ||
| 44 | public static function userId($userId, $isRequired) |
|
| 45 | { |
|
| @@ 44-58 (lines=15) @@ | ||
| 41 | return $commonName; |
|
| 42 | } |
|
| 43 | ||
| 44 | public static function userId($userId, $isRequired) |
|
| 45 | { |
|
| 46 | $userId = !empty($userId) ? $userId : null; |
|
| 47 | if (!$isRequired && is_null($userId)) { |
|
| 48 | return; |
|
| 49 | } |
|
| 50 | if (0 === preg_match(self::USER_ID_PATTERN, $userId)) { |
|
| 51 | throw new BadRequestException('invalid value for "user_id"'); |
|
| 52 | } |
|
| 53 | if ('..' === $userId) { |
|
| 54 | throw new BadRequestException('"user_id" cannot be ".."'); |
|
| 55 | } |
|
| 56 | ||
| 57 | return $userId; |
|
| 58 | } |
|
| 59 | ||
| 60 | public static function date($date, $isRequired) |
|
| 61 | { |
|