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\Driver;
24

25
use Shieldon\Firewall\Driver\DriverInterface;
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 DriverFactory
35
{
36
    /**
37
     * Create a driver instance.
38
     *
39
     * @param string $type    The driver's type string.
40
     * @param array  $setting The configuration of that driver.
41
     *
42
     * @return DriverInterface|null
43
     */
44 3
    public static function getInstance(string $type, array $setting)
45
    {
46 3
        $className = '\Shieldon\Firewall\Firewall\Driver\Item' . self::getCamelCase($type) . 'Driver';
47

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

51
    /**
52
     * Covert string with dashes into camel-case string.
53
     *
54
     * @param string $string A string with dashes.
55
     *
56
     * @return string
57
     */
58 3
    public static function getCamelCase(string $string = '')
59
    {
60 3
        $str = explode('-', $string);
61 3
        $str = implode(
62 3
            '',
63 3
            array_map(
64
                function ($word) {
65 3
                    return ucwords($word); 
66 3
                },
67 3
                $str
68
            )
69
        );
70 3
        return $str;
71
    }
72
}

Read our documentation on viewing source code .

Loading