src/AsYouTypeFormatter.php
private function getFormattingTemplate($numberPattern, $numberFormat)
    {
        // Creates a phone number consisting only of the digit 9 that matches the
        // numberPattern by applying the pattern to the longestPhoneNumber string.
        $longestPhoneNumber = '999999999999999';
        $m = new Matcher($numberPattern, $longestPhoneNumber);
        $m->find();
        $aPhoneNumber = $m->group();
        // No formatting template can be created if the number of digits entered entered so far
        // is longer than the maximum the current formatting rule can accommodate.
        if (mb_strlen($aPhoneNumber) < mb_strlen($this->nationalNumber)) {
            return '';
        }
        // Formats the number according to $numberFormat
        $template = preg_replace('/' . $numberPattern . '/' . PhoneNumberUtil::REGEX_FLAGS, $numberFormat, $aPhoneNumber);
        // Replaces each digit with character self::$digitPlattern
        $template = preg_replace('/9/', self::$digitPattern, $template);
        return $template;
    }
private function getFormattingTemplate($numberPattern, $numberFormat)
    {
        // Creates a phone number consisting only of the digit 9 that matches the
        // numberPattern by applying the pattern to the longestPhoneNumber string.
        $longestPhoneNumber = '999999999999999';
        $m = new Matcher($numberPattern, $longestPhoneNumber);
        $m->find();
        $aPhoneNumber = $m->group();
        // No formatting template can be created if the number of digits entered entered so far
        // is longer than the maximum the current formatting rule can accommodate.
        if (mb_strlen($aPhoneNumber) < mb_strlen($this->nationalNumber)) {
            return '';
        }
        // Formats the number according to $numberFormat
        $template = preg_replace('/' . $numberPattern . '/' . PhoneNumberUtil::REGEX_FLAGS, $numberFormat, $aPhoneNumber);
        // Replaces each digit with character self::$digitPlattern
        $template = preg_replace('/9/', self::$digitPattern, $template);
        return $template;
    }
private function getFormattingTemplate ( $ numberPattern , $ numberFormat ) { // Creates a phone number consisting only of the digit 9 that matches the // numberPattern by applying the pattern to the longestPhoneNumber string. $ longestPhoneNumber = '999999999999999' ; $ m = new Matcher ( $ numberPattern , $ longestPhoneNumber ) ; $ m -> find ( ) ; $ aPhoneNumber = $ m -> group ( ) ; // No formatting template can be created if the number of digits entered entered so far // is longer than the maximum the current formatting rule can accommodate. if ( mb_strlen ( $ aPhoneNumber ) < mb_strlen ( $ this -> nationalNumber ) ) { return '' ; } // Formats the number according to $numberFormat $ template = preg_replace ( '/' . $ numberPattern . '/' . PhoneNumberUtil :: REGEX_FLAGS , $ numberFormat , $ aPhoneNumber ) ; // Replaces each digit with character self::$digitPlattern $ template = preg_replace ( '/9/' , self :: $ digitPattern , $ template ) ; return $ template ; }
Gets a formatting template which can be used to efficiently format a partial number where
digits are added one by one.
@param string $numberPattern
@param string $numberFormat
@return string
Gets a formatting template which can be used to efficiently format a partial number where digits are added one by one .