Function phone_number_old_and_new - Get Phone Number Old and New

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 9/28/18 13:39

@param string $my_number
@param null   $my_format

@return array|mixed|null|string
@throws \Exception
171657
public function phone_number_old_and_new($my_number = '', $my_format = NULL)
    {
        if (empty($my_number)) {
            return NULL;
        }
        try {
            $old_number = $this->phone_number_convert($my_number, 'old', $my_format);
            $new_number = $this->phone_number_convert($my_number, 'new', $my_format);
            if ($old_number != $new_number) {
                // Nếu sau khi so sánh convert số cũ và số mới khác nhau -> trả về 1 array
                $result = [
                    $old_number,
                    $new_number
                ];
                $this->_debug->info(__FUNCTION__, 'Result: ' . $result);

                return $result;
            } else {
                // Nếu không khác, trả về string
                $result = $this->format($my_number, $my_format);
                $this->_debug->info(__FUNCTION__, 'Result: ' . $result);

                return $result;
            }
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->_debug->error(__FUNCTION__, $message);

            return $my_number;
        }
    }
1043984
public function phoneFormatByCountry($phone, $country = 'BR', $format = 'n')
    {
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $phoneParse = $phoneUtil->parse($phone, $country);
        } catch (\libphonenumber\NumberParseException $e) {
            return null;
        }

        if ($format == 'n') {
            $method = PhoneNumberFormat::NATIONAL;
        } elseif ($format == 'i') {
            $method = PhoneNumberFormat::INTERNATIONAL;
        } else {
            $method = PhoneNumberFormat::E164;
        }

        return $phoneUtil->format($phoneParse, $method);
    }
985070
public static function dateNow($default_format = null)
    {
        $now = new \DateTime();

        if (is_null($default_format)) {
            $default_format = Grav::instance()['config']->get('system.pages.dateformat.default');
        }

        return $now->format($default_format);
    }
265128
public function format(PhoneNumber $phoneNumber, $format = PhoneNumberFormat::INTERNATIONAL)
    {
        if (true === is_string($format)) {
            $constant = '\libphonenumber\PhoneNumberFormat::' . $format;

            if (false === defined($constant)) {
                throw new InvalidArgumentException('The format must be either a constant value or name in libphonenumber\PhoneNumberFormat');
            }

            $format = constant('\libphonenumber\PhoneNumberFormat::' . $format);
        }

        return $this->phoneNumberUtil->format($phoneNumber, $format);
    }
1230172
private function process_data($last_call)
    {
        $response = null;
        $error = null;
        $view = false;

        if (empty($_POST['phery'])) {
            return self::exception($this, 'Non-Phery AJAX request', self::ERROR_PROCESS);
        }

        if (!empty($_GET['_'])) {
            $this->data['requested'] = (int)$_GET['_'];
            unset($_GET['_']);
        }

        if (isset($_GET['_try_count'])) {
            $this->data['retries'] = (int)$_GET['_try_count'];
            unset($_GET['_try_count']);
        }

        $args = array();
        $remote = false;

        if (!empty($_POST['phery']['remote'])) {
            $remote = $_POST['phery']['remote'];
        }

        if (!empty($_POST['phery']['submit_id'])) {
            $this->data['submit_id'] = "#{$_POST['phery']['submit_id']}";
        }

        if ($remote !== false) {
            $this->data['remote'] = $remote;
        }

        if (!empty($_POST['args'])) {
            $args = get_magic_quotes_gpc() ? $this->stripslashes_recursive($_POST['args']) : $_POST['args'];

            if ($last_call === true) {
                unset($_POST['args']);
            }
        }

        foreach ($_POST['phery'] as $name => $post) {
            if (!isset($this->data[$name])) {
                $this->data[$name] = $post;
            }
        }

        if (count($this->callbacks['before'])) {
            foreach ($this->callbacks['before'] as $func) {
                if (($args = call_user_func($func, $args, $this->data, $this)) === false) {
                    return false;
                }
            }
        }

        if (!empty($_POST['phery']['view'])) {
            $this->data['view'] = $_POST['phery']['view'];
        }

        if ($remote !== false) {
            if (isset($this->functions[$remote])) {
                if (isset($_POST['phery']['remote'])) {
                    unset($_POST['phery']['remote']);
                }

                $this->before_user_func();

                $response = call_user_func($this->functions[$remote], $args, $this->data, $this);

                foreach ($this->callbacks['after'] as $func) {
                    if (call_user_func($func, $args, $this->data, $response, $this) === false) {
                        return false;
                    }
                }

                if (($response = self::respond($response, false)) === null) {
                    $error = 'Response was void for function "' . htmlentities($remote, ENT_COMPAT, null, false) . '"';
                }

                $_POST['phery']['remote'] = $remote;
            } else {
                if ($last_call) {
                    self::exception($this, 'The function provided "' . htmlentities($remote, ENT_COMPAT, null, false) . '" isn\'t set', self::ERROR_PROCESS);
                }
            }
        } else {
            if (!empty($this->data['view']) && isset($this->views[$this->data['view']])) {
                $view = $this->data['view'];

                $this->before_user_func();

                $response = call_user_func($this->views[$this->data['view']], $args, $this->data, $this);

                foreach ($this->callbacks['after'] as $func) {
                    if (call_user_func($func, $args, $this->data, $response, $this) === false) {
                        return false;
                    }
                }

                if (($response = self::respond($response, false)) === null) {
                    $error = 'Response was void for view "' . htmlentities($this->data['view'], ENT_COMPAT, null, false) . '"';
                }
            } else {
                if ($last_call) {
                    if (!empty($this->data['view'])) {
                        self::exception($this, 'The provided view "' . htmlentities($this->data['view'], ENT_COMPAT, null, false) . '" isn\'t set', self::ERROR_PROCESS);
                    } else {
                        self::exception($this, 'Empty request', self::ERROR_PROCESS);
                    }
                }
            }
        }

        if ($error !== null) {
            self::error_handler(E_NOTICE, $error, '', 0);
        } elseif ($response === null && $last_call & !$view) {
            $response = PheryResponse::factory();
        } elseif ($response !== null) {
            ob_start();

            if (!$this->config['return']) {
                echo $response;
            }
        }

        if (!$this->config['return'] && $this->config['exit_allowed'] === true) {
            if ($last_call || $response !== null) {
                exit;
            }
        } elseif ($this->config['return']) {
            self::flush(true);
        }

        if ($this->config['error_reporting'] !== false) {
            restore_error_handler();
        }

        return $response;
    }
