|
@@ 998-1016 (lines=19) @@
|
| 995 |
|
* @return Assert |
| 996 |
|
* @throws AssertionFailedException |
| 997 |
|
*/ |
| 998 |
|
public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 999 |
|
{ |
| 1000 |
|
if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
| 1001 |
|
{ |
| 1002 |
|
return $this; |
| 1003 |
|
} |
| 1004 |
|
$this->string($message, $propertyPath); |
| 1005 |
|
if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
| 1006 |
|
{ |
| 1007 |
|
$message = sprintf( |
| 1008 |
|
$message ?: 'Value "%s" does not start with "%s".', |
| 1009 |
|
$this->stringify($this->value), |
| 1010 |
|
$this->stringify($needle) |
| 1011 |
|
); |
| 1012 |
|
$constraints = ['needle' => $needle, 'encoding' => $encoding]; |
| 1013 |
|
throw $this->createException($message, self::INVALID_STRING_START, $propertyPath, $constraints); |
| 1014 |
|
} |
| 1015 |
|
return $this; |
| 1016 |
|
} |
| 1017 |
|
|
| 1018 |
|
/** |
| 1019 |
|
* Assert that string ends with a sequence of chars. |
|
@@ 1059-1077 (lines=19) @@
|
| 1056 |
|
* @return Assert |
| 1057 |
|
* @throws AssertionFailedException |
| 1058 |
|
*/ |
| 1059 |
|
public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1060 |
|
{ |
| 1061 |
|
if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
| 1062 |
|
{ |
| 1063 |
|
return $this; |
| 1064 |
|
} |
| 1065 |
|
$this->string($message, $propertyPath); |
| 1066 |
|
if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
| 1067 |
|
{ |
| 1068 |
|
$message = sprintf( |
| 1069 |
|
$message ?: 'Value "%s" does not contain "%s".', |
| 1070 |
|
$this->stringify($this->value), |
| 1071 |
|
$this->stringify($needle) |
| 1072 |
|
); |
| 1073 |
|
$constraints = ['needle' => $needle, 'encoding' => $encoding]; |
| 1074 |
|
throw $this->createException($message, self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
| 1075 |
|
} |
| 1076 |
|
return $this; |
| 1077 |
|
} |
| 1078 |
|
|
| 1079 |
|
/** |
| 1080 |
|
* Assert that value is in array of choices. |