Пример #1
0
 protected function getDataToImport(UserSettings $userSettings)
 {
     $xmlrpc = new XmlRpc($userSettings->getUsername(), $userSettings->getPassword());
     $result = [];
     try {
         $listEntry = $xmlrpc->phonebookListGet();
         $entryIds = array_map(function (PhonebookListEntry $entry) {
             return $entry->getEntryId();
         }, $listEntry);
         $entries = $xmlrpc->phonebookEntryGet($entryIds);
     } catch (XmlRpcException $e) {
         $this->logError('An XMLRPC exception occurred: %s', $e->getMessage());
         return $result;
     } catch (HttpException $e) {
         $this->logError('Remote backend failed with HTTP status code %d', $e->getCode());
         return $result;
     }
     foreach ($entries as $entry) {
         /** @var PhonebookEntry $entry */
         try {
             $numbers = $entry->getPhoneNumbers($userSettings->getDefaultCountryCode());
             foreach ($numbers as $number) {
                 $result[] = new Item($entry->getEntryId(), $entry->getFullName(), $number);
             }
         } catch (NumberParseException $e) {
             $this->logError('Error parsing phone number for entry #%s (code %d): %s', $entry->getEntryId(), $e->getCode(), $e->getMessage());
         } catch (ParseException $e) {
             $this->logError('Error parsing VCard for entry #%s: %s', $entry->getEntryId(), $e->getMessage());
         }
     }
     return $result;
 }