419231
public function getPhoneNumbers()
    {
        Piwik::checkUserIsNotAnonymous();

        $rawPhoneNumbers = $this->retrievePhoneNumbers();

        $phoneNumbers = array();
        foreach ($rawPhoneNumbers as $phoneNumber => $verificationCode) {
            $phoneNumbers[$phoneNumber] = self::isActivated($verificationCode);
        }

        return $phoneNumbers;
    }
1303573
public static function format_phone($string = '', $format = null)
	{
		is_null($format) and $format = static::$config['formatting']['phone'];
		return static::format($string, $format);
	}
841876
static function parseMobileNumber($number) {
    // Extract numerics
    $numerics = static::extractNumerics($number);
    // Set country code
    $countryCode = '';
    // Get last 10 digits
    $short = static::right($numerics, 10, $countryCode);
    // Set carrier code
    $carriercode = '';
    // Get number
    $number = static::right($short, 7, $carrierCode);
    // Return
    return compact('countryCode', 'carrierCode', 'number');
  }
925974
private static function determineNumberFormatType($num_format)
    {
        $num_format = preg_replace("/\[(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow)\]/i", "", $num_format);
        if ($num_format == 'GENERAL') {
            return 'n_auto';
        }
        if ($num_format == '@') {
            return 'n_string';
        }
        if ($num_format == '0') {
            return 'n_numeric';
        }
        if (preg_match("/[H]{1,2}:[M]{1,2}/i", $num_format)) {
            return 'n_datetime';
        }
        if (preg_match("/[M]{1,2}:[S]{1,2}/i", $num_format)) {
            return 'n_datetime';
        }
        if (preg_match("/[Y]{2,4}/i", $num_format)) {
            return 'n_date';
        }
        if (preg_match("/[D]{1,2}/i", $num_format)) {
            return 'n_date';
        }
        if (preg_match("/[M]{1,2}/i", $num_format)) {
            return 'n_date';
        }
        if (preg_match("/$/", $num_format)) {
            return 'n_numeric';
        }
        if (preg_match("/%/", $num_format)) {
            return 'n_numeric';
        }
        if (preg_match("/0/", $num_format)) {
            return 'n_numeric';
        }
        return 'n_auto';
    }
1350882
private function phoneValidate($phone)
    {
        $result = null;
        $phone  = trim($phone);
        if (!empty($phone)) {
            if (!$this->phoneHelper) {
                $this->phoneHelper = new PhoneNumberHelper();
            }
            try {
                $phone = $this->phoneHelper->format($phone);
                if (!empty($phone)) {
                    $result = $phone;
                }
            } catch (\Exception $e) {
            }
        }

        return $result;
    }
