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 Shieldon\Firewall\Captcha\ImageCaptcha;
27

28
/**
29
 * Get File driver.
30
 */
31
class ItemImage
32
{
33
    /**
34
     * Initialize and get the instance.
35
     *
36
     * @param array $setting The configuration of that driver.
37
     *
38
     * @return CaptchaInterface
39
     */
40 3
    public static function get(array $setting): CaptchaInterface
41
    {
42 3
        $type   = $setting['config']['type']   ?? 'alnum';
43 3
        $length = $setting['config']['length'] ?? 8;
44

45 3
        $imageCaptchaConfig = [];
46

47 2
        switch ($type) {
48 3
            case 'numeric':
49 3
                $imageCaptchaConfig['pool'] = '0123456789';
50 3
                break;
51

52 3
            case 'alpha':
53 3
                $imageCaptchaConfig['pool'] = '0123456789abcdefghijklmnopqrstuvwxyz';
54 3
                break;
55

56 3
            case 'alnum':
57
            default:
58 3
                $imageCaptchaConfig['pool'] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
59
        }
60

61 3
        $imageCaptchaConfig['word_length'] = $length;
62

63 3
        return new ImageCaptcha($imageCaptchaConfig);
64
    }
65
}

Read our documentation on viewing source code .

Loading