1: <?php
2:
3: namespace Charcoal\Source;
4:
5: // Dependencies from `PHP`
6: use \InvalidArgumentException;
7:
8: // Local namespace dependencies
9: use \Charcoal\Source\SourceConfig;
10:
11: /**
12: *
13: */
14: class DatabaseSourceConfig extends SourceConfig
15: {
16: /**
17: * @var string $hostname
18: */
19: private $hostname;
20:
21: /**
22: * @var string $username
23: */
24: private $username;
25:
26: /**
27: * @var string $password
28: */
29: private $password;
30:
31: /**
32: * @var string $database
33: */
34: private $database;
35:
36:
37: /**
38: * @var boolean $disableUtf8
39: */
40: private $disableUtf8;
41:
42: /**
43: * @return array
44: */
45: public function defaults()
46: {
47: return [
48: 'type' => 'mysql',
49: 'hostname' => 'localhost',
50: 'username' => '',
51: 'password' => '',
52: 'database' => '',
53: 'table' => '',
54: 'disable_ytf8' => false
55: ];
56: }
57:
58: /**
59: * Set hostname
60: *
61: * @param string $hostname The database hostname.
62: * @throws InvalidArgumentException If hostname is not a string.
63: * @return DatabaseSourceConfig Chainable
64: */
65: public function setHostname($hostname)
66: {
67: if (!is_string($hostname)) {
68: throw new InvalidArgumentException(
69: 'Hostname must be a string.'
70: );
71: }
72: $this->hostname = $hostname;
73: return $this;
74: }
75:
76: /**
77: * Get hostname
78: *
79: * @return string
80: */
81: public function hostname()
82: {
83: return $this->hostname;
84: }
85:
86: /**
87: * Set username
88: *
89: * @param string $username The database username.
90: * @throws InvalidArgumentException If username is not a string.
91: * @return DatabaseSourceConfig Chainable
92: */
93: public function setUsername($username)
94: {
95: if (!is_string($username)) {
96: throw new InvalidArgumentException(
97: 'Username must be a string.'
98: );
99: }
100: $this->username = $username;
101: return $this;
102: }
103:
104: /**
105: * Get username
106: *
107: * @return string
108: */
109: public function username()
110: {
111: return $this->username;
112: }
113:
114: /**
115: * Set password
116: *
117: * @param string $password The database password.
118: * @throws InvalidArgumentException If password is not a string.
119: * @return DatabaseSourceConfig Chainable
120: */
121: public function setPassword($password)
122: {
123: if (!is_string($password)) {
124: throw new InvalidArgumentException(
125: 'Password must be a string.'
126: );
127: }
128: $this->password = $password;
129: return $this;
130: }
131:
132: /**
133: * Get password
134: *
135: * @return string
136: */
137: public function password()
138: {
139: return $this->password;
140: }
141:
142: /**
143: * Set database
144: *
145: * @param string $database The database name.
146: * @throws InvalidArgumentException If database is not a string.
147: * @return DatabaseSourceConfig Chainable
148: */
149: public function setDatabase($database)
150: {
151: if (!is_string($database)) {
152: throw new InvalidArgumentException(
153: 'Database must be a string.'
154: );
155: }
156: $this->database = $database;
157: return $this;
158: }
159:
160: /**
161: * Get database
162: *
163: * @return string
164: */
165: public function database()
166: {
167: return $this->database;
168: }
169:
170: /**
171: * @param boolean $disableUtf8 The "disable UTF8" flag.
172: * @return DatabaseSourceConfig Chainable
173: */
174: public function setDisableUtf8($disableUtf8)
175: {
176: $this->disableUtf8 = !!$disableUtf8;
177: return $this;
178: }
179:
180: /**
181: * @return bools
182: */
183: public function disableUtf8()
184: {
185: return $this->disableUtf8;
186: }
187: }
188: