Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LaminasBase
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 verify
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getCaptcha
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlInternalId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlInputId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Laminas base CAPTCHA
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2020.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  CAPTCHA
25 * @author   Mario Trojan <mario.trojan@uni-tuebingen.de>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\Captcha;
31
32use Laminas\Mvc\Controller\Plugin\Params;
33
34/**
35 * Laminas base CAPTCHA
36 *
37 * @category VuFind
38 * @package  CAPTCHA
39 * @author   Mario Trojan <mario.trojan@uni-tuebingen.de>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org/wiki/development Wiki
42 */
43abstract class LaminasBase extends AbstractBase
44{
45    /**
46     * Laminas CAPTCHA object
47     *
48     * @var \Laminas\Captcha\AbstractWord
49     */
50    protected $captcha;
51
52    /**
53     * HTML input name for generated captcha
54     *
55     * @var string
56     */
57    protected $captchaHtmlInternalId = 'captcha-id';
58
59    /**
60     * HTML input name for user input
61     *
62     * @var string
63     */
64    protected $captchaHtmlInputId = 'captcha-input';
65
66    /**
67     * Constructor
68     *
69     * @param \Laminas\Captcha\AbstractWord $captcha Laminas CAPTCHA object
70     */
71    public function __construct(\Laminas\Captcha\AbstractWord $captcha)
72    {
73        $this->captcha = $captcha;
74        $this->captchaHtmlInputId .= '-' . $this->getId();
75        $this->captchaHtmlInternalId .= '-' . $this->getId();
76    }
77
78    /**
79     * Pull the captcha field from controller params and check them for accuracy
80     *
81     * @param Params $params Controller params
82     *
83     * @return bool
84     */
85    public function verify(Params $params): bool
86    {
87        $validateParams = [
88            'id' => $params->fromPost($this->captchaHtmlInternalId),
89            'input' => $params->fromPost($this->captchaHtmlInputId),
90        ];
91        return $this->captcha->isValid($validateParams);
92    }
93
94    /**
95     * Laminas CAPTCHA object
96     *
97     * @return \Laminas\Captcha\AbstractWord
98     */
99    public function getCaptcha(): \Laminas\Captcha\AbstractWord
100    {
101        return $this->captcha;
102    }
103
104    /**
105     * Getter for template
106     *
107     * @return string
108     */
109    public function getHtmlInternalId(): string
110    {
111        return $this->captchaHtmlInternalId;
112    }
113
114    /**
115     * Getter for template
116     *
117     * @return string
118     */
119    public function getHtmlInputId(): string
120    {
121        return $this->captchaHtmlInputId;
122    }
123}