| @@ 1645-1662 (lines=18) @@ | ||
| 1642 | * @return Assert |
|
| 1643 | * @throws AssertionFailedException |
|
| 1644 | */ |
|
| 1645 | public function utf8($message = null, $fieldName = null) |
|
| 1646 | { |
|
| 1647 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1648 | { |
|
| 1649 | return $this; |
|
| 1650 | } |
|
| 1651 | $this->string($message, $fieldName); |
|
| 1652 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1653 | { |
|
| 1654 | $message = $message |
|
| 1655 | ?: sprintf( |
|
| 1656 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1657 | $this->stringify($this->value) |
|
| 1658 | ); |
|
| 1659 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $fieldName); |
|
| 1660 | } |
|
| 1661 | return $this; |
|
| 1662 | } |
|
| 1663 | ||
| 1664 | ||
| 1665 | /** |
|
| @@ 1673-1690 (lines=18) @@ | ||
| 1670 | * @return Assert |
|
| 1671 | * @throws AssertionFailedException |
|
| 1672 | */ |
|
| 1673 | public function ascii($message = null, $fieldName = null) |
|
| 1674 | { |
|
| 1675 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1676 | { |
|
| 1677 | return $this; |
|
| 1678 | } |
|
| 1679 | $this->string($message, $fieldName); |
|
| 1680 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1681 | { |
|
| 1682 | $message = $message |
|
| 1683 | ?: sprintf( |
|
| 1684 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1685 | $this->stringify($this->value) |
|
| 1686 | ); |
|
| 1687 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $fieldName); |
|
| 1688 | } |
|
| 1689 | return $this; |
|
| 1690 | } |
|
| 1691 | ||
| 1692 | /** |
|
| 1693 | * Assert that key exists in an array/array-accessible object |
|
| @@ 2518-2534 (lines=17) @@ | ||
| 2515 | * @return Assert |
|
| 2516 | * @throws AssertionFailedException |
|
| 2517 | */ |
|
| 2518 | public function samAccountName($message = null, $fieldName = null) |
|
| 2519 | { |
|
| 2520 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2521 | { |
|
| 2522 | return $this; |
|
| 2523 | } |
|
| 2524 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2525 | { |
|
| 2526 | $message = $message ?: $this->overrideError; |
|
| 2527 | $message = sprintf( |
|
| 2528 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
| 2529 | $this->stringify($this->value) |
|
| 2530 | ); |
|
| 2531 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $fieldName); |
|
| 2532 | } |
|
| 2533 | return $this; |
|
| 2534 | } |
|
| 2535 | ||
| 2536 | /** |
|
| 2537 | * Assert that value is a valid userPrincipalName. |
|