Exemple #1
0
 /**
  * Find a mixer based upon the requested strength
  *
  * @param Strength $strength The strength mixer to find
  *
  * @return Mixer The found mixer
  * @throws RuntimeException if a valid mixer cannot be found
  */
 protected function findMixer(\PasswordLib\Core\Strength $strength)
 {
     $newMixer = null;
     $fallback = null;
     foreach ($this->getMixers() as $mixer) {
         if ($strength->compare($mixer::getStrength()) == 0) {
             $newMixer = new $mixer();
         } elseif ($strength->compare($mixer::getStrength()) == 1) {
             $fallback = new $mixer();
         }
     }
     if (is_null($newMixer)) {
         if (is_null($fallback)) {
             throw new \RuntimeException('Could not find mixer');
         }
         return $fallback;
     }
     return $newMixer;
 }