function Number::alphadecimalToInt

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Number.php \Drupal\Component\Utility\Number::alphadecimalToInt()
  2. 8.9.x core/lib/Drupal/Component/Utility/Number.php \Drupal\Component\Utility\Number::alphadecimalToInt()
  3. 10 core/lib/Drupal/Component/Utility/Number.php \Drupal\Component\Utility\Number::alphadecimalToInt()

Decodes a sorting code back to an integer.

Parameters

string $string: The alpha decimal value to convert.

Return value

int The integer value.

Throws

\InvalidArgumentException If $string contains invalid characters, throw an exception.

See also

\Drupal\Component\Utility\Number::intToAlphadecimal

4 calls to Number::alphadecimalToInt()
Comment::preSave in core/modules/comment/src/Entity/Comment.php
Acts on an entity before the presave hook is invoked.
NumberTest::testAlphadecimalToIntReturnsZeroWithNullAndEmptyString in core/tests/Drupal/Tests/Component/Utility/NumberTest.php
Tests the alphadecimal conversion function keeps backward compatibility.
NumberTest::testAlphadecimalToIntThrowsExceptionWithMalformedStrings in core/tests/Drupal/Tests/Component/Utility/NumberTest.php
Tests the alphadecimal conversion function input parameter checking.
NumberTest::testConversions in core/tests/Drupal/Tests/Component/Utility/NumberTest.php
Tests the alphadecimal conversion functions.

File

core/lib/Drupal/Component/Utility/Number.php, line 100

Class

Number
Provides helper methods for manipulating numbers.

Namespace

Drupal\Component\Utility

Code

public static function alphadecimalToInt($string = '00') {
  // For backwards compatibility, we must accept NULL
  // and the empty string, returning 0,
  // like (int) base_convert(substr($string, 1), 36, 10) always did.
  if ('' === $string || NULL === $string) {
    @trigger_error('Passing NULL or an empty string to ' . __METHOD__ . '() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. See https://www.drupal.org/node/3494472', E_USER_DEPRECATED);
    return 0;
  }
  $alpha_decimal_substring = substr($string, 1);
  if (!ctype_alnum($alpha_decimal_substring)) {
    throw new \InvalidArgumentException("Invalid characters passed for attempted conversion: {$string}");
  }
  return (int) base_convert($alpha_decimal_substring, 36, 10);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.