Package.php
3.12 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Automattic\WooCommerce\Blocks\Domain;
use Automattic\WooCommerce\Blocks\Options;
use Automattic\WooCommerce\Blocks\Domain\Services\FeatureGating;
/**
* Main package class.
*
* Returns information about the package and handles init.
*
* @since 2.5.0
*/
class Package {
/**
* Holds the current version of the blocks plugin.
*
* @var string
*/
private $version;
/**
* Holds the main path to the blocks plugin directory.
*
* @var string
*/
private $path;
/**
* Holds locally the plugin_dir_url to avoid recomputing it.
*
* @var string
*/
private $plugin_dir_url;
/**
* Holds the feature gating class instance.
*
* @var FeatureGating
*/
private $feature_gating;
/**
* Constructor
*
* @param string $version Version of the plugin.
* @param string $plugin_path Path to the main plugin file.
* @param FeatureGating $feature_gating Feature gating class instance.
*/
public function __construct( $version, $plugin_path, FeatureGating $feature_gating ) {
$this->version = $version;
$this->path = $plugin_path;
$this->feature_gating = $feature_gating;
}
/**
* Returns the version of the plugin.
*
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Returns the version of the plugin stored in the database.
*
* @return string
*/
public function get_version_stored_on_db() {
return get_option( Options::WC_BLOCK_VERSION, '' );
}
/**
* Set the version of the plugin stored in the database.
* This is useful during the first installation or after the upgrade process.
*/
public function set_version_stored_on_db() {
update_option( Options::WC_BLOCK_VERSION, $this->get_version() );
}
/**
* Returns the path to the plugin directory.
*
* @param string $relative_path If provided, the relative path will be
* appended to the plugin path.
*
* @return string
*/
public function get_path( $relative_path = '' ) {
return trailingslashit( $this->path ) . $relative_path;
}
/**
* Returns the url to the blocks plugin directory.
*
* @param string $relative_url If provided, the relative url will be
* appended to the plugin url.
*
* @return string
*/
public function get_url( $relative_url = '' ) {
if ( ! $this->plugin_dir_url ) {
// Append index.php so WP does not return the parent directory.
$this->plugin_dir_url = plugin_dir_url( $this->path . '/index.php' );
}
return $this->plugin_dir_url . $relative_url;
}
/**
* Returns an instance of the the FeatureGating class.
*
* @return FeatureGating
*/
public function feature() {
return $this->feature_gating;
}
/**
* Checks if we're executing the code in an experimental build mode.
*
* @return boolean
*/
public function is_experimental_build() {
return $this->feature()->is_experimental_build();
}
/**
* Checks if we're executing the code in an feature plugin or experimental build mode.
*
* @return boolean
*/
public function is_feature_plugin_build() {
return $this->feature()->is_feature_plugin_build();
}
}