1 | <?php |
||
10 | abstract class Database_Backup_Engine extends Backup_Engine { |
||
11 | |||
12 | /** |
||
13 | * The filename for the resulting Backup |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | public $backup_filename = ''; |
||
18 | |||
19 | /** |
||
20 | * The database host string, typically the value of |
||
21 | * the `DB_HOST` Constant. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $host = ''; |
||
26 | |||
27 | /** |
||
28 | * The database socket, if it's using a socket connection |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $socket = ''; |
||
33 | |||
34 | /** |
||
35 | * The database port, if a custom one is set |
||
36 | * |
||
37 | * @var integer |
||
38 | */ |
||
39 | private $port = 0; |
||
40 | |||
41 | /** |
||
42 | * Individual Database Backup Engine implementations must include |
||
43 | * a backup method at a minimum. |
||
44 | * |
||
45 | * @return [type] [description] |
||
|
|||
46 | */ |
||
47 | abstract public function backup(); |
||
48 | |||
49 | /** |
||
50 | * Setup some general database backup settings |
||
51 | * |
||
52 | * Child classes must call `parent::__construct` in their own constructor. |
||
53 | */ |
||
54 | public function __construct() { |
||
55 | |||
56 | parent::__construct(); |
||
57 | |||
58 | $this->parse_db_host_constant(); |
||
59 | |||
60 | // Set a default backup filename |
||
61 | $this->set_backup_filename( 'database-' . $this->get_name() . '.sql' ); |
||
62 | |||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get the database charset setting. |
||
67 | * |
||
68 | * @return [string The database charset. |
||
69 | */ |
||
70 | public function get_charset() { |
||
74 | |||
75 | /** |
||
76 | * Get the database collate setting. |
||
77 | * |
||
78 | * @return string The database collage setting. |
||
79 | */ |
||
80 | public function get_collate() { |
||
84 | |||
85 | /** |
||
86 | * Get the database name. |
||
87 | * |
||
88 | * @return string The database name. |
||
89 | */ |
||
90 | public function get_name() { |
||
94 | |||
95 | /** |
||
96 | * Get the database user. |
||
97 | * |
||
98 | * @return string The database user. |
||
99 | */ |
||
100 | public function get_user() { |
||
104 | |||
105 | /** |
||
106 | * Get the database password. |
||
107 | * |
||
108 | * @return string The database password. |
||
109 | */ |
||
110 | public function get_password() { |
||
114 | |||
115 | /** |
||
116 | * Get the database hostname. |
||
117 | * |
||
118 | * @return string The database hostname. |
||
119 | */ |
||
120 | public function get_host() { |
||
123 | |||
124 | /** |
||
125 | * Get the database port. |
||
126 | * |
||
127 | * @return int The database port. |
||
128 | */ |
||
129 | public function get_port() { |
||
132 | |||
133 | /** |
||
134 | * Get the database socket. |
||
135 | * |
||
136 | * @return string The database socket. |
||
137 | */ |
||
138 | public function get_socket() { |
||
141 | |||
142 | /** |
||
143 | * Parse the `DB_HOST` constant. |
||
144 | * |
||
145 | * The `DB_HOST` constant potentially contains the hostname, port or socket. |
||
146 | * We need to parse it to figure out the type of mysql connection to make. |
||
147 | * |
||
148 | * @param string $constant The Constant to parse. If the string isn't a |
||
149 | * defined Constant then it will be parsed directly. |
||
150 | */ |
||
151 | public function parse_db_host_constant( $constant = 'DB_HOST' ) { |
||
188 | |||
189 | /** |
||
190 | * Verify that the database backup was successful. |
||
191 | * |
||
192 | * It's important this function is performant as it's called after every |
||
193 | * backup. |
||
194 | * |
||
195 | * @return bool Whether the backup completed successfully |
||
196 | */ |
||
197 | public function verify_backup() { |
||
217 | |||
218 | } |
||
219 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.