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\MysqlDriver;
26
use PDO;
27
use PDOException;
28

29
/**
30
 * Get MySQL driver.
31
 */
32
class ItemMysqlDriver
33
{
34
    /**
35
     * Initialize and get the instance.
36
     *
37
     * @param array $setting The configuration of that driver.
38
     *
39
     * @return MysqlDriver|null
40
     */
41 3
    public static function get(array $setting)
42
    {
43 3
        $instance = null;
44

45
        try {
46
  
47
            $host = 'mysql' . 
48 3
                ':host='    . $setting['host'] .
49 3
                ';dbname='  . $setting['dbname'] .
50 3
                ';charset=' . $setting['charset'];
51

52 3
            $user = (string) $setting['user'];
53 3
            $pass = (string) $setting['pass'];
54

55
            // Create a PDO instance.
56 3
            $pdoInstance = new PDO($host, $user, $pass);
57

58
            // Use MySQL data driver.
59 3
            $instance = new MysqlDriver($pdoInstance);
60

61
            // @codeCoverageIgnoreStart
62

63
        } catch (PDOException $e) {
64
            echo $e->getMessage();
65
        }
66

67
        // @codeCoverageIgnoreEnd
68

69 3
        return $instance;
70
    }
71
}

Read our documentation on viewing source code .

Loading