| @@ 511-520 (lines=10) @@ | ||
| 508 | } |
|
| 509 | } |
|
| 510 | ||
| 511 | public static function endsWith($value, $suffix, $message = '') |
|
| 512 | { |
|
| 513 | if ($suffix !== substr($value, -static::strlen($suffix))) { |
|
| 514 | throw static::createException(sprintf( |
|
| 515 | $message ?: 'Expected a value to end with %2$s. Got: %s', |
|
| 516 | static::valueToString($value), |
|
| 517 | static::valueToString($suffix) |
|
| 518 | )); |
|
| 519 | } |
|
| 520 | } |
|
| 521 | ||
| 522 | public static function regex($value, $pattern, $message = '') |
|
| 523 | { |
|
| @@ 666-676 (lines=11) @@ | ||
| 663 | } |
|
| 664 | } |
|
| 665 | ||
| 666 | public static function file($value, $message = '') |
|
| 667 | { |
|
| 668 | static::fileExists($value, $message); |
|
| 669 | ||
| 670 | if (!is_file($value)) { |
|
| 671 | throw static::createException(sprintf( |
|
| 672 | $message ?: 'The path %s is not a file.', |
|
| 673 | static::valueToString($value) |
|
| 674 | )); |
|
| 675 | } |
|
| 676 | } |
|
| 677 | ||
| 678 | public static function directory($value, $message = '') |
|
| 679 | { |
|
| @@ 678-688 (lines=11) @@ | ||
| 675 | } |
|
| 676 | } |
|
| 677 | ||
| 678 | public static function directory($value, $message = '') |
|
| 679 | { |
|
| 680 | static::fileExists($value, $message); |
|
| 681 | ||
| 682 | if (!is_dir($value)) { |
|
| 683 | throw static::createException(sprintf( |
|
| 684 | $message ?: 'The path %s is no directory.', |
|
| 685 | static::valueToString($value) |
|
| 686 | )); |
|
| 687 | } |
|
| 688 | } |
|
| 689 | ||
| 690 | public static function readable($value, $message = '') |
|
| 691 | { |
|
| @@ 731-740 (lines=10) @@ | ||
| 728 | } |
|
| 729 | } |
|
| 730 | ||
| 731 | public static function implementsInterface($value, $interface, $message = '') |
|
| 732 | { |
|
| 733 | if (!in_array($interface, class_implements($value))) { |
|
| 734 | throw static::createException(sprintf( |
|
| 735 | $message ?: 'Expected an implementation of %2$s. Got: %s', |
|
| 736 | static::valueToString($value), |
|
| 737 | static::valueToString($interface) |
|
| 738 | )); |
|
| 739 | } |
|
| 740 | } |
|
| 741 | ||
| 742 | public static function propertyExists($classOrObject, $property, $message = '') |
|
| 743 | { |
|