| @@ 1567-1584 (lines=18) @@ | ||
| 1564 | * @return Assert |
|
| 1565 | * @throws AssertionFailedException |
|
| 1566 | */ |
|
| 1567 | public function utf8($message = null, $propertyPath = null) |
|
| 1568 | { |
|
| 1569 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1570 | { |
|
| 1571 | return $this; |
|
| 1572 | } |
|
| 1573 | $this->string($message, $propertyPath); |
|
| 1574 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1575 | { |
|
| 1576 | $message = $message |
|
| 1577 | ?: sprintf( |
|
| 1578 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1579 | $this->stringify($this->value) |
|
| 1580 | ); |
|
| 1581 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath); |
|
| 1582 | } |
|
| 1583 | return $this; |
|
| 1584 | } |
|
| 1585 | ||
| 1586 | ||
| 1587 | /** |
|
| @@ 1595-1612 (lines=18) @@ | ||
| 1592 | * @return Assert |
|
| 1593 | * @throws AssertionFailedException |
|
| 1594 | */ |
|
| 1595 | public function ascii($message = null, $propertyPath = null) |
|
| 1596 | { |
|
| 1597 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1598 | { |
|
| 1599 | return $this; |
|
| 1600 | } |
|
| 1601 | $this->string($message, $propertyPath); |
|
| 1602 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1603 | { |
|
| 1604 | $message = $message |
|
| 1605 | ?: sprintf( |
|
| 1606 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1607 | $this->stringify($this->value) |
|
| 1608 | ); |
|
| 1609 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath); |
|
| 1610 | } |
|
| 1611 | return $this; |
|
| 1612 | } |
|
| 1613 | ||
| 1614 | /** |
|
| 1615 | * Assert that key exists in an array/array-accessible object using isset() |
|
| @@ 2432-2448 (lines=17) @@ | ||
| 2429 | * @return Assert |
|
| 2430 | * @throws AssertionFailedException |
|
| 2431 | */ |
|
| 2432 | public function samAccountName($message = null, $propertyPath = null) |
|
| 2433 | { |
|
| 2434 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2435 | { |
|
| 2436 | return $this; |
|
| 2437 | } |
|
| 2438 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2439 | { |
|
| 2440 | $message = $message ?: $this->overrideError; |
|
| 2441 | $message = sprintf( |
|
| 2442 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
| 2443 | $this->stringify($this->value) |
|
| 2444 | ); |
|
| 2445 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $propertyPath); |
|
| 2446 | } |
|
| 2447 | return $this; |
|
| 2448 | } |
|
| 2449 | ||
| 2450 | /** |
|
| 2451 | * Assert that the given string is a valid userPrincipalName |
|