Fix "Use of undefined constant" error for PHP below 7.2.

This commit is contained in:
Marcin Łojewski
2018-06-13 19:31:56 +02:00
parent 3f4c5e2b05
commit b00f61193e

View File

@@ -54,15 +54,22 @@ class CryptArgon2 extends AbstractAlgorithm
* @param int $threads Number of threads to use for computing. * @param int $threads Number of threads to use for computing.
*/ */
public function __construct( public function __construct(
IL10N $localization, IL10N $localization, $memoryCost = -1, $timeCost = -1, $threads = -1
$memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST,
$timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST,
$threads = PASSWORD_ARGON2_DEFAULT_THREADS
) { ) {
if (version_compare(PHP_VERSION, "7.2.0") === -1) { if (version_compare(PHP_VERSION, "7.2.0") === -1) {
throw new \RuntimeException( throw new \RuntimeException(
"PASSWORD_ARGON2I requires PHP 7.2.0 or above." "PASSWORD_ARGON2I requires PHP 7.2.0 or above."
); );
} else {
if ($memoryCost === -1) {
$memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST;
}
if ($timeCost === -1) {
$timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST;
}
if ($threads === -1) {
$threads = PASSWORD_ARGON2_DEFAULT_THREADS;
}
} }
parent::__construct($localization); parent::__construct($localization);