Webmozart\Assert\Assert::lessThanEq PHP Метод

lessThanEq() публичный статический Метод

public static lessThanEq ( $value, $limit, $message = '' )
    public static function lessThanEq($value, $limit, $message = '')
    {
        if ($value > $limit) {
            static::reportInvalidArgument(sprintf($message ?: 'Expected a value less than or equal to %2$s. Got: %s', static::valueToString($value), static::valueToString($limit)));
        }
    }

Usage Example

Пример #1
0
 /**
  * @param string $plainPassword
  * @param string $salt
  *
  * @return string
  *
  * @throws \InvalidArgumentException
  * @throws \LogicException when the algorithm is not supported
  */
 private function encodePassword($plainPassword, $salt)
 {
     Assert::lessThanEq(strlen($plainPassword), self::MAX_PASSWORD_LENGTH, sprintf('The password must be at most %d characters long.', self::MAX_PASSWORD_LENGTH));
     if (!in_array($this->algorithm, hash_algos(), true)) {
         throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
     }
     $digest = hash_pbkdf2($this->algorithm, $plainPassword, $salt, $this->iterations, $this->length, true);
     return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
 }