src/Ten24/Component/Formatter/PhoneNumberFormatter.php
public function getComponent($component = null)
    {
        if (null === $this->components)
        {
            $pattern = '/
                (?<countryCode>(\+?\d{1,2})?\D*)         # optional country code
                (?<areaCode>(\d{3})?\D*)                 # optional area code
                (?<prefix>(\d{3})\D*)                    # first three (prefix)
                (?<lineNumber>(\d{4}))                   # last four (line number)
                (?<extensionDelimiter>(?:\D+|$))         # extension delimiter or EOL
                (?<extension>(\d*))                      # optional extension
                /x';

            if (preg_match($pattern, $this->phoneNumber, $matches))
            {
                // Matches will be
                // Array
                //(
                // [0] => +11235551234x999
                // [1] => +1
                // [2] => 123
                // [3] => 555
                // [4] => 1234
                // [5] => x
                // [6] => 999
                //)
                $this->components = $matches;
            }
        }

        switch ($component)
        {
            case self::COUNTRY_CODE:
                return !empty($this->components['countryCode']) ? $this->components['countryCode'] : '+1';
                break;
            case self::AREA_CODE:
                return $this->components['areaCode'];
                break;
            case self::PREFIX:
                return $this->components['prefix'];
                break;
            case self::LINE_NUMBER:
                return $this->components['lineNumber'];
                break;
            case self::EXTENSION_DELIMITER:
                return $this->components['extensionDelimiter'];
                break;
            case self::EXTENSION:
                return $this->components['extension'];
                break;
            default:
                return null;
        }
    }
public function getComponent($component = null)
    {
        if (null === $this->components)
        {
            $pattern = '/
                (?<countryCode>(\+?\d{1,2})?\D*)         # optional country code
                (?<areaCode>(\d{3})?\D*)                 # optional area code
                (?<prefix>(\d{3})\D*)                    # first three (prefix)
                (?<lineNumber>(\d{4}))                   # last four (line number)
                (?<extensionDelimiter>(?:\D+|$))         # extension delimiter or EOL
                (?<extension>(\d*))                      # optional extension
                /x';

            if (preg_match($pattern, $this->phoneNumber, $matches))
            {
                // Matches will be
                // Array
                //(
                // [0] => +11235551234x999
                // [1] => +1
                // [2] => 123
                // [3] => 555
                // [4] => 1234
                // [5] => x
                // [6] => 999
                //)
                $this->components = $matches;
            }
        }

        switch ($component)
        {
            case self::COUNTRY_CODE:
                return !empty($this->components['countryCode']) ? $this->components['countryCode'] : '+1';
                break;
            case self::AREA_CODE:
                return $this->components['areaCode'];
                break;
            case self::PREFIX:
                return $this->components['prefix'];
                break;
            case self::LINE_NUMBER:
                return $this->components['lineNumber'];
                break;
            case self::EXTENSION_DELIMITER:
                return $this->components['extensionDelimiter'];
                break;
            case self::EXTENSION:
                return $this->components['extension'];
                break;
            default:
                return null;
        }
    }
public function getComponent ( $ component = null ) { if ( null === $ this -> components ) { $ pattern = '/
                (?<countryCode>(\+?\d{1,2})?\D*)         # optional country code
                (?<areaCode>(\d{3})?\D*)                 # optional area code
                (?<prefix>(\d{3})\D*)                    # first three (prefix)
                (?<lineNumber>(\d{4}))                   # last four (line number)
                (?<extensionDelimiter>(?:\D+|$))         # extension delimiter or EOL
                (?<extension>(\d*))                      # optional extension
                /x' ; if ( preg_match ( $ pattern , $ this -> phoneNumber , $ matches ) ) { // Matches will be // Array //( // [0] => +11235551234x999 // [1] => +1 // [2] => 123 // [3] => 555 // [4] => 1234 // [5] => x // [6] => 999 //) $ this -> components = $ matches ; } } switch ( $ component ) { case self :: COUNTRY_CODE : return ! empty ( $ this -> components [ 'countryCode' ] ) ? $ this -> components [ 'countryCode' ] : '+1' ; break ; case self :: AREA_CODE : return $ this -> components [ 'areaCode' ] ; break ; case self :: PREFIX : return $ this -> components [ 'prefix' ] ; break ; case self :: LINE_NUMBER : return $ this -> components [ 'lineNumber' ] ; break ; case self :: EXTENSION_DELIMITER : return $ this -> components [ 'extensionDelimiter' ] ; break ; case self :: EXTENSION : return $ this -> components [ 'extension' ] ; break ; default : return null ; } }
Get phone number component

@param null $component
@return null
Get phone number component