| @@ 1762-1781 (lines=20) @@ | ||
| 1759 | * @return Assert |
|
| 1760 | * @throws AssertionFailedException |
|
| 1761 | */ |
|
| 1762 | public function utf8(string $message='', string $fieldName='') : Assert |
|
| 1763 | { |
|
| 1764 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1765 | { |
|
| 1766 | return $this; |
|
| 1767 | } |
|
| 1768 | $this->string($message, $fieldName); |
|
| 1769 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1770 | { |
|
| 1771 | $message = $message |
|
| 1772 | ?: sprintf( |
|
| 1773 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1774 | $this->stringify($this->value) |
|
| 1775 | ); |
|
| 1776 | ||
| 1777 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $fieldName); |
|
| 1778 | } |
|
| 1779 | ||
| 1780 | return $this; |
|
| 1781 | } |
|
| 1782 | ||
| 1783 | ||
| 1784 | /** |
|
| @@ 1792-1811 (lines=20) @@ | ||
| 1789 | * @return Assert |
|
| 1790 | * @throws AssertionFailedException |
|
| 1791 | */ |
|
| 1792 | public function ascii(string $message='', string $fieldName='') : Assert |
|
| 1793 | { |
|
| 1794 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1795 | { |
|
| 1796 | return $this; |
|
| 1797 | } |
|
| 1798 | $this->string($message, $fieldName); |
|
| 1799 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1800 | { |
|
| 1801 | $message = $message |
|
| 1802 | ?: sprintf( |
|
| 1803 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1804 | $this->stringify($this->value) |
|
| 1805 | ); |
|
| 1806 | ||
| 1807 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $fieldName); |
|
| 1808 | } |
|
| 1809 | ||
| 1810 | return $this; |
|
| 1811 | } |
|
| 1812 | ||
| 1813 | /** |
|
| 1814 | * Assert that key exists in an array/array-accessible object |
|
| @@ 2691-2709 (lines=19) @@ | ||
| 2688 | * @return Assert |
|
| 2689 | * @throws AssertionFailedException |
|
| 2690 | */ |
|
| 2691 | public function samAccountName(string $message='', string $fieldName='') : Assert |
|
| 2692 | { |
|
| 2693 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2694 | { |
|
| 2695 | return $this; |
|
| 2696 | } |
|
| 2697 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2698 | { |
|
| 2699 | $message = $message ?: $this->overrideError; |
|
| 2700 | $message = sprintf( |
|
| 2701 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
| 2702 | $this->stringify($this->value) |
|
| 2703 | ); |
|
| 2704 | ||
| 2705 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $fieldName); |
|
| 2706 | } |
|
| 2707 | ||
| 2708 | return $this; |
|
| 2709 | } |
|
| 2710 | ||
| 2711 | /** |
|
| 2712 | * Assert that value is a valid userPrincipalName. |
|