Completed
Push — master ( 7840cd...ebd957 )
by CodexShaper
11:45
created

DB::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * The database file.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 *
8
 * @package    WPB
9
 * @subpackage WPB/src/Database
10
 */
11
12
namespace WPB\Database;
13
14
use Illuminate\Database\Capsule\Manager as Capsule;
15
16
/**
17
 * The Database class.
18
 *
19
 * @since      1.0.0
20
 * @package    WPB
21
 * @subpackage WPB/src/Database
22
 * @author     Md Abu Ahsan basir <[email protected]>
23
 */
24
class DB extends Capsule {
25
26
	/**
27
	 * The database instance.
28
	 *
29
	 * @since    1.0.0
30
	 * @access   protected
31
	 * @var      \WPB\Database\DB    $instance    The database instance.
32
	 */
33
	protected static $instance = false;
34
35
	/**
36
	 * Return database instance.
37
	 *
38
	 * @since    1.0.0
39
	 * @access   public
40
	 *
41
	 * @return null|\WPB\Database\DB
42
	 */
43
	public static function instance() {
44
		if ( ! static::$instance ) {
45
			static::$instance = new self();
46
		}
47
48
		return static::$instance;
49
	}
50
51
	/**
52
	 * The database constructor.
53
	 *
54
	 * @since    1.0.0
55
	 * @access   public
56
	 *
57
	 * @return void
58
	 */
59
	public function __construct() {
60
		parent::__construct();
61
62
		global $wpdb;
63
64
		$this->addConnection(
65
			array(
66
67
				'driver'    => 'mysql',
68
				'host'      => $wpdb->dbhost,
69
				'database'  => $wpdb->dbname,
70
				'username'  => $wpdb->dbuser,
71
				'password'  => $wpdb->dbpassword,
72
				'prefix'    => $wpdb->prefix,
73
				'charset'   => $wpdb->charset,
74
				'collation' => $wpdb->collate,
75
			)
76
		);
77
78
		// Make this Capsule instance available globally.
79
		$this->setAsGlobal();
80
		// Setup the Eloquent ORM.
81
		$this->bootEloquent();
82
	}
83
}
84