Beispiel #1
0
 /**
  * @return IPub\Phone\Entities\Phone|NULL
  */
 public function getValue()
 {
     if ($this->country === NULL || $this->number === NULL) {
         return NULL;
     }
     try {
         // Try to parse number & country
         $number = IPub\Phone\Entities\Phone::fromNumber($this->number, $this->country);
         return $number === NULL ? NULL : $number;
     } catch (IPub\Phone\Exceptions\NoValidCountryException $ex) {
         return NULL;
     } catch (IPub\Phone\Exceptions\NoValidPhoneException $ex) {
         return NULL;
     }
 }
Beispiel #2
0
 /**
  * @param string $number
  * @param string $country
  *
  * @return array
  *
  * @throws Exceptions\NoValidCountryException
  * @throws Exceptions\NoValidPhoneException
  */
 public function getTimeZones($number, $country = 'AUTO')
 {
     // Create phone entity
     $entity = Entities\Phone::fromNumber($number, $country);
     // Extract carrier name from given phone number
     return $entity->getTimeZones();
 }
 /**
  * @param $entity
  * @param Common\Persistence\ObjectManager $objectManager
  *
  * @throws Phone\Exceptions\NoValidCountryException
  * @throws Phone\Exceptions\NoValidPhoneException
  */
 private function postLoadAndPreFlush($entity, Common\Persistence\ObjectManager $objectManager)
 {
     $cache = $objectManager->getMetadataFactory()->getCacheDriver();
     if (!($fieldsMap = $this->getEntityPhoneFields($entity, $cache))) {
         return;
     }
     foreach ($fieldsMap as $phoneAssoc => $phoneMeta) {
         foreach ($phoneMeta['fields'] as $phoneField) {
             $number = $phoneMeta['class']->getFieldValue($entity, $phoneField);
             if ($number instanceof Phone\Entities\Phone || $number === NULL) {
                 continue;
             }
             $phoneMeta['class']->setFieldValue($entity, $phoneField, Phone\Entities\Phone::fromNumber($number));
         }
     }
 }