Skip to content

Commit

Permalink
remove initialize method in captcha classes (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Jun 25, 2024
1 parent c04729b commit c92927b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 0 additions & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
}

$captchaInstance = new $captcha_class(...$params);
$captchaInstance->initialize();
}
else
{
Expand Down
19 changes: 17 additions & 2 deletions htdocs/newcaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@
require_once(__DIR__ . "/../lib/captcha/" . $captcha_class . ".php");
error_log("Captcha module $captcha_class successfully loaded");

$captchaInstance = new $captcha_class();
$captchaInstance->initialize();
# Inspect parameters of constructor
$reflection = new ReflectionClass($captcha_class);
$constructorParams = $reflection->getConstructor()->getParameters();

# Gather parameters to pass to the class: all config params to pass
$definedVariables = get_defined_vars(); # get all variables, including configuration
$params = [];
foreach ($constructorParams AS $param) {
if(!isset($definedVariables[$param->name]))
{
error_log("Error: Missing param $param->name for $captcha_class");
exit(1);
}
array_push($params, $definedVariables[$param->name]);
}

$captchaInstance = new $captcha_class(...$params);
}
else
{
Expand Down
5 changes: 0 additions & 5 deletions lib/captcha/InternalCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
class InternalCaptcha extends Captcha
{

# Function for initializing the component
# loading libraries,...
function initialize(){
}

# Function that insert extra css
function generate_css_captcha(){
$captcha_css = '
Expand Down

0 comments on commit c92927b

Please sign in to comment.