1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <contact@terryl.in>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 * 
10
 * php version 7.1.0
11
 * 
12
 * @category  Web-security
13
 * @package   Shieldon
14
 * @author    Terry Lin <contact@terryl.in>
15
 * @copyright 2019 terrylinooo
16
 * @license   https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
17
 * @link      https://github.com/terrylinooo/shieldon
18
 * @see       https://shieldon.io
19
 */
20

21
declare(strict_types=1);
22

23
namespace Shieldon\Firewall\Firewall\Captcha;
24

25
use Shieldon\Firewall\Captcha\CaptchaInterface;
26
use function array_map;
27
use function explode;
28
use function implode;
29
use function ucwords;
30

31
/*
32
 * The factory creates driver instances.
33
 */
34
class CaptchaFactory
35
{
36
    /**
37
     * Create a captcha instance.
38
     *
39
     * @param string $type    The driver's type string.
40
     * @param array  $setting The configuration of that driver.
41
     *
42
     * @return CaptchaInterface
43
     */
44 3
    public static function getInstance(string $type, array $setting): CaptchaInterface
45
    {
46 3
        $className = '\Shieldon\Firewall\Firewall\Captcha\Item' . self::getCamelCase($type);
47

48 3
        return $className::get($setting);
49
    }
50

51
    /**
52
     * Check whether a messenger is available or not.
53
     *
54
     * @param array  $setting The configuration of that messanger.
55
     *
56
     * @return bool
57
     */
58 3
    public static function check(array $setting): bool
59
    {
60 3
        if (empty($setting['enable'])) {
61 3
            return false;
62
        }
63

64 3
        return true;
65
    }
66

67
    /**
68
     * Covert string with dashes into camel-case string.
69
     *
70
     * @param string $string A string with dashes.
71
     *
72
     * @return string
73
     */
74 3
    public static function getCamelCase(string $string = '')
75
    {
76 3
        $str = explode('-', $string);
77 3
        $str = implode(
78 3
            '',
79 3
            array_map(
80
                function ($word) {
81 3
                    return ucwords($word); 
82 3
                },
83 3
                $str
84
            )
85
        );
86 3
        return $str;
87
    }
88
}

Read our documentation on viewing source code .

Loading