966216
public function callbackChangeSortIndex($new, $old)
    {
        // get old position
        $newPos = (new Query)->select([$this->sortIndexFieldName])->from($this->refTableName)->where([$this->imageIdFieldName => $new['originalImageId']])->scalar();
        $oldPos = (new Query)->select([$this->sortIndexFieldName])->from($this->refTableName)->where([$this->imageIdFieldName => $old['originalImageId']])->scalar();
        
        // switch positions
        $changeNewPos = Yii::$app->db->createCommand()->update($this->refTableName, [$this->sortIndexFieldName => $oldPos], [
            $this->imageIdFieldName => $new['originalImageId'],
            $this->refFieldName => $this->itemId,
        ])->execute();
        
        $changeOldPos = Yii::$app->db->createCommand()->update($this->refTableName, [$this->sortIndexFieldName => $newPos], [
            $this->imageIdFieldName => $old['originalImageId'],
            $this->refFieldName => $this->itemId,
        ])->execute();
        
        return true;
    }
813500
public function getPhone(): string
    {
        $string = '';
        if ($this->userMeta->notification_phone !== null) {
            $phone = new UserMetaPhone($this->userMeta->notification_phone);
            $string = $phone->country . $phone->number;
        }
        return $string;
    }
233415
@GET
  @Path(PhoneNumber.PARSE_AND_FORMAT)
  public PhoneNumberDataWithFormats parseAndFormatPhoneNumber(
      @QueryParam(Parameters.LANGUAGE) final String planguage,
      @QueryParam(Parameters.COUNTRY) final String pcountry,
      @QueryParam(Parameters.PHONE_NUMBER) final String pphoneNumber) {
    final PhoneNumberDataWithFormats result = new PhoneNumberDataWithFormats(phoneNumberUtil
        .parsePhoneNumber(pphoneNumber, pcountry, LocaleUtil.convertLanguageToLocale(planguage)));
    result.setCommonInternational(phoneNumberUtil.formatCommonInternational(result));
    result.setCommonNational(phoneNumberUtil.formatCommonNational(result));
    result.setDin5008International(phoneNumberUtil.formatDin5008International(result));
    result.setDin5008National(phoneNumberUtil.formatDin5008National(result));
    result.setE123International(phoneNumberUtil.formatE123International(result));
    result.setE123National(phoneNumberUtil.formatE123National(result));
    result.setMs(phoneNumberUtil.formatMs(result));
    result.setUrl(phoneNumberUtil.formatUrl(result));
    return result;
  }
457486
public function set_num_format($num_format) {
        $numbers = array();

        $numbers[1] = '0';
        $numbers[2] = '0.00';
        $numbers[3] = '#,##0';
        $numbers[4] = '#,##0.00';
        $numbers[11] = '0.00E+00';
        $numbers[12] = '# ?/?';
        $numbers[13] = '# ??/??';
        $numbers[14] = 'mm-dd-yy';
        $numbers[15] = 'd-mmm-yy';
        $numbers[16] = 'd-mmm';
        $numbers[17] = 'mmm-yy';
        $numbers[22] = 'm/d/yy h:mm';
        $numbers[49] = '@';

        if ($num_format !== 0 and in_array($num_format, $numbers)) {
            $this->format['numberformat']['code'] = $num_format;
        }

        if (!isset($numbers[$num_format])) {
            return;
        }

        $this->format['numberformat']['code'] = $numbers[$num_format];
    }
1169868
public function getExpiryDate($format = null)
    {
        $node = $this->getFirst('//epp:epp/epp:response/epp:resData/domain:trnData/domain:exDate');
        if ($node === null) {
            return null;
        }

        if ($format === null) {
            return $node->nodeValue;
        }

        return date_create_from_format($format, $node->nodeValue);
    }
1241545
public function get_mform_set_data() {
        if (!empty($this->rule)) {
            $rule = fullclone($this->rule);
            $rule->description = array('text' => $rule->description, 'format' => $rule->descriptionformat);
            $rule->template = array('text' => $rule->template, 'format' => $rule->templateformat);
            return $rule;
        }
        throw new \coding_exception('Invalid call to get_mform_set_data.');
    }
516750
public function now($format = null)
    {
        $date = $this->currentDate
            ? clone $this->currentDate
            : ($this->currentDate = new \DateTime())
        ;

        return empty($format) ?
            $date :
            $date->format($format)
        ;
    }