@@ 470-479 (lines=10) @@ | ||
467 | } |
|
468 | } |
|
469 | ||
470 | public static function contains($value, $subString, $message = '') |
|
471 | { |
|
472 | if (false === strpos($value, $subString)) { |
|
473 | throw new InvalidArgumentException(sprintf( |
|
474 | $message ?: 'Expected a value to contain %2$s. Got: %s', |
|
475 | self::valueToString($value), |
|
476 | self::valueToString($subString) |
|
477 | )); |
|
478 | } |
|
479 | } |
|
480 | ||
481 | public static function startsWith($value, $prefix, $message = '') |
|
482 | { |
|
@@ 481-490 (lines=10) @@ | ||
478 | } |
|
479 | } |
|
480 | ||
481 | public static function startsWith($value, $prefix, $message = '') |
|
482 | { |
|
483 | if (0 !== strpos($value, $prefix)) { |
|
484 | throw new InvalidArgumentException(sprintf( |
|
485 | $message ?: 'Expected a value to start with %2$s. Got: %s', |
|
486 | self::valueToString($value), |
|
487 | self::valueToString($prefix) |
|
488 | )); |
|
489 | } |
|
490 | } |
|
491 | ||
492 | public static function startsWithLetter($value, $message = '') |
|
493 | { |
|
@@ 511-520 (lines=10) @@ | ||
508 | } |
|
509 | } |
|
510 | ||
511 | public static function endsWith($value, $suffix, $message = '') |
|
512 | { |
|
513 | if ($suffix !== substr($value, -self::strlen($suffix))) { |
|
514 | throw new InvalidArgumentException(sprintf( |
|
515 | $message ?: 'Expected a value to end with %2$s. Got: %s', |
|
516 | self::valueToString($value), |
|
517 | self::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 | self::fileExists($value, $message); |
|
669 | ||
670 | if (!is_file($value)) { |
|
671 | throw new InvalidArgumentException(sprintf( |
|
672 | $message ?: 'The path %s is not a file.', |
|
673 | self::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 | self::fileExists($value, $message); |
|
681 | ||
682 | if (!is_dir($value)) { |
|
683 | throw new InvalidArgumentException(sprintf( |
|
684 | $message ?: 'The path %s is no directory.', |
|
685 | self::valueToString($value) |
|
686 | )); |
|
687 | } |
|
688 | } |
|
689 | ||
690 | public static function readable($value, $message = '') |
|
691 | { |
|
@@ 720-729 (lines=10) @@ | ||
717 | } |
|
718 | } |
|
719 | ||
720 | public static function subclassOf($value, $class, $message = '') |
|
721 | { |
|
722 | if (!is_subclass_of($value, $class)) { |
|
723 | throw new InvalidArgumentException(sprintf( |
|
724 | $message ?: 'Expected a sub-class of %2$s. Got: %s', |
|
725 | self::valueToString($value), |
|
726 | self::valueToString($class) |
|
727 | )); |
|
728 | } |
|
729 | } |
|
730 | ||
731 | public static function implementsInterface($value, $interface, $message = '') |
|
732 | { |
|
@@ 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 new InvalidArgumentException(sprintf( |
|
735 | $message ?: 'Expected an implementation of %2$s. Got: %s', |
|
736 | self::valueToString($value), |
|
737 | self::valueToString($interface) |
|
738 | )); |
|
739 | } |
|
740 | } |
|
741 | ||
742 | public static function propertyExists($classOrObject, $property, $message = '') |
|
743 | { |