/**
  * Deletes the profile with given uniqueness.
  *
  * @param string $uniqueness
  *
  * @throws NonExistentUniquenessSharedException
  */
 public function delete($uniqueness)
 {
     $result = $this->connectToStorageInternalWorker->connect()->remove(['uniqueness' => $uniqueness]);
     if ($result['n'] == 0) {
         throw new NonExistentUniquenessSharedException($uniqueness);
     }
 }
Example #2
0
 /**
  * Picks the profile with given uniqueness.
  *
  * @param string $uniqueness
  *
  * @return array
  *
  * @throws NonExistentUniquenessApiException
  */
 public function pick($uniqueness)
 {
     $profile = $this->connectToStorageInternalWorker->connect()->findOne(['uniqueness' => $uniqueness], ['_id' => 0]);
     if (!$profile) {
         throw new NonExistentUniquenessApiException();
     }
     return $profile;
 }
 /**
  * Picks the profile with given number.
  *
  * @param string $number
  *
  * @return array
  *
  * @throws NonExistentNumberApiException
  */
 public function pick($number)
 {
     $number = PhoneNumberFixer::fix($number);
     $profile = $this->connectToStorageInternalWorker->connect()->findOne(['number' => $number], ['_id' => 0]);
     if (!$profile) {
         throw new NonExistentNumberApiException();
     }
     return $profile;
 }
 /**
  * Creates a profile.
  *
  * @param string $uniqueness
  * @param string $number
  *
  * @throws InvalidNumberSharedException
  * @throws ExistentNumberSharedException
  * @throws ExistentUniquenessSharedException
  * @throws \MongoCursorException
  */
 public function create($uniqueness, $number)
 {
     try {
         $number = PhoneNumberFixer::fix($number);
     } catch (\InvalidArgumentException $e) {
         throw new InvalidNumberSharedException();
     }
     try {
         $this->connectToStorageInternalWorker->connect()->insert(['uniqueness' => $uniqueness, 'number' => $number]);
     } catch (\MongoCursorException $e) {
         if (11000 == $e->getCode()) {
             if (strpos($e->getMessage(), '$number_1') !== false) {
                 throw new ExistentNumberSharedException();
             }
             throw new ExistentUniquenessSharedException();
         }
         throw $e;
     }
 }
 /**
  * Collects mobile profiles.
  *
  * @return \Iterator
  */
 public function collect()
 {
     return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]);
 }