src/Registration.php
protected function dissectPhone()
  {
      if (($handle = fopen(dirname(__FILE__).'/countries.csv', 'rb')) !== false) {
          while (($data = fgetcsv($handle, 1000)) !== false) {
              if (strpos($this->phoneNumber, $data[1]) === 0) {
                  // Return the first appearance.
                  fclose($handle);

                  $mcc = explode('|', $data[2]);
                  $mcc = $mcc[0];

                  //hook:
                  //fix country code for North America
                  if ($data[1][0] == '1') {
                      $data[1] = '1';
                  }

                  $phone = [
                      'country' => $data[0],
                      'cc'      => $data[1],
                      'phone'   => substr($this->phoneNumber, strlen($data[1]), strlen($this->phoneNumber)),
                      'mcc'     => $mcc,
                      'ISO3166' => @$data[3],
                      'ISO639'  => @$data[4],
                      'mnc'     => $data[5],
                  ];

                  $this->eventManager()->fire('onDissectPhone',
                      [
                          $this->phoneNumber,
                          $phone['country'],
                          $phone['cc'],
                          $phone['phone'],
                          $phone['mcc'],
                          $phone['ISO3166'],
                          $phone['ISO639'],
                          $phone['mnc'],
                      ]
                  );

                  return $phone;
              }
          }
          fclose($handle);
      }

      $this->eventManager()->fire('onDissectPhoneFailed',
          [
              $this->phoneNumber,
          ]);

      return false;
  }
protected function dissectPhone()
  {
      if (($handle = fopen(dirname(__FILE__).'/countries.csv', 'rb')) !== false) {
          while (($data = fgetcsv($handle, 1000)) !== false) {
              if (strpos($this->phoneNumber, $data[1]) === 0) {
                  // Return the first appearance.
                  fclose($handle);

                  $mcc = explode('|', $data[2]);
                  $mcc = $mcc[0];

                  //hook:
                  //fix country code for North America
                  if ($data[1][0] == '1') {
                      $data[1] = '1';
                  }

                  $phone = [
                      'country' => $data[0],
                      'cc'      => $data[1],
                      'phone'   => substr($this->phoneNumber, strlen($data[1]), strlen($this->phoneNumber)),
                      'mcc'     => $mcc,
                      'ISO3166' => @$data[3],
                      'ISO639'  => @$data[4],
                      'mnc'     => $data[5],
                  ];

                  $this->eventManager()->fire('onDissectPhone',
                      [
                          $this->phoneNumber,
                          $phone['country'],
                          $phone['cc'],
                          $phone['phone'],
                          $phone['mcc'],
                          $phone['ISO3166'],
                          $phone['ISO639'],
                          $phone['mnc'],
                      ]
                  );

                  return $phone;
              }
          }
          fclose($handle);
      }

      $this->eventManager()->fire('onDissectPhoneFailed',
          [
              $this->phoneNumber,
          ]);

      return false;
  }
protected function dissectPhone ( ) { if ( ( $ handle = fopen ( dirname ( __FILE__ ) . '/countries.csv' , 'rb' ) ) !== false ) { while ( ( $ data = fgetcsv ( $ handle , 1000 ) ) !== false ) { if ( strpos ( $ this -> phoneNumber , $ data [ 1 ] ) === 0 ) { // Return the first appearance. fclose ( $ handle ) ; $ mcc = explode ( '|' , $ data [ 2 ] ) ; $ mcc = $ mcc [ 0 ] ; //hook: //fix country code for North America if ( $ data [ 1 ] [ 0 ] == '1' ) { $ data [ 1 ] = '1' ; } $ phone = [ 'country' => $ data [ 0 ] , 'cc' => $ data [ 1 ] , 'phone' => substr ( $ this -> phoneNumber , strlen ( $ data [ 1 ] ) , strlen ( $ this -> phoneNumber ) ) , 'mcc' => $ mcc , 'ISO3166' => @ $ data [ 3 ] , 'ISO639' => @ $ data [ 4 ] , 'mnc' => $ data [ 5 ] , ] ; $ this -> eventManager ( ) -> fire ( 'onDissectPhone' , [ $ this -> phoneNumber , $ phone [ 'country' ] , $ phone [ 'cc' ] , $ phone [ 'phone' ] , $ phone [ 'mcc' ] , $ phone [ 'ISO3166' ] , $ phone [ 'ISO639' ] , $ phone [ 'mnc' ] , ] ) ; return $ phone ; } } fclose ( $ handle ) ; } $ this -> eventManager ( ) -> fire ( 'onDissectPhoneFailed' , [ $ this -> phoneNumber , ] ) ; return false ; }
Dissect country code from phone number.

@return array
An associative array with country code and phone number.
- country: The detected country name.
- cc: The detected country code (phone prefix).
- phone: The phone number.
- ISO3166: 2-Letter country code
- ISO639: 2-Letter language code
Return false if country code is not found.
Dissect country code from phone number .