@@ 1730-1749 (lines=20) @@ | ||
1727 | * @return Assert |
|
1728 | * @throws AssertionFailedException |
|
1729 | */ |
|
1730 | public function utf8(string $message = '', string $fieldName = '') : Assert |
|
1731 | { |
|
1732 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1733 | { |
|
1734 | return $this; |
|
1735 | } |
|
1736 | $this->string($message, $fieldName); |
|
1737 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1738 | { |
|
1739 | $message = $message |
|
1740 | ?: sprintf( |
|
1741 | 'Value "%s" was expected to be a valid UTF8 string', |
|
1742 | $this->stringify($this->value) |
|
1743 | ); |
|
1744 | ||
1745 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $fieldName); |
|
1746 | } |
|
1747 | ||
1748 | return $this; |
|
1749 | } |
|
1750 | ||
1751 | ||
1752 | /** |
|
@@ 1760-1779 (lines=20) @@ | ||
1757 | * @return Assert |
|
1758 | * @throws AssertionFailedException |
|
1759 | */ |
|
1760 | public function ascii(string $message = '', string $fieldName = '') : Assert |
|
1761 | { |
|
1762 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1763 | { |
|
1764 | return $this; |
|
1765 | } |
|
1766 | $this->string($message, $fieldName); |
|
1767 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1768 | { |
|
1769 | $message = $message |
|
1770 | ?: sprintf( |
|
1771 | 'Value "%s" was expected to be a valid ASCII string', |
|
1772 | $this->stringify($this->value) |
|
1773 | ); |
|
1774 | ||
1775 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $fieldName); |
|
1776 | } |
|
1777 | ||
1778 | return $this; |
|
1779 | } |
|
1780 | ||
1781 | /** |
|
1782 | * Assert that key exists in an array/array-accessible object |
|
@@ 2659-2677 (lines=19) @@ | ||
2656 | * @return Assert |
|
2657 | * @throws AssertionFailedException |
|
2658 | */ |
|
2659 | public function samAccountName(string $message = '', string $fieldName = '') : Assert |
|
2660 | { |
|
2661 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2662 | { |
|
2663 | return $this; |
|
2664 | } |
|
2665 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
2666 | { |
|
2667 | $message = $message ?: $this->overrideError; |
|
2668 | $message = sprintf( |
|
2669 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
2670 | $this->stringify($this->value) |
|
2671 | ); |
|
2672 | ||
2673 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $fieldName); |
|
2674 | } |
|
2675 | ||
2676 | return $this; |
|
2677 | } |
|
2678 | ||
2679 | /** |
|
2680 | * Assert that value is a valid userPrincipalName. |