You are here

interface MobileNumberUtilInterface in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/MobileNumberUtilInterface.php \Drupal\mobile_number\MobileNumberUtilInterface

Provides an interface for mobile number utility.

Hierarchy

Expanded class hierarchy of MobileNumberUtilInterface

All classes that implement MobileNumberUtilInterface

8 files declare their use of MobileNumberUtilInterface
MobileNumber.php in src/Element/MobileNumber.php
MobileNumber.php in src/Plugin/WebformElement/MobileNumber.php
MobileNumberClassTest.php in src/Tests/MobileNumberClassTest.php
MobileNumberFieldTest.php in src/Tests/MobileNumberFieldTest.php
MobileNumberItem.php in src/Plugin/Field/FieldType/MobileNumberItem.php

... See full list

File

src/MobileNumberUtilInterface.php, line 10

Namespace

Drupal\mobile_number
View source
interface MobileNumberUtilInterface {
  const MOBILE_NUMBER_UNIQUE_NO = 0;
  const MOBILE_NUMBER_UNIQUE_YES = 1;
  const MOBILE_NUMBER_UNIQUE_YES_VERIFIED = 2;
  const MOBILE_NUMBER_VERIFY_NONE = 'none';
  const MOBILE_NUMBER_VERIFY_OPTIONAL = 'optional';
  const MOBILE_NUMBER_VERIFY_REQUIRED = 'required';
  const MOBILE_NUMBER_DEFAULT_SMS_MESSAGE = "Your verification code from !site_name:\n!code";
  const VERIFY_ATTEMPTS_INTERVAL = 3600;
  const VERIFY_ATTEMPTS_COUNT = 5;
  const SMS_ATTEMPTS_INTERVAL = 60;
  const SMS_ATTEMPTS_COUNT = 1;

  /**
   * Specifies the mobile number was verified.
   */
  const MOBILE_NUMBER_VERIFIED = 1;

  /**
   * Specifies the mobile number was not verified.
   */
  const MOBILE_NUMBER_NOT_VERIFIED = 0;

  /**
   * Specifies the tfa was enabled.
   */
  const MOBILE_NUMBER_TFA_ENABLED = 1;

  /**
   * Specifies the tfa was disabled.
   */
  const MOBILE_NUMBER_TFA_DISABLED = 0;

  /**
   * Get libphonenumber Util instance.
   *
   * @return \libphonenumber\PhoneNumberUtil
   *   Libphonenumber utility instance.
   */
  public function libUtil();

  /**
   * Get mobile number object.
   *
   * @param string $number
   *   Number.
   * @param null|string $country
   *   Country.
   * @param array $types
   *   Mobile number types to verify as defined in
   *   \libphonenumber\PhoneNumberType.
   *
   * @return \libphonenumber\PhoneNumber|null
   *   Phone Number object if successful.
   */
  public function getMobileNumber($number, $country = NULL, $types = [
    1 => 1,
    2 => 2,
  ]);

  /**
   * Test mobile number validity.
   *
   * @param string $number
   *   Number.
   * @param null|string $country
   *   Country.
   * @param array $types
   *   Mobile number types to verify as defined in
   *   \libphonenumber\PhoneNumberType.
   *
   * @throws \Drupal\mobile_number\Exception\MobileNumberException
   *   Thrown if mobile number is not valid.
   *
   * @return \libphonenumber\PhoneNumber
   *   Libphonenumber Phone number object.
   */
  public function testMobileNumber($number, $country = NULL, $types = [
    1 => 1,
    2 => 2,
  ]);

  /**
   * Get international number.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   *
   * @return string
   *   E.164 formatted number.
   */
  public function getCallableNumber(PhoneNumber $mobile_number);

  /**
   * Get country code.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   *
   * @return string
   *   Country code.
   */
  public function getCountry(PhoneNumber $mobile_number);

  /**
   * Get country display name given country code.
   *
   * @param string $country
   *   Country code.
   *
   * @return string
   *   Country name.
   */
  public function getCountryName($country);

