| @@ 1542-1559 (lines=18) @@ | ||
| 1539 | * @return Assert |
|
| 1540 | * @throws AssertionFailedException |
|
| 1541 | */ |
|
| 1542 | public function utf8($message = null, $propertyPath = null) |
|
| 1543 | { |
|
| 1544 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1545 | { |
|
| 1546 | return $this; |
|
| 1547 | } |
|
| 1548 | $this->string($message, $propertyPath); |
|
| 1549 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1550 | { |
|
| 1551 | $message = $message |
|
| 1552 | ?: sprintf( |
|
| 1553 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1554 | $this->stringify($this->value) |
|
| 1555 | ); |
|
| 1556 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath); |
|
| 1557 | } |
|
| 1558 | return $this; |
|
| 1559 | } |
|
| 1560 | ||
| 1561 | ||
| 1562 | /** |
|
| @@ 1570-1587 (lines=18) @@ | ||
| 1567 | * @return Assert |
|
| 1568 | * @throws AssertionFailedException |
|
| 1569 | */ |
|
| 1570 | public function ascii($message = null, $propertyPath = null) |
|
| 1571 | { |
|
| 1572 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1573 | { |
|
| 1574 | return $this; |
|
| 1575 | } |
|
| 1576 | $this->string($message, $propertyPath); |
|
| 1577 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1578 | { |
|
| 1579 | $message = $message |
|
| 1580 | ?: sprintf( |
|
| 1581 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1582 | $this->stringify($this->value) |
|
| 1583 | ); |
|
| 1584 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath); |
|
| 1585 | } |
|
| 1586 | return $this; |
|
| 1587 | } |
|
| 1588 | ||
| 1589 | /** |
|
| 1590 | * Assert that key exists in an array/array-accessible object using isset() |
|