Mark V
1: <?php
2: namespace MOC\V\Component\Captcha\Component\Bridge\Repository;
3:
4: use MOC\V\Component\Captcha\Component\Bridge\Bridge;
5: use MOC\V\Component\Captcha\Component\IBridgeInterface;
6: use MOC\V\Core\GlobalsKernel\GlobalsKernel;
7:
8: /**
9: * Class SimplePhpCaptcha
10: *
11: * @package MOC\V\Component\Captcha\Component\Bridge
12: */
13: class SimplePhpCaptcha extends Bridge implements IBridgeInterface
14: {
15:
16: /** @var string $SessionKey */
17: private $SessionKey = '';
18:
19: /**
20: *
21: */
22: public function __construct()
23: {
24:
25: require_once( __DIR__.'/../../../Vendor/SimplePhpCaptcha/0.0-Master/simple-php-captcha.php' );
26: $this->SessionKey = sha1(__CLASS__);
27: }
28:
29: /**
30: * @return SimplePhpCaptcha
31: * @throws \Exception
32: */
33: public function createCaptcha()
34: {
35:
36: $SESSION = GlobalsKernel::getGlobals()->getSESSION();
37: $SESSION[$this->SessionKey] = \simple_php_captcha();
38: GlobalsKernel::getGlobals()->setSESSION($SESSION);
39: return $this;
40: }
41:
42: /**
43: * @param string $InputValue
44: *
45: * @return bool
46: */
47: public function verifyCaptcha($InputValue)
48: {
49:
50: $SESSION = GlobalsKernel::getGlobals()->getSESSION();
51: return $SESSION[$this->SessionKey]['code'] == $InputValue;
52: }
53:
54: /**
55: * @return string
56: */
57: public function getCode()
58: {
59:
60: $SESSION = GlobalsKernel::getGlobals()->getSESSION();
61: return $SESSION[$this->SessionKey]['code'];
62: }
63:
64: /**
65: * @return string
66: */
67: public function getCaptcha()
68: {
69:
70: $SESSION = GlobalsKernel::getGlobals()->getSESSION();
71: return $SESSION[$this->SessionKey]['image_src'];
72: }
73: }
74: