| @@ 1758-1777 (lines=20) @@ | ||
| 1755 | * @return Assert |
|
| 1756 | * @throws AssertionFailedException |
|
| 1757 | */ |
|
| 1758 | public function utf8(string $message='', string $fieldName='') : Assert |
|
| 1759 | { |
|
| 1760 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1761 | { |
|
| 1762 | return $this; |
|
| 1763 | } |
|
| 1764 | $this->string($message, $fieldName); |
|
| 1765 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1766 | { |
|
| 1767 | $message = $message |
|
| 1768 | ?: sprintf( |
|
| 1769 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1770 | $this->stringify($this->value) |
|
| 1771 | ); |
|
| 1772 | ||
| 1773 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $fieldName); |
|
| 1774 | } |
|
| 1775 | ||
| 1776 | return $this; |
|
| 1777 | } |
|
| 1778 | ||
| 1779 | ||
| 1780 | /** |
|
| @@ 1788-1807 (lines=20) @@ | ||
| 1785 | * @return Assert |
|
| 1786 | * @throws AssertionFailedException |
|
| 1787 | */ |
|
| 1788 | public function ascii(string $message='', string $fieldName='') : Assert |
|
| 1789 | { |
|
| 1790 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1791 | { |
|
| 1792 | return $this; |
|
| 1793 | } |
|
| 1794 | $this->string($message, $fieldName); |
|
| 1795 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1796 | { |
|
| 1797 | $message = $message |
|
| 1798 | ?: sprintf( |
|
| 1799 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1800 | $this->stringify($this->value) |
|
| 1801 | ); |
|
| 1802 | ||
| 1803 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $fieldName); |
|
| 1804 | } |
|
| 1805 | ||
| 1806 | return $this; |
|
| 1807 | } |
|
| 1808 | ||
| 1809 | /** |
|
| 1810 | * Assert that key exists in an array/array-accessible object |
|
| @@ 2687-2705 (lines=19) @@ | ||
| 2684 | * @return Assert |
|
| 2685 | * @throws AssertionFailedException |
|
| 2686 | */ |
|
| 2687 | public function samAccountName(string $message='', string $fieldName='') : Assert |
|
| 2688 | { |
|
| 2689 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2690 | { |
|
| 2691 | return $this; |
|
| 2692 | } |
|
| 2693 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2694 | { |
|
| 2695 | $message = $message ?: $this->overrideError; |
|
| 2696 | $message = sprintf( |
|
| 2697 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
| 2698 | $this->stringify($this->value) |
|
| 2699 | ); |
|
| 2700 | ||
| 2701 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $fieldName); |
|
| 2702 | } |
|
| 2703 | ||
| 2704 | return $this; |
|
| 2705 | } |
|
| 2706 | ||
| 2707 | /** |
|
| 2708 | * Assert that value is a valid userPrincipalName. |
|
| @@ 2750-2768 (lines=19) @@ | ||
| 2747 | * @return Assert |
|
| 2748 | * @throws AssertionFailedException |
|
| 2749 | */ |
|
| 2750 | public function isni(string $message='', string $fieldName='') |
|
| 2751 | { |
|
| 2752 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2753 | { |
|
| 2754 | return $this; |
|
| 2755 | } |
|
| 2756 | if ( !preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value) ) |
|
| 2757 | { |
|
| 2758 | $message = $message ?: $this->overrideError; |
|
| 2759 | $message = sprintf( |
|
| 2760 | $message ?: 'Value "%s" is not a valid ISNI.', |
|
| 2761 | $this->stringify($this->value) |
|
| 2762 | ); |
|
| 2763 | ||
| 2764 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ISNI, $fieldName); |
|
| 2765 | } |
|
| 2766 | ||
| 2767 | return $this; |
|
| 2768 | } |
|
| 2769 | ||
| 2770 | /** |
|
| 2771 | * Assert that the count of countable is equal to count. |
|