class-wpml-upgrade-command-definition.php
1.94 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
<?php
/**
* @author OnTheGo Systems
*/
class WPML_Upgrade_Command_Definition {
private $class_name;
private $dependencies = array();
/** @var array Can be 'admin', 'ajax' or 'front-end' */
private $scopes = array();
private $method;
/** @var callable|null */
private $factory_method;
/**
* WPML_Upgrade_Command_Definition constructor.
*
* @param string $class_name A class implementing \IWPML_Upgrade_Command.
* @param array $dependencies An array of dependencies passed to the `$class_name`'s constructor.
* @param array $scopes An array of scope values. Accepted values are: `\WPML_Upgrade::SCOPE_ADMIN`, `\WPML_Upgrade::SCOPE_AJAX`, and `\WPML_Upgrade::SCOPE_FRONT_END`.
* @param string|null $method The method to call to run the upgrade (otherwise, it calls the "run" method),
* @param callable $factory_method
*/
public function __construct(
$class_name,
array $dependencies,
array $scopes,
$method = null,
callable $factory_method = null
) {
$this->class_name = $class_name;
$this->dependencies = $dependencies;
$this->scopes = $scopes;
$this->method = $method;
$this->factory_method = $factory_method;
}
/**
* @return array
*/
public function get_dependencies() {
return $this->dependencies;
}
/**
* @return string
*/
public function get_class_name() {
return $this->class_name;
}
/**
* @return string
*/
public function get_method() {
return $this->method;
}
/**
* @return array
*/
public function get_scopes() {
return $this->scopes;
}
/**
* @return callable|null
*/
public function get_factory_method() {
return $this->factory_method;
}
/**
* @return IWPML_Upgrade_Command
*/
public function create() {
if ( $this->get_factory_method() ) {
$factory_method = $this->get_factory_method();
return $factory_method();
}
$class_name = $this->get_class_name();
return new $class_name( $this->get_dependencies() );
}
}