  /**
   * Get national number.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   *
   * @return string
   *   National number.
   */
  public function getLocalNumber(PhoneNumber $mobile_number);

  /**
   * Gets the country phone number prefix given a country code.
   *
   * @param string $country
   *   Country code (Eg. IL).
   *
   * @return int
   *   Country phone number prefix (Eg. 972).
   */
  public function getCountryCode($country);

  /**
   * Checks whether there were too many verifications attempted with the current number.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   * @param string $type
   *   Flood type, 'sms' or 'verification'.
   *
   * @return bool
   *   FALSE for too many attempts on this mobile number, TRUE otherwise.
   */
  public function checkFlood(PhoneNumber $mobile_number, $type = 'verification');

  /**
   * Gets token generated if verification code was sent.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   *
   * @return string|null
   *   A drupal token (43 characters).
   */
  public function getToken(PhoneNumber $mobile_number);

  /**
   * Generates a random numeric string.
   *
   * @param int $length
   *   Number of digits.
   *
   * @return string
   *   Code in length of $length.
   */
  public function generateVerificationCode($length = 4);

  /**
   * Get all supported countries.
   *
   * @param array $filter
   *   Limit options to the ones in the filter. (Eg. ['IL' => 'IL', 'US' => 'US'].
   * @param bool $show_country_names
   *   Whether to show full country name instead of country codes.
   *
   * @return array
   *   Array of options, with country code as keys. (Eg. ['IL' => 'IL (+972)'])
   */
  public function getCountryOptions($filter = [], $show_country_names = FALSE);

  /**
   * Verifies input code matches code sent to user.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   * @param string $code
   *   Input code.
   * @param string|null $token
   *   Verification token, if verification code was not sent in this session.
   *
   * @return bool
   *   TRUE if matches
   */
  public function verifyCode(PhoneNumber $mobile_number, $code, $token = NULL);

  /**
   * Send verification code to mobile number.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   * @param string $message
   *   Drupal translatable string.
   * @param string $code
   *   Code to send.
   * @param array $token_data
   *   Token variables to be used with token_replace().
   *
   * @return bool
   *   Success flag.
   */
  public function sendVerification(PhoneNumber $mobile_number, $message, $code, $token_data = []);

  /**
   * Is the number already verified.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   *
   * @return bool
   *   TRUE if verified.
   */
  public function isVerified(PhoneNumber $mobile_number);

  /**
   * Registers code for mobile number and returns it's token.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   * @param string $code
   *   Access code.
   *
   * @return string
   *   43 character token.
   */
  public function registerVerificationCode(PhoneNumber $mobile_number, $code);

  /**
   * Generate hash given token and code.
   *
   * @param \libphonenumber\PhoneNumber $mobile_number
   *   Phone number object.
   * @param string $token
   *   Token.
   * @param string $code
   *   Verification code.
   *
   * @return string
   *   Hash string.
   */
  public function codeHash(PhoneNumber $mobile_number, $token, $code);

  /**
   * Gets sms callback for sending SMS's. The callback should accept $number and $message, and returns status booleans.
   *
   * @return callable
   *   SMS callback.
   */
  public function smsCallback();

  /**
   * Checks if sms sending is enabled.
   *
   * @return bool
   *   True or false.
   */
  public function isSmsEnabled();

  /**
   * Sends an sms, based on callback provided by smsCallback().
   *
   * @param string $number
   *   A callable number in international format.
   * @param string $message
   *   String message, after translation.
   *
   * @return bool
   *   SMS callback result, TRUE = success, FALSE otherwise.
   */
  public function sendSms($number, $message);

  /**
   * Gets account mobile number if tfa was enabled for the user.
   *
   * @param int $uid
   *   User id.
   *
   * @return string
   *   International number
   */
  public function tfaAccountNumber($uid);

  /**
   * Gets the tfa field configuration.
   *
   * @return string
   *   Currently configured user field for tfa. '' if not set or tfa is not enabled.
   */
  public function getTfaField();

  /**
   * Sets the tfa field configuration.
   *
   * @param string $field_name
   *   User field name.
   */
  public function setTfaField($field_name);

