Commit | Line | Data |
---|---|---|
96714cab | 1 | <?php |
a9229942 | 2 | |
96714cab | 3 | namespace wcf\system\captcha; |
a9229942 | 4 | |
734662c9 | 5 | use wcf\data\object\type\ObjectType; |
96714cab MS |
6 | use wcf\data\object\type\ObjectTypeCache; |
7 | use wcf\system\SingletonFactory; | |
8 | use wcf\system\WCF; | |
9 | ||
10 | /** | |
11 | * Handles captchas. | |
a9229942 TD |
12 | * |
13 | * @author Matthias Schmidt | |
14 | * @copyright 2001-2019 WoltLab GmbH | |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
96714cab | 16 | */ |
a9229942 TD |
17 | class CaptchaHandler extends SingletonFactory |
18 | { | |
19 | /** | |
20 | * available captcha object types | |
21 | * @var ObjectType[] | |
22 | */ | |
23 | protected $objectTypes = []; | |
24 | ||
25 | /** | |
26 | * Returns the available captcha types for selection. | |
27 | * | |
28 | * @return string[] | |
29 | */ | |
30 | public function getCaptchaSelection() | |
31 | { | |
32 | $selection = []; | |
33 | foreach ($this->objectTypes as $objectType) { | |
34 | if ($objectType->getProcessor()->isAvailable()) { | |
35 | $selection[$objectType->objectType] = WCF::getLanguage()->get('wcf.captcha.' . $objectType->objectType); | |
36 | } | |
37 | } | |
38 | ||
39 | return $selection; | |
40 | } | |
41 | ||
42 | /** | |
43 | * Returns the captcha object type with the given id or `null` if no such | |
44 | * object type exists. | |
45 | * | |
46 | * @param int $objectTypeID | |
47 | * @return ObjectType|null | |
48 | */ | |
49 | public function getObjectType($objectTypeID) | |
50 | { | |
813c41ce | 51 | return $this->objectTypes[$objectTypeID] ?? null; |
a9229942 TD |
52 | } |
53 | ||
54 | /** | |
55 | * Returns the captcha object type with the given name or null if no such | |
56 | * object type exists. | |
57 | * | |
58 | * @param string $objectType | |
59 | * @return ObjectType|null | |
60 | */ | |
61 | public function getObjectTypeByName($objectType) | |
62 | { | |
63 | return ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.captcha', $objectType); | |
64 | } | |
65 | ||
66 | /** | |
67 | * @inheritDoc | |
68 | */ | |
69 | protected function init() | |
70 | { | |
71 | $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.captcha'); | |
72 | foreach ($objectTypes as $objectType) { | |
73 | $this->objectTypes[$objectType->objectTypeID] = $objectType; | |
74 | } | |
75 | } | |
96714cab | 76 | } |