$params['rowCount'] = $params['rp'];
$params['sort'] = $params['sortBy'] ?? NULL;
$params['caseId'] = NULL;
- $context = $params['context'] ?? NULL;
- $showContactOverlay = !CRM_Utils_String::startsWith($context, "dashlet");
+ $context = $params['context'] ?? '';
+ $showContactOverlay = !str_starts_with($context, "dashlet");
$activityTypeInfo = civicrm_api3('OptionValue', 'get', [
'option_group_id' => "activity_type",
'options' => ['limit' => 0],
public function getKeysByPath($pattern) {
$keys = [];
- if (CRM_Utils_String::endsWith($pattern, '*')) {
+ if (str_ends_with($pattern, '*')) {
$prefix = rtrim($pattern, '*');
foreach ($this->container->getKeys() as $key) {
$path = CRM_Utils_File::addTrailingSlash($this->container->getPath($key));
$strBuf = strtolower(str_replace('-', '', $english));
foreach (self::$intervalsOfTen as $num => $name) {
- if (CRM_Utils_String::startsWith($strBuf, strtolower($name))) {
+ if (str_starts_with($strBuf, strtolower($name))) {
$intBuf += 10 * $num;
$strBuf = substr($strBuf, strlen($name));
break;
}
}
foreach (array_reverse(self::$lowNumbers, TRUE) as $num => $name) {
- if (CRM_Utils_String::startsWith($strBuf, strtolower($name))) {
+ if (str_starts_with($strBuf, strtolower($name))) {
$intBuf += $num;
$strBuf = substr($strBuf, strlen($name));
break;
}
/**
- * Determine if $string starts with $fragment.
+ * @deprecated
*
* @param string $string
* The long string.
* @return bool
*/
public static function startsWith($string, $fragment) {
- if ($fragment === '') {
- return TRUE;
- }
- $len = strlen($fragment ?? '');
- return substr(($string ?? ''), 0, $len) === $fragment;
+ CRM_Core_Error::deprecatedFunctionWarning('str_starts_with');
+ return str_starts_with((string) $string, (string) $fragment);
}
/**
- * Determine if $string ends with $fragment.
+ * @deprecated
*
* @param string $string
* The long string.
* @return bool
*/
public static function endsWith($string, $fragment) {
- if ($fragment === '') {
- return TRUE;
- }
- $len = strlen($fragment ?? '');
- return substr(($string ?? ''), -1 * $len) === $fragment;
+ CRM_Core_Error::deprecatedFunctionWarning('str_ends_with');
+ return str_ends_with((string) $string, (string) $fragment);
}
/**
$patterns = (array) $patterns;
$result = [];
foreach ($patterns as $pattern) {
- if (!\CRM_Utils_String::endsWith($pattern, '*')) {
+ if (!str_ends_with($pattern, '*')) {
if ($allowNew || in_array($pattern, $allStrings)) {
$result[] = $pattern;
}
else {
$prefix = rtrim($pattern, '*');
foreach ($allStrings as $key) {
- if (\CRM_Utils_String::startsWith($key, $prefix)) {
+ if (str_starts_with($key, $prefix)) {
$result[] = $key;
}
}
default:
if (in_array($token, $supportedTokens)) {
$value = $membership[$token];
- if (CRM_Utils_String::endsWith($token, '_date')) {
+ if (str_ends_with($token, '_date')) {
$value = CRM_Utils_Date::customFormat($value);
}
}
$value = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $token, $value);
}
}
- elseif ($value && CRM_Utils_String::endsWith($token, '_date')) {
+ elseif ($value && str_ends_with($token, '_date')) {
$value = CRM_Utils_Date::customFormat($value);
}
return $value;
yield from [];
foreach ($clazz->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
- if (\CRM_Utils_String::startsWith($m->getName(), $prefix)) {
+ if (str_starts_with($m->getName(), $prefix)) {
yield $m;
}
}
* @return mixed
*/
protected function callApi4AjaxSuccess(string $entity, string $action, $params = []) {
- $method = \CRM_Utils_String::startsWith($action, 'get') ? 'GET' : 'POST';
+ $method = str_starts_with($action, 'get') ? 'GET' : 'POST';
$response = $this->createGuzzle()->request($method, "civicrm/ajax/api4/$entity/$action", [
'headers' => ['X-Requested-With' => 'XMLHttpRequest'],
// This should probably be 'form_params', but 'query' is more representative of frontend.
* @return mixed
*/
protected function callApi4AjaxError(string $entity, string $action, $params = []) {
- $method = \CRM_Utils_String::startsWith($action, 'get') ? 'GET' : 'POST';
+ $method = str_starts_with($action, 'get') ? 'GET' : 'POST';
$response = $this->createGuzzle()->request($method, "civicrm/ajax/api4/$entity/$action", [
'headers' => ['X-Requested-With' => 'XMLHttpRequest'],
// This should probably be 'form_params', but 'query' is more representative of frontend.
function _authx_reload($route, $queryString) {
parse_str($queryString, $query);
foreach (array_keys($query) as $key) {
- if (CRM_Utils_String::startsWith($key, '_authx')) {
+ if (str_starts_with($key, '_authx')) {
unset($query[$key]);
}
}
//Return if searched string ends with an unsupported operator.
//Or if the string contains an invalid joint occurrence of operators.
foreach ($operators as $val) {
- if ($text == '@' || CRM_Utils_String::endsWith($text, $val) || preg_match("/[{$expression}]{2,}/", $text)) {
+ if ($text == '@' || str_ends_with($text, $val) || preg_match("/[{$expression}]{2,}/", $text)) {
$csid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'CRM_Contact_Form_Search_Custom_FullText', 'value', 'name');
$url = CRM_Utils_System::url("civicrm/contact/search/custom", "csid={$csid}&reset=1");
$operators = implode("', '", $operators);
$discountedItems = 0;
foreach ($lineItemResult['values'] as $lineItem) {
$this->assertEquals(round($lineItem['line_total'] * .1, 2), $lineItem['tax_amount']);
- if (CRM_Utils_String::startsWith($lineItem['label'], 'Long Haired Goat')) {
+ if (str_starts_with($lineItem['label'], 'Long Haired Goat')) {
$this->assertEquals(15.0, $lineItem['line_total']);
$this->assertEquals('Long Haired Goat - one leg free!', $lineItem['label']);
$discountedItems++;
// Form an expected array replacing tokens for each contact.
foreach ($tokens as $key => $val) {
- if (CRM_Utils_String::endsWith($val, '_date')) {
+ if (str_ends_with($val, '_date')) {
$formattedDate = CRM_Utils_Date::customFormat($params[$val]);
$expected[$contactId][$val] = "{$key} - {$formattedDate}";
}
$this->assertSame($expected, $actual);
}
- /**
- * Data provider for checking how strings start and end.
- *
- * @noinspection SpellCheckingInspection
- */
- public function startEndCases(): array {
- $cases = [];
- $cases[] = ['startsWith', 'foo', '', TRUE];
- $cases[] = ['startsWith', 'foo', 'f', TRUE];
- $cases[] = ['startsWith', 'foo', 'fo', TRUE];
- $cases[] = ['startsWith', 'foo', 'foo', TRUE];
- $cases[] = ['startsWith', 'foo', 'fooo', FALSE];
- $cases[] = ['startsWith', 'foo', 'o', FALSE];
- $cases[] = ['endsWith', 'foo', 'f', FALSE];
- $cases[] = ['endsWith', 'foo', '', TRUE];
- $cases[] = ['endsWith', 'foo', 'o', TRUE];
- $cases[] = ['endsWith', 'foo', 'oo', TRUE];
- $cases[] = ['endsWith', 'foo', 'foo', TRUE];
- $cases[] = ['endsWith', 'foo', 'fooo', FALSE];
- $cases[] = ['endsWith', 'foo*', '*', TRUE];
- return $cases;
- }
-
- /**
- * @param string $function
- * One of: 'startsWith' or 'endsWith'.
- * @param $string
- * @param $fragment
- * @param $expectedResult
- *
- * @dataProvider startEndCases
- */
- public function testStartEndWith(string $function, $string, $fragment, $expectedResult): void {
- $actualResult = CRM_Utils_String::$function($string, $fragment);
- $this->assertEquals($expectedResult, $actualResult, "Checking $function($string,$fragment)");
- }
-
public function wildcardCases(): array {
$cases = [];
$cases[] = ['*', ['foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang']];