  /**
   * Checks if tfa is enabled.
   *
   * @return bool
   *   True or false.
   */
  public function isTfaEnabled();

}

Members

Namesort descending Modifiers Type Description Overrides
MobileNumberUtilInterface::checkFlood public function Checks whether there were too many verifications attempted with the current number. 1
MobileNumberUtilInterface::codeHash public function Generate hash given token and code. 1
MobileNumberUtilInterface::generateVerificationCode public function Generates a random numeric string. 1
MobileNumberUtilInterface::getCallableNumber public function Get international number. 1
MobileNumberUtilInterface::getCountry public function Get country code. 1
MobileNumberUtilInterface::getCountryCode public function Gets the country phone number prefix given a country code. 1
MobileNumberUtilInterface::getCountryName public function Get country display name given country code. 1
MobileNumberUtilInterface::getCountryOptions public function Get all supported countries. 1
MobileNumberUtilInterface::getLocalNumber public function Get national number. 1
MobileNumberUtilInterface::getMobileNumber public function Get mobile number object. 1
MobileNumberUtilInterface::getTfaField public function Gets the tfa field configuration. 1
MobileNumberUtilInterface::getToken public function Gets token generated if verification code was sent. 1
MobileNumberUtilInterface::isSmsEnabled public function Checks if sms sending is enabled. 1
MobileNumberUtilInterface::isTfaEnabled public function Checks if tfa is enabled. 1
MobileNumberUtilInterface::isVerified public function Is the number already verified. 1
MobileNumberUtilInterface::libUtil public function Get libphonenumber Util instance. 1
MobileNumberUtilInterface::MOBILE_NUMBER_DEFAULT_SMS_MESSAGE constant
MobileNumberUtilInterface::MOBILE_NUMBER_NOT_VERIFIED constant Specifies the mobile number was not verified.
MobileNumberUtilInterface::MOBILE_NUMBER_TFA_DISABLED constant Specifies the tfa was disabled.
MobileNumberUtilInterface::MOBILE_NUMBER_TFA_ENABLED constant Specifies the tfa was enabled.
MobileNumberUtilInterface::MOBILE_NUMBER_UNIQUE_NO constant
MobileNumberUtilInterface::MOBILE_NUMBER_UNIQUE_YES constant
MobileNumberUtilInterface::MOBILE_NUMBER_UNIQUE_YES_VERIFIED constant
MobileNumberUtilInterface::MOBILE_NUMBER_VERIFIED constant Specifies the mobile number was verified.
MobileNumberUtilInterface::MOBILE_NUMBER_VERIFY_NONE constant
MobileNumberUtilInterface::MOBILE_NUMBER_VERIFY_OPTIONAL constant
MobileNumberUtilInterface::MOBILE_NUMBER_VERIFY_REQUIRED constant
MobileNumberUtilInterface::registerVerificationCode public function Registers code for mobile number and returns it's token. 1
MobileNumberUtilInterface::sendSms public function Sends an sms, based on callback provided by smsCallback(). 1
MobileNumberUtilInterface::sendVerification public function Send verification code to mobile number. 1
MobileNumberUtilInterface::setTfaField public function Sets the tfa field configuration. 1
MobileNumberUtilInterface::smsCallback public function Gets sms callback for sending SMS's. The callback should accept $number and $message, and returns status booleans. 1
MobileNumberUtilInterface::SMS_ATTEMPTS_COUNT constant
MobileNumberUtilInterface::SMS_ATTEMPTS_INTERVAL constant
MobileNumberUtilInterface::testMobileNumber public function Test mobile number validity. 1
MobileNumberUtilInterface::tfaAccountNumber public function Gets account mobile number if tfa was enabled for the user. 1
MobileNumberUtilInterface::verifyCode public function Verifies input code matches code sent to user. 1
MobileNumberUtilInterface::VERIFY_ATTEMPTS_COUNT constant
MobileNumberUtilInterface::VERIFY_ATTEMPTS_INTERVAL constant