Пример #1
0
 /**
  * Deletes the profile with given uniqueness.
  *
  * @param string $uniqueness
  *
  * @throws NonExistentProfileException
  */
 public function delete($uniqueness)
 {
     $result = $this->connectToStorage->connect()->deleteOne(['_id' => $uniqueness]);
     if ($result->getDeletedCount() === 0) {
         throw new NonExistentProfileException();
     }
 }
Пример #2
0
 /**
  * Updates the profile with given uniqueness.
  *
  * @param string   $uniqueness
  * @param string[] $roles
  *
  * @throws NonExistentUniquenessException
  */
 public function update($uniqueness, $roles)
 {
     $result = $this->connectToStorage->connect()->updateOne(['_id' => $uniqueness], ['$set' => ['roles' => $roles]]);
     if ($result->getMatchedCount() == 0) {
         throw new NonExistentUniquenessException();
     }
 }
Пример #3
0
 /**
  * Picks the profile with given criteria.
  *
  * @param string|null $uniqueness
  *
  * @throws NonExistentProfileException
  *
  * @return Profile
  */
 public function pick($uniqueness)
 {
     $profile = $this->connectToStorage->connect()->findOne(['_id' => $uniqueness]);
     if (is_null($profile)) {
         throw new NonExistentProfileException();
     }
     return $profile;
 }
 /**
  * Collects profiles.
  *
  * @param string[] $roles
  *
  * @return Profiles
  */
 public function collect($roles)
 {
     $criteria = [];
     if (!is_null($roles)) {
         $criteria['roles'] = ['$in' => $roles];
     }
     $profiles = new Profiles($this->connectToStorage->connect()->find($criteria));
     return $profiles;
 }
Пример #5
0
 /**
  * Creates a profile.
  *
  * @param string   $uniqueness
  * @param string[] $roles
  *
  * @return string
  */
 public function create($uniqueness, $roles)
 {
     $uniqueness = $uniqueness ?: uniqid();
     $this->connectToStorage->connect()->insertOne(new Profile($uniqueness, $roles));
     return $uniqueness;
 }