@@ -25,14 +25,14 @@ |
||
25 | 25 | * @param int $code |
26 | 26 | * @param \Exception $previous |
27 | 27 | */ |
28 | - public function __construct( $interface_name, $message = '', $code = 0, \Exception $previous = null ) { |
|
29 | - if ( empty( $message ) ) { |
|
28 | + public function __construct($interface_name, $message = '', $code = 0, \Exception $previous = null) { |
|
29 | + if (empty($message)) { |
|
30 | 30 | $message = sprintf( |
31 | - __( 'The "%1$s" Interface is either missing or invalid.', 'event_espresso' ), |
|
31 | + __('The "%1$s" Interface is either missing or invalid.', 'event_espresso'), |
|
32 | 32 | $interface_name |
33 | 33 | ); |
34 | 34 | } |
35 | - parent::__construct( $message, $code, $previous ); |
|
35 | + parent::__construct($message, $code, $previous); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | } |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * @param int $code |
30 | 30 | * @param Exception $previous |
31 | 31 | */ |
32 | - public function __construct( $var_name, $variable, $expected, $message = '', $code = 0, Exception $previous = null ) { |
|
33 | - if ( empty( $message ) ) { |
|
34 | - $expected = strpos( ' was expected.', $expected ) === false |
|
35 | - ? $this->addIndefiniteArticle( $expected ) . ' was expected.' |
|
32 | + public function __construct($var_name, $variable, $expected, $message = '', $code = 0, Exception $previous = null) { |
|
33 | + if (empty($message)) { |
|
34 | + $expected = strpos(' was expected.', $expected) === false |
|
35 | + ? $this->addIndefiniteArticle($expected).' was expected.' |
|
36 | 36 | : $expected; |
37 | 37 | $message = sprintf( |
38 | 38 | __( |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | 'event_espresso' |
41 | 41 | ), |
42 | 42 | $var_name, |
43 | - $this->addIndefiniteArticle( gettype( $variable ) ), |
|
43 | + $this->addIndefiniteArticle(gettype($variable)), |
|
44 | 44 | $expected |
45 | 45 | ); |
46 | 46 | } |
47 | - parent::__construct( $message, $code, $previous ); |
|
47 | + parent::__construct($message, $code, $previous); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * @param $string |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - protected function addIndefiniteArticle( $string ) { |
|
57 | - if ( strtolower( $string ) === 'null' ) { |
|
56 | + protected function addIndefiniteArticle($string) { |
|
57 | + if (strtolower($string) === 'null') { |
|
58 | 58 | return $string; |
59 | 59 | } |
60 | - return ( stripos( 'aeiou', $string[0] ) !== false ? 'an ' : 'a ' ) . $string; |
|
60 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string; |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | // End of file InvalidDataTypeException.php |
@@ -24,14 +24,14 @@ |
||
24 | 24 | * @param int $code |
25 | 25 | * @param \Exception $previous |
26 | 26 | */ |
27 | - public function __construct( $class_name, $message = '', $code = 0, \Exception $previous = null ) { |
|
28 | - if ( empty( $message ) ) { |
|
27 | + public function __construct($class_name, $message = '', $code = 0, \Exception $previous = null) { |
|
28 | + if (empty($message)) { |
|
29 | 29 | $message = sprintf( |
30 | - __( 'The "%1$s" Class is either missing or invalid.', 'event_espresso' ), |
|
30 | + __('The "%1$s" Class is either missing or invalid.', 'event_espresso'), |
|
31 | 31 | $class_name |
32 | 32 | ); |
33 | 33 | } |
34 | - parent::__construct( $message, $code, $previous ); |
|
34 | + parent::__construct($message, $code, $previous); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
42 | 42 | { |
43 | - if (! isset($arguments[0], $arguments[1])) { |
|
43 | + if ( ! isset($arguments[0], $arguments[1])) { |
|
44 | 44 | throw new InvalidArgumentException( |
45 | 45 | esc_html__( |
46 | 46 | 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | ); |
50 | 50 | } |
51 | 51 | $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
52 | - if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
52 | + if ( ! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
53 | 53 | throw new DomainException( |
54 | 54 | sprintf( |
55 | 55 | esc_html__( |
@@ -24,44 +24,44 @@ |
||
24 | 24 | class DomainFactory |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
29 | - * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
30 | - * constructor. Must at least include the following two value objects: |
|
31 | - * array( |
|
32 | - * EventEspresso\core\domain\values\FilePath $plugin_file |
|
33 | - * EventEspresso\core\domain\values\Version $version |
|
34 | - * ) |
|
35 | - * @return mixed |
|
36 | - * @throws DomainException |
|
37 | - * @throws InvalidArgumentException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidInterfaceException |
|
40 | - */ |
|
41 | - public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
42 | - { |
|
43 | - if (! isset($arguments[0], $arguments[1])) { |
|
44 | - throw new InvalidArgumentException( |
|
45 | - esc_html__( |
|
46 | - 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
47 | - 'event_espresso' |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
52 | - if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
53 | - throw new DomainException( |
|
54 | - sprintf( |
|
55 | - esc_html__( |
|
56 | - 'The requested Domain class "%1$s" could not be loaded.', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - $domain_fqcn |
|
60 | - ) |
|
61 | - ); |
|
62 | - } |
|
63 | - return $domain; |
|
64 | - } |
|
27 | + /** |
|
28 | + * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
29 | + * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
30 | + * constructor. Must at least include the following two value objects: |
|
31 | + * array( |
|
32 | + * EventEspresso\core\domain\values\FilePath $plugin_file |
|
33 | + * EventEspresso\core\domain\values\Version $version |
|
34 | + * ) |
|
35 | + * @return mixed |
|
36 | + * @throws DomainException |
|
37 | + * @throws InvalidArgumentException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidInterfaceException |
|
40 | + */ |
|
41 | + public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
42 | + { |
|
43 | + if (! isset($arguments[0], $arguments[1])) { |
|
44 | + throw new InvalidArgumentException( |
|
45 | + esc_html__( |
|
46 | + 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
47 | + 'event_espresso' |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
52 | + if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
53 | + throw new DomainException( |
|
54 | + sprintf( |
|
55 | + esc_html__( |
|
56 | + 'The requested Domain class "%1$s" could not be loaded.', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + $domain_fqcn |
|
60 | + ) |
|
61 | + ); |
|
62 | + } |
|
63 | + return $domain; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
67 | 67 |
@@ -20,42 +20,42 @@ |
||
20 | 20 | class FilePath |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string file_path |
|
25 | - */ |
|
26 | - private $file_path; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * FilePath constructor. |
|
31 | - * |
|
32 | - * @param string $file_path |
|
33 | - * @throws InvalidDataTypeException |
|
34 | - * @throws InvalidFilePathException |
|
35 | - */ |
|
36 | - public function __construct($file_path) |
|
37 | - { |
|
38 | - if (! is_string($file_path)) { |
|
39 | - throw new InvalidDataTypeException( |
|
40 | - '$file_path', |
|
41 | - $file_path, |
|
42 | - 'string' |
|
43 | - ); |
|
44 | - } |
|
45 | - if (! is_readable($file_path)) { |
|
46 | - throw new InvalidFilePathException($file_path); |
|
47 | - } |
|
48 | - $this->file_path = $file_path; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function __toString() |
|
56 | - { |
|
57 | - return $this->file_path; |
|
58 | - } |
|
23 | + /** |
|
24 | + * @var string file_path |
|
25 | + */ |
|
26 | + private $file_path; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * FilePath constructor. |
|
31 | + * |
|
32 | + * @param string $file_path |
|
33 | + * @throws InvalidDataTypeException |
|
34 | + * @throws InvalidFilePathException |
|
35 | + */ |
|
36 | + public function __construct($file_path) |
|
37 | + { |
|
38 | + if (! is_string($file_path)) { |
|
39 | + throw new InvalidDataTypeException( |
|
40 | + '$file_path', |
|
41 | + $file_path, |
|
42 | + 'string' |
|
43 | + ); |
|
44 | + } |
|
45 | + if (! is_readable($file_path)) { |
|
46 | + throw new InvalidFilePathException($file_path); |
|
47 | + } |
|
48 | + $this->file_path = $file_path; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function __toString() |
|
56 | + { |
|
57 | + return $this->file_path; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | 61 | } |
@@ -35,14 +35,14 @@ |
||
35 | 35 | */ |
36 | 36 | public function __construct($file_path) |
37 | 37 | { |
38 | - if (! is_string($file_path)) { |
|
38 | + if ( ! is_string($file_path)) { |
|
39 | 39 | throw new InvalidDataTypeException( |
40 | 40 | '$file_path', |
41 | 41 | $file_path, |
42 | 42 | 'string' |
43 | 43 | ); |
44 | 44 | } |
45 | - if (! is_readable($file_path)) { |
|
45 | + if ( ! is_readable($file_path)) { |
|
46 | 46 | throw new InvalidFilePathException($file_path); |
47 | 47 | } |
48 | 48 | $this->file_path = $file_path; |
@@ -21,45 +21,45 @@ |
||
21 | 21 | class FullyQualifiedName |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var string $fully_qualified_name |
|
26 | - */ |
|
27 | - private $fully_qualified_name; |
|
24 | + /** |
|
25 | + * @var string $fully_qualified_name |
|
26 | + */ |
|
27 | + private $fully_qualified_name; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * FullyQualifiedName constructor. |
|
32 | - * |
|
33 | - * @param string $fully_qualified_name |
|
34 | - * @throws InvalidClassException |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - * @throws InvalidDataTypeException |
|
37 | - */ |
|
38 | - public function __construct($fully_qualified_name) |
|
39 | - { |
|
40 | - if (! is_string($fully_qualified_name)) { |
|
41 | - throw new InvalidDataTypeException( |
|
42 | - '$fully_qualified_name', |
|
43 | - $fully_qualified_name, |
|
44 | - 'string' |
|
45 | - ); |
|
46 | - } |
|
47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | - if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | - throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | - } |
|
51 | - throw new InvalidClassException($fully_qualified_name); |
|
52 | - } |
|
53 | - $this->fully_qualified_name = $fully_qualified_name; |
|
54 | - } |
|
30 | + /** |
|
31 | + * FullyQualifiedName constructor. |
|
32 | + * |
|
33 | + * @param string $fully_qualified_name |
|
34 | + * @throws InvalidClassException |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + * @throws InvalidDataTypeException |
|
37 | + */ |
|
38 | + public function __construct($fully_qualified_name) |
|
39 | + { |
|
40 | + if (! is_string($fully_qualified_name)) { |
|
41 | + throw new InvalidDataTypeException( |
|
42 | + '$fully_qualified_name', |
|
43 | + $fully_qualified_name, |
|
44 | + 'string' |
|
45 | + ); |
|
46 | + } |
|
47 | + if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | + if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | + throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | + } |
|
51 | + throw new InvalidClassException($fully_qualified_name); |
|
52 | + } |
|
53 | + $this->fully_qualified_name = $fully_qualified_name; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function __toString() |
|
61 | - { |
|
62 | - return $this->fully_qualified_name; |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function __toString() |
|
61 | + { |
|
62 | + return $this->fully_qualified_name; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | } |
@@ -37,14 +37,14 @@ |
||
37 | 37 | */ |
38 | 38 | public function __construct($fully_qualified_name) |
39 | 39 | { |
40 | - if (! is_string($fully_qualified_name)) { |
|
40 | + if ( ! is_string($fully_qualified_name)) { |
|
41 | 41 | throw new InvalidDataTypeException( |
42 | 42 | '$fully_qualified_name', |
43 | 43 | $fully_qualified_name, |
44 | 44 | 'string' |
45 | 45 | ); |
46 | 46 | } |
47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
47 | + if ( ! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | 48 | if (strpos($fully_qualified_name, 'Interface') !== false) { |
49 | 49 | throw new InvalidInterfaceException($fully_qualified_name); |
50 | 50 | } |
@@ -28,219 +28,219 @@ |
||
28 | 28 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var EE_Request $request |
|
33 | - */ |
|
34 | - protected $request; |
|
31 | + /** |
|
32 | + * @var EE_Request $request |
|
33 | + */ |
|
34 | + protected $request; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var EE_Response $response |
|
38 | - */ |
|
39 | - protected $response; |
|
36 | + /** |
|
37 | + * @var EE_Response $response |
|
38 | + */ |
|
39 | + protected $response; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var EE_Dependency_Map $dependency_map |
|
43 | - */ |
|
44 | - protected $dependency_map; |
|
41 | + /** |
|
42 | + * @var EE_Dependency_Map $dependency_map |
|
43 | + */ |
|
44 | + protected $dependency_map; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var EE_Registry $registry |
|
48 | - */ |
|
49 | - protected $registry; |
|
46 | + /** |
|
47 | + * @var EE_Registry $registry |
|
48 | + */ |
|
49 | + protected $registry; |
|
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * EE_Load_Espresso_Core constructor |
|
55 | - */ |
|
53 | + /** |
|
54 | + * EE_Load_Espresso_Core constructor |
|
55 | + */ |
|
56 | 56 | public function __construct() { |
57 | - // deprecated functions |
|
58 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
59 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * handle |
|
66 | - * sets hooks for running rest of system |
|
67 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | - * starting EE Addons from any other point may lead to problems |
|
69 | - * |
|
70 | - * @param EE_Request $request |
|
71 | - * @param EE_Response $response |
|
72 | - * @return EE_Response |
|
73 | - * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
74 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
75 | - * @throws EE_Error |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws InvalidArgumentException |
|
79 | - */ |
|
80 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
81 | - { |
|
82 | - $this->request = $request; |
|
83 | - $this->response = $response; |
|
84 | - // info about how to load classes required by other classes |
|
85 | - $this->dependency_map = $this->_load_dependency_map(); |
|
86 | - // central repository for classes |
|
87 | - $this->registry = $this->_load_registry(); |
|
88 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
89 | - $loader = LoaderFactory::getLoader($this->registry); |
|
90 | - $this->dependency_map->setLoader($loader); |
|
91 | - // instantiate core Domain class |
|
92 | - DomainFactory::getShared( |
|
93 | - new FullyQualifiedName( |
|
94 | - 'EventEspresso\core\domain\Domain' |
|
95 | - ), |
|
96 | - array( |
|
97 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
98 | - Version::fromString(espresso_version()) |
|
99 | - ) |
|
100 | - ); |
|
101 | - // build DI container |
|
102 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
103 | - // $OpenCoffeeShop->addRecipes(); |
|
104 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
105 | - // workarounds for PHP < 5.3 |
|
106 | - $this->_load_class_tools(); |
|
107 | - // deprecated functions |
|
108 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
109 | - // WP cron jobs |
|
110 | - $loader->getShared('EE_Cron_Tasks'); |
|
111 | - $loader->getShared('EE_Request_Handler'); |
|
112 | - $loader->getShared('EE_System'); |
|
113 | - return $this->response; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return EE_Request |
|
120 | - */ |
|
121 | - public function request() |
|
122 | - { |
|
123 | - return $this->request; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @return EE_Response |
|
130 | - */ |
|
131 | - public function response() |
|
132 | - { |
|
133 | - return $this->response; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return EE_Dependency_Map |
|
140 | - * @throws EE_Error |
|
141 | - */ |
|
142 | - public function dependency_map() |
|
143 | - { |
|
144 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
145 | - throw new EE_Error( |
|
146 | - sprintf( |
|
147 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
148 | - print_r($this->dependency_map, true) |
|
149 | - ) |
|
150 | - ); |
|
151 | - } |
|
152 | - return $this->dependency_map; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return EE_Registry |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public function registry() |
|
162 | - { |
|
163 | - if (! $this->registry instanceof EE_Registry) { |
|
164 | - throw new EE_Error( |
|
165 | - sprintf( |
|
166 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
167 | - print_r($this->registry, true) |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - return $this->registry; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return EE_Dependency_Map |
|
178 | - */ |
|
179 | - private function _load_dependency_map() |
|
180 | - { |
|
181 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
182 | - EE_Error::add_error( |
|
183 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
184 | - __FILE__, __FUNCTION__, __LINE__ |
|
185 | - ); |
|
186 | - wp_die(EE_Error::get_notices()); |
|
187 | - } |
|
188 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
189 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @return EE_Registry |
|
196 | - * @throws \InvalidArgumentException |
|
197 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
198 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
199 | - */ |
|
200 | - private function _load_registry() |
|
201 | - { |
|
202 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
203 | - EE_Error::add_error( |
|
204 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
205 | - __FILE__, __FUNCTION__, __LINE__ |
|
206 | - ); |
|
207 | - wp_die(EE_Error::get_notices()); |
|
208 | - } |
|
209 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
210 | - return EE_Registry::instance($this->dependency_map); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - private function _load_class_tools() |
|
219 | - { |
|
220 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
221 | - EE_Error::add_error( |
|
222 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
223 | - __FILE__, __FUNCTION__, __LINE__ |
|
224 | - ); |
|
225 | - } |
|
226 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * called after the request stack has been fully processed |
|
233 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
234 | - * |
|
235 | - * @param EE_Request $request |
|
236 | - * @param EE_Response $response |
|
237 | - */ |
|
238 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
239 | - { |
|
240 | - if ($response->plugin_deactivated()) { |
|
241 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
242 | - } |
|
243 | - } |
|
57 | + // deprecated functions |
|
58 | + espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
59 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * handle |
|
66 | + * sets hooks for running rest of system |
|
67 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
68 | + * starting EE Addons from any other point may lead to problems |
|
69 | + * |
|
70 | + * @param EE_Request $request |
|
71 | + * @param EE_Response $response |
|
72 | + * @return EE_Response |
|
73 | + * @throws \EventEspresso\core\exceptions\InvalidFilePathException |
|
74 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
75 | + * @throws EE_Error |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws InvalidArgumentException |
|
79 | + */ |
|
80 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
81 | + { |
|
82 | + $this->request = $request; |
|
83 | + $this->response = $response; |
|
84 | + // info about how to load classes required by other classes |
|
85 | + $this->dependency_map = $this->_load_dependency_map(); |
|
86 | + // central repository for classes |
|
87 | + $this->registry = $this->_load_registry(); |
|
88 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
89 | + $loader = LoaderFactory::getLoader($this->registry); |
|
90 | + $this->dependency_map->setLoader($loader); |
|
91 | + // instantiate core Domain class |
|
92 | + DomainFactory::getShared( |
|
93 | + new FullyQualifiedName( |
|
94 | + 'EventEspresso\core\domain\Domain' |
|
95 | + ), |
|
96 | + array( |
|
97 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
98 | + Version::fromString(espresso_version()) |
|
99 | + ) |
|
100 | + ); |
|
101 | + // build DI container |
|
102 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
103 | + // $OpenCoffeeShop->addRecipes(); |
|
104 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
105 | + // workarounds for PHP < 5.3 |
|
106 | + $this->_load_class_tools(); |
|
107 | + // deprecated functions |
|
108 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
109 | + // WP cron jobs |
|
110 | + $loader->getShared('EE_Cron_Tasks'); |
|
111 | + $loader->getShared('EE_Request_Handler'); |
|
112 | + $loader->getShared('EE_System'); |
|
113 | + return $this->response; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return EE_Request |
|
120 | + */ |
|
121 | + public function request() |
|
122 | + { |
|
123 | + return $this->request; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @return EE_Response |
|
130 | + */ |
|
131 | + public function response() |
|
132 | + { |
|
133 | + return $this->response; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return EE_Dependency_Map |
|
140 | + * @throws EE_Error |
|
141 | + */ |
|
142 | + public function dependency_map() |
|
143 | + { |
|
144 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
145 | + throw new EE_Error( |
|
146 | + sprintf( |
|
147 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
148 | + print_r($this->dependency_map, true) |
|
149 | + ) |
|
150 | + ); |
|
151 | + } |
|
152 | + return $this->dependency_map; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return EE_Registry |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public function registry() |
|
162 | + { |
|
163 | + if (! $this->registry instanceof EE_Registry) { |
|
164 | + throw new EE_Error( |
|
165 | + sprintf( |
|
166 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
167 | + print_r($this->registry, true) |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + return $this->registry; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return EE_Dependency_Map |
|
178 | + */ |
|
179 | + private function _load_dependency_map() |
|
180 | + { |
|
181 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
182 | + EE_Error::add_error( |
|
183 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
184 | + __FILE__, __FUNCTION__, __LINE__ |
|
185 | + ); |
|
186 | + wp_die(EE_Error::get_notices()); |
|
187 | + } |
|
188 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
189 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @return EE_Registry |
|
196 | + * @throws \InvalidArgumentException |
|
197 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
198 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
199 | + */ |
|
200 | + private function _load_registry() |
|
201 | + { |
|
202 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
203 | + EE_Error::add_error( |
|
204 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
205 | + __FILE__, __FUNCTION__, __LINE__ |
|
206 | + ); |
|
207 | + wp_die(EE_Error::get_notices()); |
|
208 | + } |
|
209 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
210 | + return EE_Registry::instance($this->dependency_map); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + private function _load_class_tools() |
|
219 | + { |
|
220 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
221 | + EE_Error::add_error( |
|
222 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
223 | + __FILE__, __FUNCTION__, __LINE__ |
|
224 | + ); |
|
225 | + } |
|
226 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * called after the request stack has been fully processed |
|
233 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
234 | + * |
|
235 | + * @param EE_Request $request |
|
236 | + * @param EE_Response $response |
|
237 | + */ |
|
238 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
239 | + { |
|
240 | + if ($response->plugin_deactivated()) { |
|
241 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | |
246 | 246 |
@@ -121,7 +121,7 @@ |
||
121 | 121 | |
122 | 122 | |
123 | 123 | /** |
124 | - * @return Version |
|
124 | + * @return string |
|
125 | 125 | */ |
126 | 126 | public function versionValueObject() |
127 | 127 | { |
@@ -21,112 +21,112 @@ |
||
21 | 21 | abstract class DomainBase implements DomainInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Equivalent to `__FILE__` for main plugin file. |
|
26 | - * |
|
27 | - * @var FilePath |
|
28 | - */ |
|
29 | - private $plugin_file; |
|
30 | - |
|
31 | - /** |
|
32 | - * String indicating version for plugin |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $version; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $plugin_basename |
|
40 | - */ |
|
41 | - private $plugin_basename; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $plugin_path |
|
45 | - */ |
|
46 | - private $plugin_path; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $plugin_url |
|
50 | - */ |
|
51 | - private $plugin_url; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Initializes internal properties. |
|
57 | - * |
|
58 | - * @param FilePath $plugin_file |
|
59 | - * @param Version $version |
|
60 | - * @throws InvalidArgumentException |
|
61 | - * @throws DomainException |
|
62 | - */ |
|
63 | - public function __construct(FilePath $plugin_file, Version $version) |
|
64 | - { |
|
65 | - $this->plugin_file = $plugin_file; |
|
66 | - $this->version = $version; |
|
67 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
68 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
69 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function pluginFile() |
|
77 | - { |
|
78 | - return (string) $this->plugin_file; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function pluginBasename() |
|
87 | - { |
|
88 | - return $this->plugin_basename; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function pluginPath() |
|
97 | - { |
|
98 | - return $this->plugin_path; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function pluginUrl() |
|
107 | - { |
|
108 | - return $this->plugin_url; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function version() |
|
117 | - { |
|
118 | - return (string) $this->version; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return Version |
|
125 | - */ |
|
126 | - public function versionValueObject() |
|
127 | - { |
|
128 | - return $this->version; |
|
129 | - } |
|
24 | + /** |
|
25 | + * Equivalent to `__FILE__` for main plugin file. |
|
26 | + * |
|
27 | + * @var FilePath |
|
28 | + */ |
|
29 | + private $plugin_file; |
|
30 | + |
|
31 | + /** |
|
32 | + * String indicating version for plugin |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $version; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $plugin_basename |
|
40 | + */ |
|
41 | + private $plugin_basename; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $plugin_path |
|
45 | + */ |
|
46 | + private $plugin_path; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $plugin_url |
|
50 | + */ |
|
51 | + private $plugin_url; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Initializes internal properties. |
|
57 | + * |
|
58 | + * @param FilePath $plugin_file |
|
59 | + * @param Version $version |
|
60 | + * @throws InvalidArgumentException |
|
61 | + * @throws DomainException |
|
62 | + */ |
|
63 | + public function __construct(FilePath $plugin_file, Version $version) |
|
64 | + { |
|
65 | + $this->plugin_file = $plugin_file; |
|
66 | + $this->version = $version; |
|
67 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
68 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
69 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function pluginFile() |
|
77 | + { |
|
78 | + return (string) $this->plugin_file; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function pluginBasename() |
|
87 | + { |
|
88 | + return $this->plugin_basename; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function pluginPath() |
|
97 | + { |
|
98 | + return $this->plugin_path; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function pluginUrl() |
|
107 | + { |
|
108 | + return $this->plugin_url; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function version() |
|
117 | + { |
|
118 | + return (string) $this->version; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return Version |
|
125 | + */ |
|
126 | + public function versionValueObject() |
|
127 | + { |
|
128 | + return $this->version; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | 132 | } |
@@ -20,297 +20,297 @@ |
||
20 | 20 | class Version |
21 | 21 | { |
22 | 22 | |
23 | - const RELEASE_TYPE_RC = 'rc'; |
|
24 | - |
|
25 | - const RELEASE_TYPE_BETA = 'beta'; |
|
26 | - |
|
27 | - const RELEASE_TYPE_DECAF = 'decaf'; |
|
28 | - |
|
29 | - const RELEASE_TYPE_PROD = 'p'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var int $major |
|
33 | - */ |
|
34 | - private $major; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var int $minor |
|
38 | - */ |
|
39 | - private $minor; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int $patch |
|
43 | - */ |
|
44 | - private $patch; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $release |
|
48 | - */ |
|
49 | - private $release; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var int $build |
|
53 | - */ |
|
54 | - private $build; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Version constructor. |
|
59 | - * |
|
60 | - * @param int $major |
|
61 | - * @param int $minor |
|
62 | - * @param int $patch |
|
63 | - * @param string $release |
|
64 | - * @param int $build |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidArgumentException |
|
67 | - */ |
|
68 | - public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
69 | - { |
|
70 | - $this->setMajor($major); |
|
71 | - $this->setMinor($minor); |
|
72 | - $this->setPatch($patch); |
|
73 | - $this->setRelease($release); |
|
74 | - $this->setBuild($build); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $version_string |
|
80 | - * @return Version |
|
81 | - * @throws InvalidArgumentException |
|
82 | - */ |
|
83 | - public static function fromString($version_string) |
|
84 | - { |
|
85 | - // compare incoming version string against the lowest possible valid version |
|
86 | - if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
87 | - throw new InvalidArgumentException( |
|
88 | - sprintf( |
|
89 | - esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
90 | - $version_string |
|
91 | - ) |
|
92 | - ); |
|
93 | - } |
|
94 | - // break apart incoming version string |
|
95 | - $version_parts = explode('.', $version_string); |
|
96 | - // verify that version string at least contains {major}.{minor}.{patch} |
|
97 | - if (count($version_parts) < 3) { |
|
98 | - throw new InvalidArgumentException( |
|
99 | - sprintf( |
|
100 | - esc_html__( |
|
101 | - 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - $version_string |
|
105 | - ) |
|
106 | - ); |
|
107 | - } |
|
108 | - // add defaults for missing pieces |
|
109 | - $version_parts += array(0,0,0,'p',0); |
|
110 | - // reassign to individual variables |
|
111 | - list($major, $minor, $patch, $release, $build) = $version_parts; |
|
112 | - return new Version( |
|
113 | - (int) $major, |
|
114 | - (int) $minor, |
|
115 | - (int) $patch, |
|
116 | - $release, |
|
117 | - (int) $build |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return int |
|
124 | - */ |
|
125 | - public function major() |
|
126 | - { |
|
127 | - return $this->major; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param int|string $major |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - */ |
|
135 | - private function setMajor($major) |
|
136 | - { |
|
137 | - if (! is_int($major)) { |
|
138 | - throw new InvalidDataTypeException( |
|
139 | - '$major', |
|
140 | - $major, |
|
141 | - 'integer' |
|
142 | - ); |
|
143 | - } |
|
144 | - $this->major = absint($major); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return int |
|
150 | - */ |
|
151 | - public function minor() |
|
152 | - { |
|
153 | - return $this->minor; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param int|string $minor |
|
159 | - * @throws InvalidDataTypeException |
|
160 | - */ |
|
161 | - private function setMinor($minor) |
|
162 | - { |
|
163 | - if (! is_int($minor)) { |
|
164 | - throw new InvalidDataTypeException( |
|
165 | - '$minor', |
|
166 | - $minor, |
|
167 | - 'integer' |
|
168 | - ); |
|
169 | - } |
|
170 | - $this->minor = absint($minor); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @return int |
|
176 | - */ |
|
177 | - public function patch() |
|
178 | - { |
|
179 | - return $this->patch; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param int|string $patch |
|
185 | - * @throws InvalidDataTypeException |
|
186 | - */ |
|
187 | - private function setPatch($patch) |
|
188 | - { |
|
189 | - if (! is_int($patch)) { |
|
190 | - throw new InvalidDataTypeException( |
|
191 | - '$patch', |
|
192 | - $patch, |
|
193 | - 'integer' |
|
194 | - ); |
|
195 | - } |
|
196 | - $this->patch = absint($patch); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function release() |
|
204 | - { |
|
205 | - return $this->release; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @param string $release |
|
211 | - * @throws InvalidArgumentException |
|
212 | - */ |
|
213 | - private function setRelease($release) |
|
214 | - { |
|
215 | - $valid_release_types = array( |
|
216 | - Version::RELEASE_TYPE_RC, |
|
217 | - Version::RELEASE_TYPE_BETA, |
|
218 | - Version::RELEASE_TYPE_DECAF, |
|
219 | - Version::RELEASE_TYPE_PROD, |
|
220 | - ); |
|
221 | - if (! in_array($release, $valid_release_types, true)) { |
|
222 | - throw new InvalidArgumentException( |
|
223 | - sprintf( |
|
224 | - esc_html__( |
|
225 | - '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
226 | - 'event_espresso' |
|
227 | - ), |
|
228 | - $release, |
|
229 | - implode(', ', $valid_release_types) |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $this->release = $release; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function build() |
|
241 | - { |
|
242 | - return $this->build; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param int|string $build |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - */ |
|
250 | - private function setBuild($build) |
|
251 | - { |
|
252 | - if (! is_int($build)) { |
|
253 | - throw new InvalidDataTypeException( |
|
254 | - '$build', |
|
255 | - $build, |
|
256 | - 'integer' |
|
257 | - ); |
|
258 | - } |
|
259 | - $this->build = absint($build); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @param Version $other_version |
|
265 | - * @return int |
|
266 | - */ |
|
267 | - public function compare(Version $other_version) |
|
268 | - { |
|
269 | - return version_compare((string) $this, (string) $other_version); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param Version $other_version |
|
275 | - * @return bool |
|
276 | - */ |
|
277 | - public function equals(Version $other_version) |
|
278 | - { |
|
279 | - return version_compare((string) $this, (string) $other_version, '=='); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param Version $other_version |
|
285 | - * @return bool |
|
286 | - */ |
|
287 | - public function newerThan(Version $other_version) |
|
288 | - { |
|
289 | - return version_compare((string) $this, (string) $other_version, '>'); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param Version $other_version |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function olderThan(Version $other_version) |
|
298 | - { |
|
299 | - return version_compare((string) $this, (string) $other_version, '<'); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return string |
|
305 | - */ |
|
306 | - public function __toString() |
|
307 | - { |
|
308 | - $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
309 | - if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
310 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
311 | - } |
|
312 | - return $version_string; |
|
313 | - } |
|
23 | + const RELEASE_TYPE_RC = 'rc'; |
|
24 | + |
|
25 | + const RELEASE_TYPE_BETA = 'beta'; |
|
26 | + |
|
27 | + const RELEASE_TYPE_DECAF = 'decaf'; |
|
28 | + |
|
29 | + const RELEASE_TYPE_PROD = 'p'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var int $major |
|
33 | + */ |
|
34 | + private $major; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var int $minor |
|
38 | + */ |
|
39 | + private $minor; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int $patch |
|
43 | + */ |
|
44 | + private $patch; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $release |
|
48 | + */ |
|
49 | + private $release; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var int $build |
|
53 | + */ |
|
54 | + private $build; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Version constructor. |
|
59 | + * |
|
60 | + * @param int $major |
|
61 | + * @param int $minor |
|
62 | + * @param int $patch |
|
63 | + * @param string $release |
|
64 | + * @param int $build |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidArgumentException |
|
67 | + */ |
|
68 | + public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
69 | + { |
|
70 | + $this->setMajor($major); |
|
71 | + $this->setMinor($minor); |
|
72 | + $this->setPatch($patch); |
|
73 | + $this->setRelease($release); |
|
74 | + $this->setBuild($build); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $version_string |
|
80 | + * @return Version |
|
81 | + * @throws InvalidArgumentException |
|
82 | + */ |
|
83 | + public static function fromString($version_string) |
|
84 | + { |
|
85 | + // compare incoming version string against the lowest possible valid version |
|
86 | + if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
87 | + throw new InvalidArgumentException( |
|
88 | + sprintf( |
|
89 | + esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
90 | + $version_string |
|
91 | + ) |
|
92 | + ); |
|
93 | + } |
|
94 | + // break apart incoming version string |
|
95 | + $version_parts = explode('.', $version_string); |
|
96 | + // verify that version string at least contains {major}.{minor}.{patch} |
|
97 | + if (count($version_parts) < 3) { |
|
98 | + throw new InvalidArgumentException( |
|
99 | + sprintf( |
|
100 | + esc_html__( |
|
101 | + 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + $version_string |
|
105 | + ) |
|
106 | + ); |
|
107 | + } |
|
108 | + // add defaults for missing pieces |
|
109 | + $version_parts += array(0,0,0,'p',0); |
|
110 | + // reassign to individual variables |
|
111 | + list($major, $minor, $patch, $release, $build) = $version_parts; |
|
112 | + return new Version( |
|
113 | + (int) $major, |
|
114 | + (int) $minor, |
|
115 | + (int) $patch, |
|
116 | + $release, |
|
117 | + (int) $build |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return int |
|
124 | + */ |
|
125 | + public function major() |
|
126 | + { |
|
127 | + return $this->major; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param int|string $major |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + */ |
|
135 | + private function setMajor($major) |
|
136 | + { |
|
137 | + if (! is_int($major)) { |
|
138 | + throw new InvalidDataTypeException( |
|
139 | + '$major', |
|
140 | + $major, |
|
141 | + 'integer' |
|
142 | + ); |
|
143 | + } |
|
144 | + $this->major = absint($major); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return int |
|
150 | + */ |
|
151 | + public function minor() |
|
152 | + { |
|
153 | + return $this->minor; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param int|string $minor |
|
159 | + * @throws InvalidDataTypeException |
|
160 | + */ |
|
161 | + private function setMinor($minor) |
|
162 | + { |
|
163 | + if (! is_int($minor)) { |
|
164 | + throw new InvalidDataTypeException( |
|
165 | + '$minor', |
|
166 | + $minor, |
|
167 | + 'integer' |
|
168 | + ); |
|
169 | + } |
|
170 | + $this->minor = absint($minor); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @return int |
|
176 | + */ |
|
177 | + public function patch() |
|
178 | + { |
|
179 | + return $this->patch; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param int|string $patch |
|
185 | + * @throws InvalidDataTypeException |
|
186 | + */ |
|
187 | + private function setPatch($patch) |
|
188 | + { |
|
189 | + if (! is_int($patch)) { |
|
190 | + throw new InvalidDataTypeException( |
|
191 | + '$patch', |
|
192 | + $patch, |
|
193 | + 'integer' |
|
194 | + ); |
|
195 | + } |
|
196 | + $this->patch = absint($patch); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function release() |
|
204 | + { |
|
205 | + return $this->release; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @param string $release |
|
211 | + * @throws InvalidArgumentException |
|
212 | + */ |
|
213 | + private function setRelease($release) |
|
214 | + { |
|
215 | + $valid_release_types = array( |
|
216 | + Version::RELEASE_TYPE_RC, |
|
217 | + Version::RELEASE_TYPE_BETA, |
|
218 | + Version::RELEASE_TYPE_DECAF, |
|
219 | + Version::RELEASE_TYPE_PROD, |
|
220 | + ); |
|
221 | + if (! in_array($release, $valid_release_types, true)) { |
|
222 | + throw new InvalidArgumentException( |
|
223 | + sprintf( |
|
224 | + esc_html__( |
|
225 | + '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
226 | + 'event_espresso' |
|
227 | + ), |
|
228 | + $release, |
|
229 | + implode(', ', $valid_release_types) |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $this->release = $release; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function build() |
|
241 | + { |
|
242 | + return $this->build; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param int|string $build |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + */ |
|
250 | + private function setBuild($build) |
|
251 | + { |
|
252 | + if (! is_int($build)) { |
|
253 | + throw new InvalidDataTypeException( |
|
254 | + '$build', |
|
255 | + $build, |
|
256 | + 'integer' |
|
257 | + ); |
|
258 | + } |
|
259 | + $this->build = absint($build); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @param Version $other_version |
|
265 | + * @return int |
|
266 | + */ |
|
267 | + public function compare(Version $other_version) |
|
268 | + { |
|
269 | + return version_compare((string) $this, (string) $other_version); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param Version $other_version |
|
275 | + * @return bool |
|
276 | + */ |
|
277 | + public function equals(Version $other_version) |
|
278 | + { |
|
279 | + return version_compare((string) $this, (string) $other_version, '=='); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param Version $other_version |
|
285 | + * @return bool |
|
286 | + */ |
|
287 | + public function newerThan(Version $other_version) |
|
288 | + { |
|
289 | + return version_compare((string) $this, (string) $other_version, '>'); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param Version $other_version |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function olderThan(Version $other_version) |
|
298 | + { |
|
299 | + return version_compare((string) $this, (string) $other_version, '<'); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + public function __toString() |
|
307 | + { |
|
308 | + $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
309 | + if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
310 | + $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
311 | + } |
|
312 | + return $version_string; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | |
316 | 316 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | // add defaults for missing pieces |
109 | - $version_parts += array(0,0,0,'p',0); |
|
109 | + $version_parts += array(0, 0, 0, 'p', 0); |
|
110 | 110 | // reassign to individual variables |
111 | 111 | list($major, $minor, $patch, $release, $build) = $version_parts; |
112 | 112 | return new Version( |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private function setMajor($major) |
136 | 136 | { |
137 | - if (! is_int($major)) { |
|
137 | + if ( ! is_int($major)) { |
|
138 | 138 | throw new InvalidDataTypeException( |
139 | 139 | '$major', |
140 | 140 | $major, |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | private function setMinor($minor) |
162 | 162 | { |
163 | - if (! is_int($minor)) { |
|
163 | + if ( ! is_int($minor)) { |
|
164 | 164 | throw new InvalidDataTypeException( |
165 | 165 | '$minor', |
166 | 166 | $minor, |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function setPatch($patch) |
188 | 188 | { |
189 | - if (! is_int($patch)) { |
|
189 | + if ( ! is_int($patch)) { |
|
190 | 190 | throw new InvalidDataTypeException( |
191 | 191 | '$patch', |
192 | 192 | $patch, |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | Version::RELEASE_TYPE_DECAF, |
219 | 219 | Version::RELEASE_TYPE_PROD, |
220 | 220 | ); |
221 | - if (! in_array($release, $valid_release_types, true)) { |
|
221 | + if ( ! in_array($release, $valid_release_types, true)) { |
|
222 | 222 | throw new InvalidArgumentException( |
223 | 223 | sprintf( |
224 | 224 | esc_html__( |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | private function setBuild($build) |
251 | 251 | { |
252 | - if (! is_int($build)) { |
|
252 | + if ( ! is_int($build)) { |
|
253 | 253 | throw new InvalidDataTypeException( |
254 | 254 | '$build', |
255 | 255 | $build, |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | public function __toString() |
307 | 307 | { |
308 | 308 | $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
309 | - if($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
310 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
309 | + if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
310 | + $version_string .= '.'.str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
311 | 311 | } |
312 | 312 | return $version_string; |
313 | 313 | } |