class-backup-size.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Smush\Core;
class Backup_Size {
private $dir;
private $file;
private $width;
private $height;
public function __construct( $dir ) {
$this->dir = $dir;
}
/**
* @return mixed
*/
public function get_file() {
return $this->file;
}
/**
* @param mixed $file
*/
public function set_file( $file ) {
$this->file = $file;
return $this;
}
/**
* @return mixed
*/
public function get_width() {
return $this->width;
}
/**
* @param mixed $width
*/
public function set_width( $width ) {
$this->width = $width;
return $this;
}
/**
* @return mixed
*/
public function get_height() {
return $this->height;
}
/**
* @param mixed $height
*/
public function set_height( $height ) {
$this->height = $height;
return $this;
}
public function from_array( $array ) {
$this->set_file( (string) $this->get_array_value( $array, 'file' ) );
$this->set_width( (int) $this->get_array_value( $array, 'width' ) );
$this->set_height( (int) $this->get_array_value( $array, 'height' ) );
}
public function to_array() {
return array(
'file' => $this->get_file(),
'width' => $this->get_width(),
'height' => $this->get_height(),
);
}
public function get_file_path() {
$file_name = $this->get_file();
return path_join( $this->dir, $file_name );
}
private function get_array_value( $array, $key ) {
return isset( $array[ $key ] ) ? $array[ $key ] : null;
}
public function file_exists() {
return file_exists( $this->get_file_path() );
}
}