Continued:
[core.git] / framework / main / classes / helper / captcha / class_BaseCaptcha.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Helper\Captcha;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator;
7 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
9 use Org\Mxchange\CoreFramework\Helper\BaseHelper;
10 use Org\Mxchange\CoreFramework\Helper\Helper;
11 use Org\Mxchange\CoreFramework\Traits\Helper\HelperTrait;
12
13 /**
14  * A general captcha
15  *
16  * @author              Roland Haeder <webmaster@shipsimu.org>
17  * @version             0.0.0
18  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
19  * @license             GNU GPL 3.0 or any newer version
20  * @link                http://www.shipsimu.org
21  *
22  * This program is free software: you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation, either version 3 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program. If not, see <http://www.gnu.org/licenses/>.
34  */
35 abstract class BaseCaptcha extends BaseHelper implements Helper {
36         // Load traits
37         use HelperTrait;
38
39         /**
40          * Instance of a RNG
41          */
42         private $rngInstance = NULL;
43
44         /**
45          * Protected constructor
46          *
47          * @param       $className      Name of the class
48          * @return      void
49          */
50         protected function __construct (string $className) {
51                 // Call parent constructor
52                 parent::__construct($className);
53         }
54
55         /**
56          * Setter for RNG instance
57          *
58          * @param       $rngInstance    An instance of a random number generator (RNG)
59          * @return      void
60          */
61         protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
62                 $this->rngInstance = $rngInstance;
63         }
64
65         /**
66          * Getter for RNG instance
67          *
68          * @return      $rngInstance    An instance of a random number generator (RNG)
69          */
70         public final function getRngInstance () {
71                 return $this->rngInstance;
72         }
73
74         /**
75          * Initializes the random number generator (RNG)
76          *
77          * @param       $extraInstance  An extra instance, just for better hash data
78          * @return      void
79          */
80         protected final function initializeRandomNumberGenerator (FrameworkInterface $extraInstance = NULL) {
81                 // Get an RNG from factory
82                 $this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class', array($extraInstance)));
83         }
84
85 }