/** * 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); } }
/** * Picks the profile with given uniqueness. * * @param string $uniqueness * * @return array * * @throws NonExistentUniquenessApiException */ public function pick($uniqueness) { $profile = $this->connectToStorageInternalWorker->connect()->findOne(['uniqueness' => $uniqueness]); if (!$profile) { throw new NonExistentUniquenessApiException(); } return ['uniqueness' => $profile['uniqueness'], 'email' => $profile['email']]; }
/** * Picks the profile with given email. * * @param string $email * * @return array An array with the following keys: * uniqueness, email * * @throws NonExistentEmailApiException */ public function pick($email) { $profile = $this->connectToStorageInternalWorker->connect()->findOne(['email' => $email], ['_id' => 0]); if (!$profile) { throw new NonExistentEmailApiException(); } return $profile; }
/** * Creates a profile. * * @param string $uniqueness * @param string $email * * @throws InvalidEmailSharedException * @throws ExistentEmailSharedException * @throws ExistentUniquenessSharedException * @throws \MongoCursorException */ public function create($uniqueness, $email) { if (!Validator::email()->validate($email)) { throw new InvalidEmailSharedException(); } try { $this->connectToStorageInternalWorker->connect()->insert(['uniqueness' => $uniqueness, 'email' => $email]); } catch (\MongoCursorException $e) { if (11000 == $e->getCode()) { if (strpos($e->getMessage(), '$email_1') !== false) { throw new ExistentEmailSharedException(); } throw new ExistentUniquenessSharedException(); } throw $e; } }
/** * Collects internet profiles. * * @return \Iterator */ public function collect() { return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]); }