Completed
Branch BUG-11108-ticket-reserved-coun... (144d27)
by
unknown
14:21 queued 17s
created
form_sections/strategies/display/EE_Display_Strategy_Base.strategy.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,237 +16,237 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var string $_tag
21
-     */
22
-    protected $_tag = '';
19
+	/**
20
+	 * @var string $_tag
21
+	 */
22
+	protected $_tag = '';
23 23
 
24 24
 
25 25
 
26 26
 
27 27
 
28
-    /**
29
-     * returns HTML and javascript related to the displaying of this input
30
-     *
31
-     * @return string
32
-     */
33
-    abstract public function display();
28
+	/**
29
+	 * returns HTML and javascript related to the displaying of this input
30
+	 *
31
+	 * @return string
32
+	 */
33
+	abstract public function display();
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
39
-     * is already there
40
-     *
41
-     * @param string $string - the string being processed
42
-     * @param string $chars  - exact string of characters to remove
43
-     * @return string
44
-     */
45
-    protected function _remove_chars($string = '', $chars = '-')
46
-    {
47
-        $char_length = strlen($chars) * -1;
48
-        // if last three characters of string is  " - ", then remove it
49
-        return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string;
50
-    }
37
+	/**
38
+	 * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
39
+	 * is already there
40
+	 *
41
+	 * @param string $string - the string being processed
42
+	 * @param string $chars  - exact string of characters to remove
43
+	 * @return string
44
+	 */
45
+	protected function _remove_chars($string = '', $chars = '-')
46
+	{
47
+		$char_length = strlen($chars) * -1;
48
+		// if last three characters of string is  " - ", then remove it
49
+		return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string;
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
56
-     * already there
57
-     *
58
-     * @param string $string - the string being processed
59
-     * @param string $chars  - exact string of characters to be added to end of string
60
-     * @return string
61
-     */
62
-    protected function _append_chars($string = '', $chars = '-')
63
-    {
64
-        return $this->_remove_chars($string, $chars) . $chars;
65
-    }
54
+	/**
55
+	 * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
56
+	 * already there
57
+	 *
58
+	 * @param string $string - the string being processed
59
+	 * @param string $chars  - exact string of characters to be added to end of string
60
+	 * @return string
61
+	 */
62
+	protected function _append_chars($string = '', $chars = '-')
63
+	{
64
+		return $this->_remove_chars($string, $chars) . $chars;
65
+	}
66 66
 
67 67
 
68
-
69
-    /**
70
-     * Gets the HTML IDs of all the inputs
71
-     *
72
-     * @param bool $add_pound_sign
73
-     * @return array
74
-     */
75
-    public function get_html_input_ids($add_pound_sign = false)
76
-    {
77
-        return array($this->get_input()->html_id($add_pound_sign));
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * Adds js variables for localization to the $other_js_data. These should be put
84
-     * in each form's "other_data" javascript object.
85
-     *
86
-     * @param array $other_js_data
87
-     * @return array
88
-     */
89
-    public function get_other_js_data($other_js_data = array())
90
-    {
91
-        return $other_js_data;
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
98
-     * This should be called during wp_enqueue_scripts
99
-     */
100
-    public function enqueue_js()
101
-    {
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * returns string like: '<tag'
108
-     *
109
-     * @param string $tag
110
-     * @return string
111
-     */
112
-    protected function _opening_tag($tag)
113
-    {
114
-        $this->_tag = $tag;
115
-        return "<{$this->_tag}";
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * returns string like: '</tag>
122
-     *
123
-     * @return string
124
-     */
125
-    protected function _closing_tag()
126
-    {
127
-        return "</{$this->_tag}>";
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * returns string like: '/>'
134
-     *
135
-     * @return string
136
-     */
137
-    protected function _close_tag()
138
-    {
139
-        return '/>';
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * returns an array of standard HTML attributes that get added to nearly all inputs,
146
-     * where string keys represent named attributes like id, class, etc
147
-     * and numeric keys represent single attributes like 'required'.
148
-     * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
149
-     * it.
150
-     *
151
-     * @return array
152
-     */
153
-    protected function _standard_attributes_array()
154
-    {
155
-        return array(
156
-            'name'  => $this->_input->html_name(),
157
-            'id'    => $this->_input->html_id(),
158
-            'class' => $this->_input->html_class(true),
159
-            0       => array('required', $this->_input->required()),
160
-            1       => $this->_input->other_html_attributes(),
161
-            'style' => $this->_input->html_style(),
162
-        );
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * sets the attributes using the incoming array
169
-     * and returns a string of all attributes rendered as valid HTML
170
-     *
171
-     * @param array $attributes
172
-     * @return string
173
-     */
174
-    protected function _attributes_string($attributes = array())
175
-    {
176
-        $attributes = apply_filters(
177
-            'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
178
-            $attributes,
179
-            $this,
180
-            $this->_input
181
-        );
182
-        $attributes_string = '';
183
-        foreach ($attributes as $attribute => $value) {
184
-            if (is_numeric($attribute)) {
185
-                $add = true;
186
-                if (is_array($value)) {
187
-                    $attribute = isset($value[0]) ? $value[0] : '';
188
-                    $add = isset($value[1]) ? $value[1] : false;
189
-                } else {
190
-                    $attribute = $value;
191
-                }
192
-                $attributes_string .= $this->_single_attribute($attribute, $add);
193
-            } else {
194
-                $attributes_string .= $this->_attribute($attribute, $value);
195
-            }
196
-        }
197
-        return $attributes_string;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * returns string like: ' attribute="value"'
204
-     * returns an empty string if $value is null
205
-     *
206
-     * @param string $attribute
207
-     * @param string $value
208
-     * @return string
209
-     */
210
-    protected function _attribute($attribute, $value = '')
211
-    {
212
-        if( $value === null) {
213
-            return '';
214
-        }
215
-        $value = esc_attr($value);
216
-        return " {$attribute}=\"{$value}\"";
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * returns string like: ' data-attribute="value"'
223
-     * returns an empty string if $value is null
224
-     *
225
-     * @param string $attribute
226
-     * @param string $value
227
-     * @return string
228
-     */
229
-    protected function _data_attribute($attribute, $value = '')
230
-    {
231
-        if( $value === null) {
232
-            return '';
233
-        }
234
-        $value = esc_attr($value);
235
-        return " data-{$attribute}=\"{$value}\"";
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * returns string like: ' attribute' if $add is true
242
-     *
243
-     * @param string  $attribute
244
-     * @param boolean $add
245
-     * @return string
246
-     */
247
-    protected function _single_attribute($attribute, $add = true)
248
-    {
249
-        return $add ? " {$attribute}" : '';
250
-    }
68
+
69
+	/**
70
+	 * Gets the HTML IDs of all the inputs
71
+	 *
72
+	 * @param bool $add_pound_sign
73
+	 * @return array
74
+	 */
75
+	public function get_html_input_ids($add_pound_sign = false)
76
+	{
77
+		return array($this->get_input()->html_id($add_pound_sign));
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * Adds js variables for localization to the $other_js_data. These should be put
84
+	 * in each form's "other_data" javascript object.
85
+	 *
86
+	 * @param array $other_js_data
87
+	 * @return array
88
+	 */
89
+	public function get_other_js_data($other_js_data = array())
90
+	{
91
+		return $other_js_data;
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
98
+	 * This should be called during wp_enqueue_scripts
99
+	 */
100
+	public function enqueue_js()
101
+	{
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * returns string like: '<tag'
108
+	 *
109
+	 * @param string $tag
110
+	 * @return string
111
+	 */
112
+	protected function _opening_tag($tag)
113
+	{
114
+		$this->_tag = $tag;
115
+		return "<{$this->_tag}";
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * returns string like: '</tag>
122
+	 *
123
+	 * @return string
124
+	 */
125
+	protected function _closing_tag()
126
+	{
127
+		return "</{$this->_tag}>";
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * returns string like: '/>'
134
+	 *
135
+	 * @return string
136
+	 */
137
+	protected function _close_tag()
138
+	{
139
+		return '/>';
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * returns an array of standard HTML attributes that get added to nearly all inputs,
146
+	 * where string keys represent named attributes like id, class, etc
147
+	 * and numeric keys represent single attributes like 'required'.
148
+	 * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
149
+	 * it.
150
+	 *
151
+	 * @return array
152
+	 */
153
+	protected function _standard_attributes_array()
154
+	{
155
+		return array(
156
+			'name'  => $this->_input->html_name(),
157
+			'id'    => $this->_input->html_id(),
158
+			'class' => $this->_input->html_class(true),
159
+			0       => array('required', $this->_input->required()),
160
+			1       => $this->_input->other_html_attributes(),
161
+			'style' => $this->_input->html_style(),
162
+		);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * sets the attributes using the incoming array
169
+	 * and returns a string of all attributes rendered as valid HTML
170
+	 *
171
+	 * @param array $attributes
172
+	 * @return string
173
+	 */
174
+	protected function _attributes_string($attributes = array())
175
+	{
176
+		$attributes = apply_filters(
177
+			'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
178
+			$attributes,
179
+			$this,
180
+			$this->_input
181
+		);
182
+		$attributes_string = '';
183
+		foreach ($attributes as $attribute => $value) {
184
+			if (is_numeric($attribute)) {
185
+				$add = true;
186
+				if (is_array($value)) {
187
+					$attribute = isset($value[0]) ? $value[0] : '';
188
+					$add = isset($value[1]) ? $value[1] : false;
189
+				} else {
190
+					$attribute = $value;
191
+				}
192
+				$attributes_string .= $this->_single_attribute($attribute, $add);
193
+			} else {
194
+				$attributes_string .= $this->_attribute($attribute, $value);
195
+			}
196
+		}
197
+		return $attributes_string;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * returns string like: ' attribute="value"'
204
+	 * returns an empty string if $value is null
205
+	 *
206
+	 * @param string $attribute
207
+	 * @param string $value
208
+	 * @return string
209
+	 */
210
+	protected function _attribute($attribute, $value = '')
211
+	{
212
+		if( $value === null) {
213
+			return '';
214
+		}
215
+		$value = esc_attr($value);
216
+		return " {$attribute}=\"{$value}\"";
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * returns string like: ' data-attribute="value"'
223
+	 * returns an empty string if $value is null
224
+	 *
225
+	 * @param string $attribute
226
+	 * @param string $value
227
+	 * @return string
228
+	 */
229
+	protected function _data_attribute($attribute, $value = '')
230
+	{
231
+		if( $value === null) {
232
+			return '';
233
+		}
234
+		$value = esc_attr($value);
235
+		return " data-{$attribute}=\"{$value}\"";
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * returns string like: ' attribute' if $add is true
242
+	 *
243
+	 * @param string  $attribute
244
+	 * @param boolean $add
245
+	 * @return string
246
+	 */
247
+	protected function _single_attribute($attribute, $add = true)
248
+	{
249
+		return $add ? " {$attribute}" : '';
250
+	}
251 251
 
252 252
 }
253 253
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     protected function _append_chars($string = '', $chars = '-')
63 63
     {
64
-        return $this->_remove_chars($string, $chars) . $chars;
64
+        return $this->_remove_chars($string, $chars).$chars;
65 65
     }
66 66
 
67 67
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      */
210 210
     protected function _attribute($attribute, $value = '')
211 211
     {
212
-        if( $value === null) {
212
+        if ($value === null) {
213 213
             return '';
214 214
         }
215 215
         $value = esc_attr($value);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     protected function _data_attribute($attribute, $value = '')
230 230
     {
231
-        if( $value === null) {
231
+        if ($value === null) {
232 232
             return '';
233 233
         }
234 234
         $value = esc_attr($value);
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Button_Display_Strategy.strategy.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -12,32 +12,32 @@
 block discarded – undo
12 12
 class EE_Button_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @return string of html to display the input
17
-     */
18
-    public function display()
19
-    {
20
-        $default_value = $this->_input->get_default();
21
-        if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
-            $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
-        }
24
-        $html = $this->_opening_tag('button');
25
-        $html .= $this->_attributes_string(
26
-            array_merge(
27
-                $this->_standard_attributes_array(),
28
-                array(
29
-                    'value' => $default_value,
30
-                )
31
-            )
32
-        );
33
-        if ($this->_input instanceof EE_Button_Input) {
34
-            $button_content = $this->_input->button_content();
35
-        } else {
36
-            $button_content = $this->_input->get_default();
37
-        }
38
-        $html .= '>';
39
-        $html .= $button_content;
40
-        $html .= $this->_closing_tag();
41
-        return $html;
42
-    }
15
+	/**
16
+	 * @return string of html to display the input
17
+	 */
18
+	public function display()
19
+	{
20
+		$default_value = $this->_input->get_default();
21
+		if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
+			$default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
+		}
24
+		$html = $this->_opening_tag('button');
25
+		$html .= $this->_attributes_string(
26
+			array_merge(
27
+				$this->_standard_attributes_array(),
28
+				array(
29
+					'value' => $default_value,
30
+				)
31
+			)
32
+		);
33
+		if ($this->_input instanceof EE_Button_Input) {
34
+			$button_content = $this->_input->button_content();
35
+		} else {
36
+			$button_content = $this->_input->get_default();
37
+		}
38
+		$html .= '>';
39
+		$html .= $button_content;
40
+		$html .= $this->_closing_tag();
41
+		return $html;
42
+	}
43 43
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Button_Input.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class EE_Button_Input extends EE_Form_Input_Base{
12 12
 
13
-    /**
14
-     * @var string of HTML to put between the button tags
15
-     */
16
-    protected $_button_content;
13
+	/**
14
+	 * @var string of HTML to put between the button tags
15
+	 */
16
+	protected $_button_content;
17 17
 	/**
18 18
 	 * @param array $options
19 19
 	 */
20 20
 	public function __construct($options = array()){
21
-	    if( empty($options['button_content'])) {
22
-	        $options['button_content'] = esc_html__('Button', 'event_espresso');
23
-        }
21
+		if( empty($options['button_content'])) {
22
+			$options['button_content'] = esc_html__('Button', 'event_espresso');
23
+		}
24 24
 		$this->_set_display_strategy(new EE_Button_Display_Strategy());
25 25
 		$this->_set_normalization_strategy(new EE_Text_Normalization());
26 26
 		$this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() );
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Sets the button content
34
-     * @see EE_Button_Input::$_button_content
35
-     * @param string $new_content
36
-     */
32
+	/**
33
+	 * Sets the button content
34
+	 * @see EE_Button_Input::$_button_content
35
+	 * @param string $new_content
36
+	 */
37 37
 	public function set_button_content($new_content)
38
-    {
39
-	    $this->_button_content = $new_content;
40
-    }
38
+	{
39
+		$this->_button_content = $new_content;
40
+	}
41 41
     
42
-    /**
43
-     * Gets the button content
44
-     * @return string
45
-     */
42
+	/**
43
+	 * Gets the button content
44
+	 * @return string
45
+	 */
46 46
 	public function button_content()
47
-    {
48
-        return $this->_button_content;
49
-    }
47
+	{
48
+		return $this->_button_content;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @author				Mike Nelson
9 9
  *
10 10
  */
11
-class EE_Button_Input extends EE_Form_Input_Base{
11
+class EE_Button_Input extends EE_Form_Input_Base {
12 12
 
13 13
     /**
14 14
      * @var string of HTML to put between the button tags
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 	/**
18 18
 	 * @param array $options
19 19
 	 */
20
-	public function __construct($options = array()){
21
-	    if( empty($options['button_content'])) {
20
+	public function __construct($options = array()) {
21
+	    if (empty($options['button_content'])) {
22 22
 	        $options['button_content'] = esc_html__('Button', 'event_espresso');
23 23
         }
24 24
 		$this->_set_display_strategy(new EE_Button_Display_Strategy());
25 25
 		$this->_set_normalization_strategy(new EE_Text_Normalization());
26
-		$this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() );
26
+		$this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
27 27
 		parent::__construct($options);
28 28
 	}
29 29
 
Please login to merge, or discard this patch.
core/domain/RequiresRegistryInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@
 block discarded – undo
19 19
 interface RequiresRegistryInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @param EE_Registry $registry
24
-     */
25
-    public function setRegistry($registry);
22
+	/**
23
+	 * @param EE_Registry $registry
24
+	 */
25
+	public function setRegistry($registry);
26 26
 
27 27
 }
28 28
 // Location: requiresRegistry.php
Please login to merge, or discard this patch.
core/domain/DomainInterface.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -15,36 +15,36 @@
 block discarded – undo
15 15
 interface DomainInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @return string
20
-     * @throws DomainException
21
-     */
22
-    public function pluginFile();
18
+	/**
19
+	 * @return string
20
+	 * @throws DomainException
21
+	 */
22
+	public function pluginFile();
23 23
 
24 24
 
25
-    /**
26
-     * @return string
27
-     * @throws DomainException
28
-     */
29
-    public function pluginBasename();
25
+	/**
26
+	 * @return string
27
+	 * @throws DomainException
28
+	 */
29
+	public function pluginBasename();
30 30
 
31 31
 
32
-    /**
33
-     * @return string
34
-     */
35
-    public function pluginPath();
32
+	/**
33
+	 * @return string
34
+	 */
35
+	public function pluginPath();
36 36
 
37 37
 
38
-    /**
39
-     * @return string
40
-     * @throws DomainException
41
-     */
42
-    public function pluginUrl();
38
+	/**
39
+	 * @return string
40
+	 * @throws DomainException
41
+	 */
42
+	public function pluginUrl();
43 43
 
44 44
 
45
-    /**
46
-     * @return string
47
-     * @throws DomainException
48
-     */
49
-    public function version();
45
+	/**
46
+	 * @return string
47
+	 * @throws DomainException
48
+	 */
49
+	public function version();
50 50
 }
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Indentation   +416 added lines, -416 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
8 8
 
@@ -23,421 +23,421 @@  discard block
 block discarded – undo
23 23
 class EE_Cart implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * instance of the EE_Cart object
28
-     *
29
-     * @access    private
30
-     * @var EE_Cart $_instance
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * instance of the EE_Session object
36
-     *
37
-     * @access    protected
38
-     * @var EE_Session $_session
39
-     */
40
-    protected $_session;
41
-
42
-    /**
43
-     * The total Line item which comprises all the children line-item subtotals,
44
-     * which in turn each have their line items.
45
-     * Typically, the line item structure will look like:
46
-     * grand total
47
-     * -tickets-sub-total
48
-     * --ticket1
49
-     * --ticket2
50
-     * --...
51
-     * -taxes-sub-total
52
-     * --tax1
53
-     * --tax2
54
-     *
55
-     * @var EE_Line_Item
56
-     */
57
-    private $_grand_total;
58
-
59
-
60
-
61
-    /**
62
-     * @singleton method used to instantiate class object
63
-     * @access    public
64
-     * @param EE_Line_Item $grand_total
65
-     * @param EE_Session   $session
66
-     * @return \EE_Cart
67
-     * @throws \EE_Error
68
-     */
69
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
-    {
71
-        if ( ! empty($grand_total)) {
72
-            self::$_instance = new self($grand_total, $session);
73
-        }
74
-        // or maybe retrieve an existing one ?
75
-        if ( ! self::$_instance instanceof EE_Cart) {
76
-            // try getting the cart out of the session
77
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
-            unset($saved_cart);
80
-        }
81
-        // verify that cart is ok and grand total line item exists
82
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
-            self::$_instance = new self($grand_total, $session);
84
-        }
85
-        self::$_instance->get_grand_total();
86
-        // once everything is all said and done, save the cart to the EE_Session
87
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
-        return self::$_instance;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * private constructor to prevent direct creation
95
-     *
96
-     * @Constructor
97
-     * @access private
98
-     * @param EE_Line_Item $grand_total
99
-     * @param EE_Session   $session
100
-     */
101
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
-    {
103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
-        $this->set_session($session);
105
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
106
-            $this->set_grand_total_line_item($grand_total);
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Resets the cart completely (whereas empty_cart
114
-     *
115
-     * @param EE_Line_Item $grand_total
116
-     * @param EE_Session   $session
117
-     * @return EE_Cart
118
-     * @throws \EE_Error
119
-     */
120
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
-    {
122
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
-        if ($session instanceof EE_Session) {
124
-            $session->reset_cart();
125
-        }
126
-        self::$_instance = null;
127
-        return self::instance($grand_total, $session);
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return \EE_Session
134
-     */
135
-    public function session()
136
-    {
137
-        if ( ! $this->_session instanceof EE_Session) {
138
-            $this->set_session();
139
-        }
140
-        return $this->_session;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param EE_Session $session
147
-     */
148
-    public function set_session(EE_Session $session = null)
149
-    {
150
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
-     *  know the grand total line item on it
158
-     *
159
-     * @param EE_Line_Item $line_item
160
-     */
161
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
162
-    {
163
-        $this->_grand_total = $line_item;
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * get_cart_from_reg_url_link
170
-     *
171
-     * @access public
172
-     * @param EE_Transaction $transaction
173
-     * @param EE_Session     $session
174
-     * @return \EE_Cart
175
-     * @throws \EE_Error
176
-     */
177
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
-    {
179
-        $grand_total = $transaction->total_line_item();
180
-        $grand_total->get_items();
181
-        $grand_total->tax_descendants();
182
-        return EE_Cart::instance($grand_total, $session);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
-     *
190
-     * @return EE_Line_Item
191
-     * @throws \EE_Error
192
-     */
193
-    private function _create_grand_total()
194
-    {
195
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
196
-        return $this->_grand_total;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Gets all the line items of object type Ticket
203
-     *
204
-     * @access public
205
-     * @return \EE_Line_Item[]
206
-     */
207
-    public function get_tickets()
208
-    {
209
-        if ($this->_grand_total === null ) {
210
-            return array();
211
-        }
212
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns the total quantity of tickets in the cart
219
-     *
220
-     * @access public
221
-     * @return int
222
-     * @throws \EE_Error
223
-     */
224
-    public function all_ticket_quantity_count()
225
-    {
226
-        $tickets = $this->get_tickets();
227
-        if (empty($tickets)) {
228
-            return 0;
229
-        }
230
-        $count = 0;
231
-        foreach ($tickets as $ticket) {
232
-            $count += $ticket->get('LIN_quantity');
233
-        }
234
-        return $count;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets all the tax line items
241
-     *
242
-     * @return \EE_Line_Item[]
243
-     * @throws \EE_Error
244
-     */
245
-    public function get_taxes()
246
-    {
247
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Gets the total line item (which is a parent of all other line items) on this cart
254
-     *
255
-     * @return EE_Line_Item
256
-     * @throws \EE_Error
257
-     */
258
-    public function get_grand_total()
259
-    {
260
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @process items for adding to cart
267
-     * @access  public
268
-     * @param EE_Ticket $ticket
269
-     * @param int       $qty
270
-     * @return TRUE on success, FALSE on fail
271
-     * @throws \EE_Error
272
-     */
273
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
-    {
275
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
-        return $this->save_cart() ? true : false;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * get_cart_total_before_tax
283
-     *
284
-     * @access public
285
-     * @return float
286
-     * @throws \EE_Error
287
-     */
288
-    public function get_cart_total_before_tax()
289
-    {
290
-        return $this->get_grand_total()->recalculate_pre_tax_total();
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * gets the total amount of tax paid for items in this cart
297
-     *
298
-     * @access public
299
-     * @return float
300
-     * @throws \EE_Error
301
-     */
302
-    public function get_applied_taxes()
303
-    {
304
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
-     *
312
-     * @access public
313
-     * @return float
314
-     * @throws \EE_Error
315
-     */
316
-    public function get_cart_grand_total()
317
-    {
318
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
-        return $this->get_grand_total()->total();
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
-     *
327
-     * @access public
328
-     * @return float
329
-     * @throws \EE_Error
330
-     */
331
-    public function recalculate_all_cart_totals()
332
-    {
333
-        $pre_tax_total = $this->get_cart_total_before_tax();
334
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
-        $this->_grand_total->save_this_and_descendants_to_txn();
337
-        return $this->get_grand_total()->total();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * deletes an item from the cart
344
-     *
345
-     * @access public
346
-     * @param array|bool|string $line_item_codes
347
-     * @return int on success, FALSE on fail
348
-     * @throws \EE_Error
349
-     */
350
-    public function delete_items($line_item_codes = false)
351
-    {
352
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @remove ALL items from cart and zero ALL totals
360
-     * @access public
361
-     * @return bool
362
-     * @throws \EE_Error
363
-     */
364
-    public function empty_cart()
365
-    {
366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
-        $this->_grand_total = $this->_create_grand_total();
368
-        return $this->save_cart(true);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @remove ALL items from cart and delete total as well
375
-     * @access public
376
-     * @return bool
377
-     * @throws \EE_Error
378
-     */
379
-    public function delete_cart()
380
-    {
381
-        if ($this->_grand_total instanceof EE_Line_Item) {
382
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
383
-            if ($deleted) {
384
-                $deleted += $this->_grand_total->delete();
385
-                $this->_grand_total = null;
386
-                return true;
387
-            }
388
-        }
389
-        return false;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * @save   cart to session
396
-     * @access public
397
-     * @param bool $apply_taxes
398
-     * @return TRUE on success, FALSE on fail
399
-     * @throws \EE_Error
400
-     */
401
-    public function save_cart($apply_taxes = true)
402
-    {
403
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
404
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
405
-            //make sure we don't cache the transaction because it can get stale
406
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
407
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
408
-            ) {
409
-                $this->_grand_total->clear_cache('Transaction', null, true);
410
-            }
411
-        }
412
-        if ($this->session() instanceof EE_Session) {
413
-            return $this->session()->set_cart($this);
414
-        } else {
415
-            return false;
416
-        }
417
-    }
418
-
419
-
420
-
421
-    public function __wakeup()
422
-    {
423
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
424
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
425
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
426
-        }
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @return array
433
-     */
434
-    public function __sleep()
435
-    {
436
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
437
-            $this->_grand_total = $this->_grand_total->ID();
438
-        }
439
-        return array('_grand_total');
440
-    }
26
+	/**
27
+	 * instance of the EE_Cart object
28
+	 *
29
+	 * @access    private
30
+	 * @var EE_Cart $_instance
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * instance of the EE_Session object
36
+	 *
37
+	 * @access    protected
38
+	 * @var EE_Session $_session
39
+	 */
40
+	protected $_session;
41
+
42
+	/**
43
+	 * The total Line item which comprises all the children line-item subtotals,
44
+	 * which in turn each have their line items.
45
+	 * Typically, the line item structure will look like:
46
+	 * grand total
47
+	 * -tickets-sub-total
48
+	 * --ticket1
49
+	 * --ticket2
50
+	 * --...
51
+	 * -taxes-sub-total
52
+	 * --tax1
53
+	 * --tax2
54
+	 *
55
+	 * @var EE_Line_Item
56
+	 */
57
+	private $_grand_total;
58
+
59
+
60
+
61
+	/**
62
+	 * @singleton method used to instantiate class object
63
+	 * @access    public
64
+	 * @param EE_Line_Item $grand_total
65
+	 * @param EE_Session   $session
66
+	 * @return \EE_Cart
67
+	 * @throws \EE_Error
68
+	 */
69
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
+	{
71
+		if ( ! empty($grand_total)) {
72
+			self::$_instance = new self($grand_total, $session);
73
+		}
74
+		// or maybe retrieve an existing one ?
75
+		if ( ! self::$_instance instanceof EE_Cart) {
76
+			// try getting the cart out of the session
77
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
+			unset($saved_cart);
80
+		}
81
+		// verify that cart is ok and grand total line item exists
82
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
+			self::$_instance = new self($grand_total, $session);
84
+		}
85
+		self::$_instance->get_grand_total();
86
+		// once everything is all said and done, save the cart to the EE_Session
87
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
+		return self::$_instance;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * private constructor to prevent direct creation
95
+	 *
96
+	 * @Constructor
97
+	 * @access private
98
+	 * @param EE_Line_Item $grand_total
99
+	 * @param EE_Session   $session
100
+	 */
101
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
+	{
103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
+		$this->set_session($session);
105
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
106
+			$this->set_grand_total_line_item($grand_total);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Resets the cart completely (whereas empty_cart
114
+	 *
115
+	 * @param EE_Line_Item $grand_total
116
+	 * @param EE_Session   $session
117
+	 * @return EE_Cart
118
+	 * @throws \EE_Error
119
+	 */
120
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
+	{
122
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
+		if ($session instanceof EE_Session) {
124
+			$session->reset_cart();
125
+		}
126
+		self::$_instance = null;
127
+		return self::instance($grand_total, $session);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return \EE_Session
134
+	 */
135
+	public function session()
136
+	{
137
+		if ( ! $this->_session instanceof EE_Session) {
138
+			$this->set_session();
139
+		}
140
+		return $this->_session;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param EE_Session $session
147
+	 */
148
+	public function set_session(EE_Session $session = null)
149
+	{
150
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
+	 *  know the grand total line item on it
158
+	 *
159
+	 * @param EE_Line_Item $line_item
160
+	 */
161
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
162
+	{
163
+		$this->_grand_total = $line_item;
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * get_cart_from_reg_url_link
170
+	 *
171
+	 * @access public
172
+	 * @param EE_Transaction $transaction
173
+	 * @param EE_Session     $session
174
+	 * @return \EE_Cart
175
+	 * @throws \EE_Error
176
+	 */
177
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
+	{
179
+		$grand_total = $transaction->total_line_item();
180
+		$grand_total->get_items();
181
+		$grand_total->tax_descendants();
182
+		return EE_Cart::instance($grand_total, $session);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
+	 *
190
+	 * @return EE_Line_Item
191
+	 * @throws \EE_Error
192
+	 */
193
+	private function _create_grand_total()
194
+	{
195
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
196
+		return $this->_grand_total;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Gets all the line items of object type Ticket
203
+	 *
204
+	 * @access public
205
+	 * @return \EE_Line_Item[]
206
+	 */
207
+	public function get_tickets()
208
+	{
209
+		if ($this->_grand_total === null ) {
210
+			return array();
211
+		}
212
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns the total quantity of tickets in the cart
219
+	 *
220
+	 * @access public
221
+	 * @return int
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function all_ticket_quantity_count()
225
+	{
226
+		$tickets = $this->get_tickets();
227
+		if (empty($tickets)) {
228
+			return 0;
229
+		}
230
+		$count = 0;
231
+		foreach ($tickets as $ticket) {
232
+			$count += $ticket->get('LIN_quantity');
233
+		}
234
+		return $count;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets all the tax line items
241
+	 *
242
+	 * @return \EE_Line_Item[]
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function get_taxes()
246
+	{
247
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Gets the total line item (which is a parent of all other line items) on this cart
254
+	 *
255
+	 * @return EE_Line_Item
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function get_grand_total()
259
+	{
260
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @process items for adding to cart
267
+	 * @access  public
268
+	 * @param EE_Ticket $ticket
269
+	 * @param int       $qty
270
+	 * @return TRUE on success, FALSE on fail
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
+	{
275
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
+		return $this->save_cart() ? true : false;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * get_cart_total_before_tax
283
+	 *
284
+	 * @access public
285
+	 * @return float
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function get_cart_total_before_tax()
289
+	{
290
+		return $this->get_grand_total()->recalculate_pre_tax_total();
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * gets the total amount of tax paid for items in this cart
297
+	 *
298
+	 * @access public
299
+	 * @return float
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function get_applied_taxes()
303
+	{
304
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
+	 *
312
+	 * @access public
313
+	 * @return float
314
+	 * @throws \EE_Error
315
+	 */
316
+	public function get_cart_grand_total()
317
+	{
318
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
+		return $this->get_grand_total()->total();
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
+	 *
327
+	 * @access public
328
+	 * @return float
329
+	 * @throws \EE_Error
330
+	 */
331
+	public function recalculate_all_cart_totals()
332
+	{
333
+		$pre_tax_total = $this->get_cart_total_before_tax();
334
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
+		$this->_grand_total->save_this_and_descendants_to_txn();
337
+		return $this->get_grand_total()->total();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * deletes an item from the cart
344
+	 *
345
+	 * @access public
346
+	 * @param array|bool|string $line_item_codes
347
+	 * @return int on success, FALSE on fail
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function delete_items($line_item_codes = false)
351
+	{
352
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @remove ALL items from cart and zero ALL totals
360
+	 * @access public
361
+	 * @return bool
362
+	 * @throws \EE_Error
363
+	 */
364
+	public function empty_cart()
365
+	{
366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
+		$this->_grand_total = $this->_create_grand_total();
368
+		return $this->save_cart(true);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @remove ALL items from cart and delete total as well
375
+	 * @access public
376
+	 * @return bool
377
+	 * @throws \EE_Error
378
+	 */
379
+	public function delete_cart()
380
+	{
381
+		if ($this->_grand_total instanceof EE_Line_Item) {
382
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
383
+			if ($deleted) {
384
+				$deleted += $this->_grand_total->delete();
385
+				$this->_grand_total = null;
386
+				return true;
387
+			}
388
+		}
389
+		return false;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * @save   cart to session
396
+	 * @access public
397
+	 * @param bool $apply_taxes
398
+	 * @return TRUE on success, FALSE on fail
399
+	 * @throws \EE_Error
400
+	 */
401
+	public function save_cart($apply_taxes = true)
402
+	{
403
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
404
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
405
+			//make sure we don't cache the transaction because it can get stale
406
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
407
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
408
+			) {
409
+				$this->_grand_total->clear_cache('Transaction', null, true);
410
+			}
411
+		}
412
+		if ($this->session() instanceof EE_Session) {
413
+			return $this->session()->set_cart($this);
414
+		} else {
415
+			return false;
416
+		}
417
+	}
418
+
419
+
420
+
421
+	public function __wakeup()
422
+	{
423
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
424
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
425
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
426
+		}
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @return array
433
+	 */
434
+	public function __sleep()
435
+	{
436
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
437
+			$this->_grand_total = $this->_grand_total->ID();
438
+		}
439
+		return array('_grand_total');
440
+	}
441 441
 
442 442
 
443 443
 }
Please login to merge, or discard this patch.
display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -17,157 +17,157 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * enqueues css and js, so that this can be called statically
22
-     */
23
-    public static function enqueue_styles_and_scripts()
24
-    {
25
-        wp_register_style(
26
-            'checkbox_dropdown_selector',
27
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
28
-            array('espresso_default'),
29
-            EVENT_ESPRESSO_VERSION
30
-        );
31
-        wp_register_style(
32
-            'espresso_default',
33
-            EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
34
-            array('dashicons'),
35
-            EVENT_ESPRESSO_VERSION
36
-        );
37
-        wp_enqueue_style('checkbox_dropdown_selector');
38
-        wp_register_script(
39
-            'checkbox_dropdown_selector',
40
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
41
-            array('jquery'),
42
-            EVENT_ESPRESSO_VERSION,
43
-            true
44
-        );
45
-        wp_enqueue_script('checkbox_dropdown_selector');
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
52
-     */
53
-    public function enqueue_js(){
54
-        EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * callback for Iframe::addStylesheets() child class methods
61
-     *
62
-     * @param array $iframe_css
63
-     * @return array
64
-     */
65
-    public function iframe_css(array $iframe_css){
66
-        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
67
-        return $iframe_css;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * callback for Iframe::addScripts() child class methods
74
-     *
75
-     * @param array $iframe_js
76
-     * @return array
77
-     */
78
-    public function iframe_js(array $iframe_js){
79
-        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
80
-        return $iframe_js;
81
-    }
82
-
83
-
84
-    /**
85
-     * @throws EE_Error
86
-     * @return string of html to display the field
87
-     */
88
-    public function display()
89
-    {
90
-        $input = $this->get_input();
91
-        $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
92
-        // $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
93
-        $input->set_label_sizes();
94
-        $label_size_class = $input->get_label_size_class();
95
-        if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) {
96
-            EE_Error::doing_it_wrong(
97
-                'EE_Checkbox_Display_Strategy::display()',
98
-                sprintf(
99
-                    esc_html__(
100
-                        'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"',
101
-                        'event_espresso'
102
-                    ),
103
-                    $input->html_id(),
104
-                    var_export($input->raw_value(), true),
105
-                    $input->html_name() . '[]'
106
-                ),
107
-                '4.8.1'
108
-            );
109
-        }
110
-
111
-
112
-        $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
113
-        $html .= '<button id="' . $input->html_id() . '-btn"';
114
-        // $html .= ' name="' . $input->html_name() . '"';
115
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
116
-        $html .= ' style="' . $input->html_style() . '"';
117
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
118
-        $html .= ' ' . $input->html_other_attributes() . '>';
119
-        $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
120
-        $html .= $select_button_text;
121
-        $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
122
-        $html .= '</button>';
123
-        $html .= EEH_HTML::div(
124
-            '',
125
-            $input->html_id() . '-options-dv',
126
-            'checkbox-dropdown-selector'
127
-        );
128
-        $html .= EEH_HTML::link(
129
-            '',
130
-            '<span class="dashicons dashicons-no"></span>',
131
-            esc_html__('close datetime selector', 'event_espresso'),
132
-            '',
133
-            'close-espresso-notice'
134
-        );
135
-        $html .= EEH_HTML::ul();
136
-        $input_raw_value = (array)$input->raw_value();
137
-        foreach ($input->options() as $value => $display_text) {
138
-            $html .= EEH_HTML::li();
139
-            $value = $input->get_normalization_strategy()->unnormalize_one($value);
140
-            $html_id = $this->get_sub_input_id($value);
141
-            $html .= EEH_HTML::nl(0, 'checkbox');
142
-            $html .= '<label for="'
143
-                     . $html_id
144
-                     . '" id="'
145
-                     . $html_id
146
-                     . '-lbl" class="ee-checkbox-label-after'
147
-                     . $label_size_class
148
-                     . '">';
149
-            $html .= EEH_HTML::nl(1, 'checkbox');
150
-            $html .= '<input type="checkbox"';
151
-            $html .= ' name="' . $input->html_name() . '[]"';
152
-            $html .= ' id="' . $html_id . '"';
153
-            $html .= ' class="' . $input->html_class() . '-option"';
154
-            $html .= ' style="' . $input->html_style() . '"';
155
-            $html .= ' value="' . esc_attr($value) . '"';
156
-            $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
157
-                ? ' checked="checked"'
158
-                : '';
159
-            $html .= ' ' . $this->_input->other_html_attributes();
160
-            $html .= '>';
161
-            $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
162
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
163
-            $html .= EEH_HTML::lix();
164
-        }
165
-        $html .= EEH_HTML::ulx();
166
-        $html .= EEH_HTML::divx();
167
-        $html .= EEH_HTML::divx();
168
-        $html .= \EEH_HTML::br();
169
-        return $html;
170
-    }
20
+	/**
21
+	 * enqueues css and js, so that this can be called statically
22
+	 */
23
+	public static function enqueue_styles_and_scripts()
24
+	{
25
+		wp_register_style(
26
+			'checkbox_dropdown_selector',
27
+			EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
28
+			array('espresso_default'),
29
+			EVENT_ESPRESSO_VERSION
30
+		);
31
+		wp_register_style(
32
+			'espresso_default',
33
+			EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
34
+			array('dashicons'),
35
+			EVENT_ESPRESSO_VERSION
36
+		);
37
+		wp_enqueue_style('checkbox_dropdown_selector');
38
+		wp_register_script(
39
+			'checkbox_dropdown_selector',
40
+			EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
41
+			array('jquery'),
42
+			EVENT_ESPRESSO_VERSION,
43
+			true
44
+		);
45
+		wp_enqueue_script('checkbox_dropdown_selector');
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
52
+	 */
53
+	public function enqueue_js(){
54
+		EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * callback for Iframe::addStylesheets() child class methods
61
+	 *
62
+	 * @param array $iframe_css
63
+	 * @return array
64
+	 */
65
+	public function iframe_css(array $iframe_css){
66
+		$iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
67
+		return $iframe_css;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * callback for Iframe::addScripts() child class methods
74
+	 *
75
+	 * @param array $iframe_js
76
+	 * @return array
77
+	 */
78
+	public function iframe_js(array $iframe_js){
79
+		$iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
80
+		return $iframe_js;
81
+	}
82
+
83
+
84
+	/**
85
+	 * @throws EE_Error
86
+	 * @return string of html to display the field
87
+	 */
88
+	public function display()
89
+	{
90
+		$input = $this->get_input();
91
+		$select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : '';
92
+		// $multi = count( $input->options() ) > 1 ? TRUE : FALSE;
93
+		$input->set_label_sizes();
94
+		$label_size_class = $input->get_label_size_class();
95
+		if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) {
96
+			EE_Error::doing_it_wrong(
97
+				'EE_Checkbox_Display_Strategy::display()',
98
+				sprintf(
99
+					esc_html__(
100
+						'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"',
101
+						'event_espresso'
102
+					),
103
+					$input->html_id(),
104
+					var_export($input->raw_value(), true),
105
+					$input->html_name() . '[]'
106
+				),
107
+				'4.8.1'
108
+			);
109
+		}
110
+
111
+
112
+		$html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
113
+		$html .= '<button id="' . $input->html_id() . '-btn"';
114
+		// $html .= ' name="' . $input->html_name() . '"';
115
+		$html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
116
+		$html .= ' style="' . $input->html_style() . '"';
117
+		$html .= ' data-target="' . $input->html_id() . '-options-dv"';
118
+		$html .= ' ' . $input->html_other_attributes() . '>';
119
+		$html .= '<span class="checkbox-dropdown-selector-selected-spn">';
120
+		$html .= $select_button_text;
121
+		$html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
122
+		$html .= '</button>';
123
+		$html .= EEH_HTML::div(
124
+			'',
125
+			$input->html_id() . '-options-dv',
126
+			'checkbox-dropdown-selector'
127
+		);
128
+		$html .= EEH_HTML::link(
129
+			'',
130
+			'<span class="dashicons dashicons-no"></span>',
131
+			esc_html__('close datetime selector', 'event_espresso'),
132
+			'',
133
+			'close-espresso-notice'
134
+		);
135
+		$html .= EEH_HTML::ul();
136
+		$input_raw_value = (array)$input->raw_value();
137
+		foreach ($input->options() as $value => $display_text) {
138
+			$html .= EEH_HTML::li();
139
+			$value = $input->get_normalization_strategy()->unnormalize_one($value);
140
+			$html_id = $this->get_sub_input_id($value);
141
+			$html .= EEH_HTML::nl(0, 'checkbox');
142
+			$html .= '<label for="'
143
+					 . $html_id
144
+					 . '" id="'
145
+					 . $html_id
146
+					 . '-lbl" class="ee-checkbox-label-after'
147
+					 . $label_size_class
148
+					 . '">';
149
+			$html .= EEH_HTML::nl(1, 'checkbox');
150
+			$html .= '<input type="checkbox"';
151
+			$html .= ' name="' . $input->html_name() . '[]"';
152
+			$html .= ' id="' . $html_id . '"';
153
+			$html .= ' class="' . $input->html_class() . '-option"';
154
+			$html .= ' style="' . $input->html_style() . '"';
155
+			$html .= ' value="' . esc_attr($value) . '"';
156
+			$html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
157
+				? ' checked="checked"'
158
+				: '';
159
+			$html .= ' ' . $this->_input->other_html_attributes();
160
+			$html .= '>';
161
+			$html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
162
+			$html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
163
+			$html .= EEH_HTML::lix();
164
+		}
165
+		$html .= EEH_HTML::ulx();
166
+		$html .= EEH_HTML::divx();
167
+		$html .= EEH_HTML::divx();
168
+		$html .= \EEH_HTML::br();
169
+		return $html;
170
+	}
171 171
 
172 172
 
173 173
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
     {
25 25
         wp_register_style(
26 26
             'checkbox_dropdown_selector',
27
-            EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css',
27
+            EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css',
28 28
             array('espresso_default'),
29 29
             EVENT_ESPRESSO_VERSION
30 30
         );
31 31
         wp_register_style(
32 32
             'espresso_default',
33
-            EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
33
+            EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
34 34
             array('dashicons'),
35 35
             EVENT_ESPRESSO_VERSION
36 36
         );
37 37
         wp_enqueue_style('checkbox_dropdown_selector');
38 38
         wp_register_script(
39 39
             'checkbox_dropdown_selector',
40
-            EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js',
40
+            EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js',
41 41
             array('jquery'),
42 42
             EVENT_ESPRESSO_VERSION,
43 43
             true
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * Informs the rest of the forms system what CSS and JS is needed to display the input
52 52
      */
53
-    public function enqueue_js(){
53
+    public function enqueue_js() {
54 54
         EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
55 55
     }
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
      * @param array $iframe_css
63 63
      * @return array
64 64
      */
65
-    public function iframe_css(array $iframe_css){
66
-        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css';
65
+    public function iframe_css(array $iframe_css) {
66
+        $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css';
67 67
         return $iframe_css;
68 68
     }
69 69
 
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
      * @param array $iframe_js
76 76
      * @return array
77 77
      */
78
-    public function iframe_js(array $iframe_js){
79
-        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js';
78
+    public function iframe_js(array $iframe_js) {
79
+        $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js';
80 80
         return $iframe_js;
81 81
     }
82 82
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                     ),
103 103
                     $input->html_id(),
104 104
                     var_export($input->raw_value(), true),
105
-                    $input->html_name() . '[]'
105
+                    $input->html_name().'[]'
106 106
                 ),
107 107
                 '4.8.1'
108 108
             );
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 
111 111
 
112 112
         $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv');
113
-        $html .= '<button id="' . $input->html_id() . '-btn"';
113
+        $html .= '<button id="'.$input->html_id().'-btn"';
114 114
         // $html .= ' name="' . $input->html_name() . '"';
115
-        $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"';
116
-        $html .= ' style="' . $input->html_style() . '"';
117
-        $html .= ' data-target="' . $input->html_id() . '-options-dv"';
118
-        $html .= ' ' . $input->html_other_attributes() . '>';
115
+        $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"';
116
+        $html .= ' style="'.$input->html_style().'"';
117
+        $html .= ' data-target="'.$input->html_id().'-options-dv"';
118
+        $html .= ' '.$input->html_other_attributes().'>';
119 119
         $html .= '<span class="checkbox-dropdown-selector-selected-spn">';
120 120
         $html .= $select_button_text;
121 121
         $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>';
122 122
         $html .= '</button>';
123 123
         $html .= EEH_HTML::div(
124 124
             '',
125
-            $input->html_id() . '-options-dv',
125
+            $input->html_id().'-options-dv',
126 126
             'checkbox-dropdown-selector'
127 127
         );
128 128
         $html .= EEH_HTML::link(
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             'close-espresso-notice'
134 134
         );
135 135
         $html .= EEH_HTML::ul();
136
-        $input_raw_value = (array)$input->raw_value();
136
+        $input_raw_value = (array) $input->raw_value();
137 137
         foreach ($input->options() as $value => $display_text) {
138 138
             $html .= EEH_HTML::li();
139 139
             $value = $input->get_normalization_strategy()->unnormalize_one($value);
@@ -148,18 +148,18 @@  discard block
 block discarded – undo
148 148
                      . '">';
149 149
             $html .= EEH_HTML::nl(1, 'checkbox');
150 150
             $html .= '<input type="checkbox"';
151
-            $html .= ' name="' . $input->html_name() . '[]"';
152
-            $html .= ' id="' . $html_id . '"';
153
-            $html .= ' class="' . $input->html_class() . '-option"';
154
-            $html .= ' style="' . $input->html_style() . '"';
155
-            $html .= ' value="' . esc_attr($value) . '"';
151
+            $html .= ' name="'.$input->html_name().'[]"';
152
+            $html .= ' id="'.$html_id.'"';
153
+            $html .= ' class="'.$input->html_class().'-option"';
154
+            $html .= ' style="'.$input->html_style().'"';
155
+            $html .= ' value="'.esc_attr($value).'"';
156 156
             $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true)
157 157
                 ? ' checked="checked"'
158 158
                 : '';
159
-            $html .= ' ' . $this->_input->other_html_attributes();
159
+            $html .= ' '.$this->_input->other_html_attributes();
160 160
             $html .= '>';
161
-            $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>';
162
-            $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>';
161
+            $html .= '<span class="datetime-selector-option-text-spn">'.$display_text.'</span>';
162
+            $html .= EEH_HTML::nl(-1, 'checkbox').'</label>';
163 163
             $html .= EEH_HTML::lix();
164 164
         }
165 165
         $html .= EEH_HTML::ulx();
Please login to merge, or discard this patch.
core/services/loaders/CachingLoader.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -21,146 +21,146 @@
 block discarded – undo
21 21
 class CachingLoader extends LoaderDecorator
22 22
 {
23 23
 
24
-    /**
25
-     * @var CollectionInterface $cache
26
-     */
27
-    protected $cache;
28
-
29
-    /**
30
-     * @var string $identifier
31
-     */
32
-    protected $identifier;
33
-
34
-
35
-
36
-    /**
37
-     * CachingLoader constructor.
38
-     *
39
-     * @param LoaderDecoratorInterface $loader
40
-     * @param CollectionInterface      $cache
41
-     * @param string                   $identifier
42
-     * @throws InvalidDataTypeException
43
-     */
44
-    public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '')
45
-    {
46
-        parent::__construct($loader);
47
-        $this->cache = $cache;
48
-        $this->setIdentifier($identifier);
49
-        if ($this->identifier !== '') {
50
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
51
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
52
-            // where "IDENTIFIER" = the string that was set during construction
53
-            add_action(
54
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
55
-                array($this, 'reset')
56
-            );
57
-        }
58
-        // to clear ALL caches, simply do the following:
59
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
60
-        add_action(
61
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
62
-            array($this, 'reset')
63
-        );
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * @return string
70
-     */
71
-    public function identifier()
72
-    {
73
-        return $this->identifier;
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * @param string $identifier
80
-     * @throws InvalidDataTypeException
81
-     */
82
-    private function setIdentifier($identifier)
83
-    {
84
-        if ( ! is_string($identifier)) {
85
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
86
-        }
87
-        $this->identifier = $identifier;
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * @param string $fqcn
94
-     * @param array  $arguments
95
-     * @param bool   $shared
96
-     * @return mixed
97
-     */
98
-    public function load($fqcn, $arguments = array(), $shared = true)
99
-    {
100
-        $fqcn = ltrim($fqcn, '\\');
101
-        // caching can be turned off via the following code:
102
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
103
-        if(
104
-            apply_filters(
105
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
106
-                false,
107
-                $this
108
-            )
109
-        ){
110
-            // even though $shared might be true, caching could be bypassed for whatever reason,
111
-            // so we don't want the core loader to cache anything, therefore caching is turned off
112
-            return $this->loader->load($fqcn, $arguments, false);
113
-        }
114
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
115
-        if($this->cache->has($identifier)){
116
-            return $this->cache->get($identifier);
117
-        }
118
-        $object = $this->loader->load($fqcn, $arguments, $shared);
119
-        if($object instanceof $fqcn){
120
-            $this->cache->add($object, $identifier);
121
-        }
122
-        return $object;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * empties cache and calls reset() on loader if method exists
129
-     */
130
-    public function reset()
131
-    {
132
-        $this->cache->trashAndDetachAll();
133
-        $this->loader->reset();
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * build a string representation of a class' arguments
140
-     * (mostly because Closures can't be serialized)
141
-     *
142
-     * @param array $arguments
143
-     * @return string
144
-     */
145
-    private function getIdentifierForArgument(array $arguments)
146
-    {
147
-        $identifier = '';
148
-        foreach ($arguments as $argument) {
149
-            switch (true) {
150
-                case is_object($argument) :
151
-                case $argument instanceof Closure :
152
-                    $identifier .= spl_object_hash($argument);
153
-                    break;
154
-                case is_array($argument) :
155
-                    $identifier .= $this->getIdentifierForArgument($argument);
156
-                    break;
157
-                default :
158
-                    $identifier .= $argument;
159
-                    break;
160
-            }
161
-        }
162
-        return $identifier;
163
-    }
24
+	/**
25
+	 * @var CollectionInterface $cache
26
+	 */
27
+	protected $cache;
28
+
29
+	/**
30
+	 * @var string $identifier
31
+	 */
32
+	protected $identifier;
33
+
34
+
35
+
36
+	/**
37
+	 * CachingLoader constructor.
38
+	 *
39
+	 * @param LoaderDecoratorInterface $loader
40
+	 * @param CollectionInterface      $cache
41
+	 * @param string                   $identifier
42
+	 * @throws InvalidDataTypeException
43
+	 */
44
+	public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '')
45
+	{
46
+		parent::__construct($loader);
47
+		$this->cache = $cache;
48
+		$this->setIdentifier($identifier);
49
+		if ($this->identifier !== '') {
50
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
51
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
52
+			// where "IDENTIFIER" = the string that was set during construction
53
+			add_action(
54
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
55
+				array($this, 'reset')
56
+			);
57
+		}
58
+		// to clear ALL caches, simply do the following:
59
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
60
+		add_action(
61
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
62
+			array($this, 'reset')
63
+		);
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function identifier()
72
+	{
73
+		return $this->identifier;
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * @param string $identifier
80
+	 * @throws InvalidDataTypeException
81
+	 */
82
+	private function setIdentifier($identifier)
83
+	{
84
+		if ( ! is_string($identifier)) {
85
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
86
+		}
87
+		$this->identifier = $identifier;
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * @param string $fqcn
94
+	 * @param array  $arguments
95
+	 * @param bool   $shared
96
+	 * @return mixed
97
+	 */
98
+	public function load($fqcn, $arguments = array(), $shared = true)
99
+	{
100
+		$fqcn = ltrim($fqcn, '\\');
101
+		// caching can be turned off via the following code:
102
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
103
+		if(
104
+			apply_filters(
105
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
106
+				false,
107
+				$this
108
+			)
109
+		){
110
+			// even though $shared might be true, caching could be bypassed for whatever reason,
111
+			// so we don't want the core loader to cache anything, therefore caching is turned off
112
+			return $this->loader->load($fqcn, $arguments, false);
113
+		}
114
+		$identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
115
+		if($this->cache->has($identifier)){
116
+			return $this->cache->get($identifier);
117
+		}
118
+		$object = $this->loader->load($fqcn, $arguments, $shared);
119
+		if($object instanceof $fqcn){
120
+			$this->cache->add($object, $identifier);
121
+		}
122
+		return $object;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * empties cache and calls reset() on loader if method exists
129
+	 */
130
+	public function reset()
131
+	{
132
+		$this->cache->trashAndDetachAll();
133
+		$this->loader->reset();
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * build a string representation of a class' arguments
140
+	 * (mostly because Closures can't be serialized)
141
+	 *
142
+	 * @param array $arguments
143
+	 * @return string
144
+	 */
145
+	private function getIdentifierForArgument(array $arguments)
146
+	{
147
+		$identifier = '';
148
+		foreach ($arguments as $argument) {
149
+			switch (true) {
150
+				case is_object($argument) :
151
+				case $argument instanceof Closure :
152
+					$identifier .= spl_object_hash($argument);
153
+					break;
154
+				case is_array($argument) :
155
+					$identifier .= $this->getIdentifierForArgument($argument);
156
+					break;
157
+				default :
158
+					$identifier .= $argument;
159
+					break;
160
+			}
161
+		}
162
+		return $identifier;
163
+	}
164 164
 
165 165
 
166 166
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -100,23 +100,23 @@
 block discarded – undo
100 100
         $fqcn = ltrim($fqcn, '\\');
101 101
         // caching can be turned off via the following code:
102 102
         // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
103
-        if(
103
+        if (
104 104
             apply_filters(
105 105
                 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
106 106
                 false,
107 107
                 $this
108 108
             )
109
-        ){
109
+        ) {
110 110
             // even though $shared might be true, caching could be bypassed for whatever reason,
111 111
             // so we don't want the core loader to cache anything, therefore caching is turned off
112 112
             return $this->loader->load($fqcn, $arguments, false);
113 113
         }
114
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
115
-        if($this->cache->has($identifier)){
114
+        $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments));
115
+        if ($this->cache->has($identifier)) {
116 116
             return $this->cache->get($identifier);
117 117
         }
118 118
         $object = $this->loader->load($fqcn, $arguments, $shared);
119
-        if($object instanceof $fqcn){
119
+        if ($object instanceof $fqcn) {
120 120
             $this->cache->add($object, $identifier);
121 121
         }
122 122
         return $object;
Please login to merge, or discard this patch.
core/domain/RequiresDependencyMapInterface.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@
 block discarded – undo
20 20
 interface RequiresDependencyMapInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @param EE_Dependency_Map $dependency_map
25
-     */
26
-    public function setDependencyMap($dependency_map);
27
-
28
-    /**
29
-     * @return EE_Dependency_Map
30
-     */
31
-    public function dependencyMap();
23
+	/**
24
+	 * @param EE_Dependency_Map $dependency_map
25
+	 */
26
+	public function setDependencyMap($dependency_map);
27
+
28
+	/**
29
+	 * @return EE_Dependency_Map
30
+	 */
31
+	public function dependencyMap();
32 32
 
33 33
 }
34 34
 // Location: RequiresDependencyMap.php
Please login to merge, or discard this patch.