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