| @@ 1505-1522 (lines=18) @@ | ||
| 1502 | * @return Assert |
|
| 1503 | * @throws AssertionFailedException |
|
| 1504 | */ |
|
| 1505 | public function utf8($message = null, $propertyPath = null) |
|
| 1506 | { |
|
| 1507 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1508 | { |
|
| 1509 | return $this; |
|
| 1510 | } |
|
| 1511 | $this->string($message, $propertyPath); |
|
| 1512 | if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1513 | { |
|
| 1514 | $message = $message |
|
| 1515 | ?: sprintf( |
|
| 1516 | 'Value "%s" was expected to be a valid UTF8 string', |
|
| 1517 | $this->stringify($this->value) |
|
| 1518 | ); |
|
| 1519 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath); |
|
| 1520 | } |
|
| 1521 | return $this; |
|
| 1522 | } |
|
| 1523 | ||
| 1524 | ||
| 1525 | /** |
|
| @@ 1533-1550 (lines=18) @@ | ||
| 1530 | * @return Assert |
|
| 1531 | * @throws AssertionFailedException |
|
| 1532 | */ |
|
| 1533 | public function ascii($message = null, $propertyPath = null) |
|
| 1534 | { |
|
| 1535 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1536 | { |
|
| 1537 | return $this; |
|
| 1538 | } |
|
| 1539 | $this->string($message, $propertyPath); |
|
| 1540 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1541 | { |
|
| 1542 | $message = $message |
|
| 1543 | ?: sprintf( |
|
| 1544 | 'Value "%s" was expected to be a valid ASCII string', |
|
| 1545 | $this->stringify($this->value) |
|
| 1546 | ); |
|
| 1547 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath); |
|
| 1548 | } |
|
| 1549 | return $this; |
|
| 1550 | } |
|
| 1551 | ||
| 1552 | /** |
|
| 1553 | * Assert that key exists in an array/array-accessible object using isset() |
|