| @@ 1544-1561 (lines=18) @@ | ||
| 1541 | * @return Assert |
|
| 1542 | * @throws AssertionFailedException |
|
| 1543 | */ |
|
| 1544 | public function utf8($message = null, $propertyPath = null) |
|
| 1545 | { |
|
| 1546 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1547 | { |
|
| 1548 | return $this; |
|
| 1549 | } |
|
| 1550 | $this->string($message, $propertyPath); |
|
| 1551 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1552 | { |
|
| 1553 | $message = $message |
|
| 1554 | ?: sprintf( |
|
| 1555 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1556 | $this->stringify($this->value) |
|
| 1557 | ); |
|
| 1558 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath); |
|
| 1559 | } |
|
| 1560 | return $this; |
|
| 1561 | } |
|
| 1562 | ||
| 1563 | ||
| 1564 | /** |
|
| @@ 1572-1589 (lines=18) @@ | ||
| 1569 | * @return Assert |
|
| 1570 | * @throws AssertionFailedException |
|
| 1571 | */ |
|
| 1572 | public function ascii($message = null, $propertyPath = null) |
|
| 1573 | { |
|
| 1574 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1575 | { |
|
| 1576 | return $this; |
|
| 1577 | } |
|
| 1578 | $this->string($message, $propertyPath); |
|
| 1579 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1580 | { |
|
| 1581 | $message = $message |
|
| 1582 | ?: sprintf( |
|
| 1583 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1584 | $this->stringify($this->value) |
|
| 1585 | ); |
|
| 1586 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath); |
|
| 1587 | } |
|
| 1588 | return $this; |
|
| 1589 | } |
|
| 1590 | ||
| 1591 | /** |
|
| 1592 | * Assert that key exists in an array/array-accessible object using isset() |
|
| @@ 2409-2425 (lines=17) @@ | ||
| 2406 | * @return Assert |
|
| 2407 | * @throws AssertionFailedException |
|
| 2408 | */ |
|
| 2409 | public function samAccountName($message = null, $propertyPath = null) |
|
| 2410 | { |
|
| 2411 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2412 | { |
|
| 2413 | return $this; |
|
| 2414 | } |
|
| 2415 | if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2416 | { |
|
| 2417 | $message = $message ?: $this->overrideError; |
|
| 2418 | $message = sprintf( |
|
| 2419 | $message ?: 'Value "%s" is not a valid samAccountName.', |
|
| 2420 | $this->stringify($this->value) |
|
| 2421 | ); |
|
| 2422 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $propertyPath); |
|
| 2423 | } |
|
| 2424 | return $this; |
|
| 2425 | } |
|
| 2426 | ||
| 2427 | /** |
|
| 2428 | * Assert that the given string is a valid userPrincipalName |
|