Stringy.php 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace AlibabaCloud\Client\Support;
  3. /**
  4. * Class Stringy
  5. *
  6. * @package AlibabaCloud\Client\Support
  7. */
  8. class Stringy
  9. {
  10. private static function _value($value, $default = '')
  11. {
  12. return null === $value ? $default : $value;
  13. }
  14. /**
  15. * @param string $str
  16. * @param string $substr
  17. *
  18. * @return bool
  19. */
  20. public static function contains($str, $substr)
  21. {
  22. return false !== strpos(self::_value($str), self::_value($substr));
  23. }
  24. /**
  25. * @param string $str
  26. * @param string $substr
  27. *
  28. * @return bool
  29. */
  30. public static function endsWith($str, $substr)
  31. {
  32. $str = self::_value($str);
  33. $substr = self::_value($substr);
  34. $length = \strlen($substr);
  35. if (!$length) {
  36. return true;
  37. }
  38. return substr($str, -$length) === $substr;
  39. }
  40. }