Completed
Branch FET-10619-money-entity (77ea92)
by
unknown
102:26 queued 91:05
created
core/services/currency/CurrencySubunits.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,8 +53,8 @@
 block discarded – undo
53 53
     /**
54 54
      * Gets the decimal fraction, or order of magnitude difference between the currency's main units and subunits.
55 55
      *
56
-     * @param $currency_code
57
-     * @return mixed
56
+     * @param string $currency_code
57
+     * @return integer
58 58
      * @throws EE_Error
59 59
      * @throws InvalidIdentifierException
60 60
      */
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -24,71 +24,71 @@
 block discarded – undo
24 24
 class CurrencySubunits
25 25
 {
26 26
 
27
-    /**
28
-     * array keys are currency codes, values are a sub-array with the  following values:
29
-     *      "decimals" : the decimal fraction, or order of magnitude difference,
30
-     *                   between that currency's main units and subunits.
31
-     *                   E.g. for USD the decimal fraction is 2.
32
-     *
33
-     * @var array $currency_subunits
34
-     */
35
-    private $currency_subunits;
36
-
37
-
38
-
39
-    /**
40
-     * Returns all the currency subunit data
41
-     *
42
-     * @return array
43
-     * @throws EE_Error
44
-     */
45
-    public function getAll()
46
-    {
47
-        $this->ensureInitialized();
48
-        return $this->currency_subunits;
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     * Gets the decimal fraction, or order of magnitude difference between the currency's main units and subunits.
55
-     *
56
-     * @param $currency_code
57
-     * @return mixed
58
-     * @throws EE_Error
59
-     * @throws InvalidIdentifierException
60
-     */
61
-    public function decimalsForCode($currency_code)
62
-    {
63
-        $this->ensureInitialized();
64
-        if (isset($this->currency_subunits[ $currency_code]['decimals'])) {
65
-            return $this->currency_subunits[ $currency_code]['decimals'];
66
-        }
67
-        throw new InvalidIdentifierException(
68
-            '',
69
-            $currency_code,
70
-            sprintf(
71
-                esc_html__('There is no currency with code %1$s', 'event_espresso'),
72
-                $currency_code
73
-            )
74
-        );
75
-    }
76
-
77
-
78
-    /**
79
-     * Just verifies this object's data from the filesystem has been loaded
80
-     *
81
-     * @throws EE_Error
82
-     */
83
-    private function ensureInitialized()
84
-    {
85
-        if ($this->currency_subunits === null) {
86
-            $this->currency_subunits = json_decode(
87
-                EEH_File::get_file_contents(__DIR__ . DS . 'currency-subunits.json'),
88
-                true
89
-            );
90
-        }
91
-    }
27
+	/**
28
+	 * array keys are currency codes, values are a sub-array with the  following values:
29
+	 *      "decimals" : the decimal fraction, or order of magnitude difference,
30
+	 *                   between that currency's main units and subunits.
31
+	 *                   E.g. for USD the decimal fraction is 2.
32
+	 *
33
+	 * @var array $currency_subunits
34
+	 */
35
+	private $currency_subunits;
36
+
37
+
38
+
39
+	/**
40
+	 * Returns all the currency subunit data
41
+	 *
42
+	 * @return array
43
+	 * @throws EE_Error
44
+	 */
45
+	public function getAll()
46
+	{
47
+		$this->ensureInitialized();
48
+		return $this->currency_subunits;
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 * Gets the decimal fraction, or order of magnitude difference between the currency's main units and subunits.
55
+	 *
56
+	 * @param $currency_code
57
+	 * @return mixed
58
+	 * @throws EE_Error
59
+	 * @throws InvalidIdentifierException
60
+	 */
61
+	public function decimalsForCode($currency_code)
62
+	{
63
+		$this->ensureInitialized();
64
+		if (isset($this->currency_subunits[ $currency_code]['decimals'])) {
65
+			return $this->currency_subunits[ $currency_code]['decimals'];
66
+		}
67
+		throw new InvalidIdentifierException(
68
+			'',
69
+			$currency_code,
70
+			sprintf(
71
+				esc_html__('There is no currency with code %1$s', 'event_espresso'),
72
+				$currency_code
73
+			)
74
+		);
75
+	}
76
+
77
+
78
+	/**
79
+	 * Just verifies this object's data from the filesystem has been loaded
80
+	 *
81
+	 * @throws EE_Error
82
+	 */
83
+	private function ensureInitialized()
84
+	{
85
+		if ($this->currency_subunits === null) {
86
+			$this->currency_subunits = json_decode(
87
+				EEH_File::get_file_contents(__DIR__ . DS . 'currency-subunits.json'),
88
+				true
89
+			);
90
+		}
91
+	}
92 92
 
93 93
 
94 94
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
     public function decimalsForCode($currency_code)
62 62
     {
63 63
         $this->ensureInitialized();
64
-        if (isset($this->currency_subunits[ $currency_code]['decimals'])) {
65
-            return $this->currency_subunits[ $currency_code]['decimals'];
64
+        if (isset($this->currency_subunits[$currency_code]['decimals'])) {
65
+            return $this->currency_subunits[$currency_code]['decimals'];
66 66
         }
67 67
         throw new InvalidIdentifierException(
68 68
             '',
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     {
85 85
         if ($this->currency_subunits === null) {
86 86
             $this->currency_subunits = json_decode(
87
-                EEH_File::get_file_contents(__DIR__ . DS . 'currency-subunits.json'),
87
+                EEH_File::get_file_contents(__DIR__.DS.'currency-subunits.json'),
88 88
                 true
89 89
             );
90 90
         }
Please login to merge, or discard this patch.
core/services/currency/CurrencyFactory.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -28,153 +28,153 @@
 block discarded – undo
28 28
 class CurrencyFactory
29 29
 {
30 30
 
31
-    /**
32
-     * @var EEM_Country $country_model
33
-     */
34
-    protected $country_model;
35
-
36
-    /**
37
-     * @var EE_Country[] $countries
38
-     */
39
-    protected $countries_by_iso_code;
40
-
41
-    /**
42
-     * @var EE_Country[] $countries
43
-     */
44
-    protected $countries_by_currency;
45
-
46
-    /**
47
-     * @var EE_Organization_Config $organization_config
48
-     */
49
-    protected $organization_config;
50
-
51
-    /**
52
-     * @var string $site_country_iso
53
-     */
54
-    protected $site_country_iso;
55
-
56
-    /**
57
-     * @var CurrencySubunits $currency_subunits
58
-     */
59
-    protected $currency_subunits;
60
-
61
-
62
-    /**
63
-     * CurrencyFactory constructor.
64
-     *
65
-     * @param EEM_Country            $country_model
66
-     * @param EE_Organization_Config $organization_config
67
-     * @param CurrencySubunits       $currency_subunits
68
-     */
69
-    public function __construct(
70
-        EEM_Country $country_model,
71
-        EE_Organization_Config$organization_config,
72
-        CurrencySubunits $currency_subunits
73
-    ) {
74
-        $this->country_model = $country_model;
75
-        $this->organization_config = $organization_config;
76
-        $this->currency_subunits = $currency_subunits;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * returns a Currency object for the supplied country code
83
-     *
84
-     * @param string $CNT_ISO
85
-     * @return Currency
86
-     * @throws InvalidIdentifierException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidInterfaceException
89
-     * @throws EE_Error
90
-     * @throws InvalidArgumentException
91
-     */
92
-    public function createFromCountryCode($CNT_ISO = null)
93
-    {
94
-        $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->organization_config->CNT_ISO;
95
-        if(isset($this->countries_by_iso_code[ $CNT_ISO])) {
96
-            $country = $this->countries_by_iso_code[ $CNT_ISO ];
97
-        } else {
98
-            /** @var EE_Country $country */
99
-            $country = $this->country_model->get_one_by_ID($CNT_ISO);
100
-            if (! $country instanceof EE_Country) {
101
-                throw new InvalidArgumentException(
102
-                    sprintf(
103
-                        esc_html__(
104
-                            'A valid country could not be found for the "%1$s" country code;',
105
-                            'event_espresso'
106
-                        ),
107
-                        $CNT_ISO
108
-                    )
109
-                );
110
-            }
111
-            $this->countries_by_iso_code[ $CNT_ISO ]                  = $country;
112
-            $this->countries_by_currency[ $country->currency_code() ] = $country;
113
-        }
114
-        return new Currency(
115
-            $country->currency_code(),
116
-            new Label(
117
-                $country->currency_name_single(),
118
-                $country->currency_name_plural()
119
-            ),
120
-            $country->currency_sign(),
121
-            $country->currency_sign_before(),
122
-            $country->currency_decimal_places(),
123
-            $country->currency_decimal_mark(),
124
-            $country->currency_thousands_separator(),
125
-            $this->currency_subunits->decimalsForCode($country->currency_code())
126
-        );
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * returns a Currency object for the supplied currency code
133
-     * PLZ NOTE: variations may exist between how different countries display the same currency,
134
-     * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results
135
-     *
136
-     * @param string $code
137
-     * @return Currency
138
-     * @throws InvalidIdentifierException
139
-     * @throws InvalidInterfaceException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidArgumentException
142
-     * @throws EE_Error
143
-     */
144
-    public function createFromCode($code)
145
-    {
146
-        if (isset($this->countries_by_currency[ $code ])) {
147
-            $country = $this->countries_by_currency[ $code ];
148
-        } else {
149
-            /** @var EE_Country $country */
150
-            $country = $this->country_model->get_one(array(array('CNT_cur_code' => $code)));
151
-            if (! $country instanceof EE_Country) {
152
-                throw new InvalidArgumentException(
153
-                    sprintf(
154
-                        esc_html__(
155
-                            'A valid currency could not be found for the "%1$s" currency code;',
156
-                            'event_espresso'
157
-                        ),
158
-                        $code
159
-                    )
160
-                );
161
-            }
162
-            $this->countries_by_iso_code[ $country->ID() ] = $country;
163
-            $this->countries_by_currency[ $code ]          = $country;
164
-        }
165
-        return new Currency(
166
-            $country->currency_code(),
167
-            new Label(
168
-                $country->currency_name_single(),
169
-                $country->currency_name_plural()
170
-            ),
171
-            $country->currency_sign(),
172
-            $country->currency_sign_before(),
173
-            $country->currency_decimal_places(),
174
-            $country->currency_decimal_mark(),
175
-            $country->currency_thousands_separator(),
176
-            $this->currency_subunits->decimalsForCode($code)
177
-        );
178
-    }
31
+	/**
32
+	 * @var EEM_Country $country_model
33
+	 */
34
+	protected $country_model;
35
+
36
+	/**
37
+	 * @var EE_Country[] $countries
38
+	 */
39
+	protected $countries_by_iso_code;
40
+
41
+	/**
42
+	 * @var EE_Country[] $countries
43
+	 */
44
+	protected $countries_by_currency;
45
+
46
+	/**
47
+	 * @var EE_Organization_Config $organization_config
48
+	 */
49
+	protected $organization_config;
50
+
51
+	/**
52
+	 * @var string $site_country_iso
53
+	 */
54
+	protected $site_country_iso;
55
+
56
+	/**
57
+	 * @var CurrencySubunits $currency_subunits
58
+	 */
59
+	protected $currency_subunits;
60
+
61
+
62
+	/**
63
+	 * CurrencyFactory constructor.
64
+	 *
65
+	 * @param EEM_Country            $country_model
66
+	 * @param EE_Organization_Config $organization_config
67
+	 * @param CurrencySubunits       $currency_subunits
68
+	 */
69
+	public function __construct(
70
+		EEM_Country $country_model,
71
+		EE_Organization_Config$organization_config,
72
+		CurrencySubunits $currency_subunits
73
+	) {
74
+		$this->country_model = $country_model;
75
+		$this->organization_config = $organization_config;
76
+		$this->currency_subunits = $currency_subunits;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * returns a Currency object for the supplied country code
83
+	 *
84
+	 * @param string $CNT_ISO
85
+	 * @return Currency
86
+	 * @throws InvalidIdentifierException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidInterfaceException
89
+	 * @throws EE_Error
90
+	 * @throws InvalidArgumentException
91
+	 */
92
+	public function createFromCountryCode($CNT_ISO = null)
93
+	{
94
+		$CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->organization_config->CNT_ISO;
95
+		if(isset($this->countries_by_iso_code[ $CNT_ISO])) {
96
+			$country = $this->countries_by_iso_code[ $CNT_ISO ];
97
+		} else {
98
+			/** @var EE_Country $country */
99
+			$country = $this->country_model->get_one_by_ID($CNT_ISO);
100
+			if (! $country instanceof EE_Country) {
101
+				throw new InvalidArgumentException(
102
+					sprintf(
103
+						esc_html__(
104
+							'A valid country could not be found for the "%1$s" country code;',
105
+							'event_espresso'
106
+						),
107
+						$CNT_ISO
108
+					)
109
+				);
110
+			}
111
+			$this->countries_by_iso_code[ $CNT_ISO ]                  = $country;
112
+			$this->countries_by_currency[ $country->currency_code() ] = $country;
113
+		}
114
+		return new Currency(
115
+			$country->currency_code(),
116
+			new Label(
117
+				$country->currency_name_single(),
118
+				$country->currency_name_plural()
119
+			),
120
+			$country->currency_sign(),
121
+			$country->currency_sign_before(),
122
+			$country->currency_decimal_places(),
123
+			$country->currency_decimal_mark(),
124
+			$country->currency_thousands_separator(),
125
+			$this->currency_subunits->decimalsForCode($country->currency_code())
126
+		);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * returns a Currency object for the supplied currency code
133
+	 * PLZ NOTE: variations may exist between how different countries display the same currency,
134
+	 * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results
135
+	 *
136
+	 * @param string $code
137
+	 * @return Currency
138
+	 * @throws InvalidIdentifierException
139
+	 * @throws InvalidInterfaceException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidArgumentException
142
+	 * @throws EE_Error
143
+	 */
144
+	public function createFromCode($code)
145
+	{
146
+		if (isset($this->countries_by_currency[ $code ])) {
147
+			$country = $this->countries_by_currency[ $code ];
148
+		} else {
149
+			/** @var EE_Country $country */
150
+			$country = $this->country_model->get_one(array(array('CNT_cur_code' => $code)));
151
+			if (! $country instanceof EE_Country) {
152
+				throw new InvalidArgumentException(
153
+					sprintf(
154
+						esc_html__(
155
+							'A valid currency could not be found for the "%1$s" currency code;',
156
+							'event_espresso'
157
+						),
158
+						$code
159
+					)
160
+				);
161
+			}
162
+			$this->countries_by_iso_code[ $country->ID() ] = $country;
163
+			$this->countries_by_currency[ $code ]          = $country;
164
+		}
165
+		return new Currency(
166
+			$country->currency_code(),
167
+			new Label(
168
+				$country->currency_name_single(),
169
+				$country->currency_name_plural()
170
+			),
171
+			$country->currency_sign(),
172
+			$country->currency_sign_before(),
173
+			$country->currency_decimal_places(),
174
+			$country->currency_decimal_mark(),
175
+			$country->currency_thousands_separator(),
176
+			$this->currency_subunits->decimalsForCode($code)
177
+		);
178
+	}
179 179
 }
180 180
 // Location: CreateCurrency.php
Please login to merge, or discard this patch.
core/services/currency/MoneyFactory.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -30,217 +30,217 @@
 block discarded – undo
30 30
 class MoneyFactory
31 31
 {
32 32
 
33
-    /**
34
-     * @var CurrencyFactory $currency_factory
35
-     */
36
-    protected $currency_factory;
37
-
38
-    /**
39
-     * @var Calculator $calculator
40
-     */
41
-    protected $calculator;
42
-
43
-    /**
44
-     * @var MoneyFormatter[] $formatters
45
-     */
46
-    protected $formatters;
47
-
48
-
49
-    /**
50
-     * CreateMoney constructor.
51
-     *
52
-     * @param CurrencyFactory  $currency_factory
53
-     * @param Calculator       $calculator
54
-     * @param MoneyFormatter[] $formatters
55
-     */
56
-    public function __construct(
57
-        CurrencyFactory $currency_factory,
58
-        Calculator $calculator = null,
59
-        array $formatters = array()
60
-    ) {
61
-        $this->calculator = $calculator;
62
-        $this->formatters = $formatters;
63
-        $this->currency_factory = $currency_factory;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * factory method that returns a Money object using amount specified in the currency's subunits
70
-     * example: for $12.50 USD use CreateMoney::fromSubUnits(1250, 'USD')
71
-     *
72
-     * @param int    $subunits_amount money amount IN THE SUBUNITS FOR THE CURRENCY ie: cents
73
-     *                                example: $12.50 USD would equate to a subunits amount of 1250
74
-     * @param string $currency_code
75
-     * @return Money
76
-     * @throws EE_Error
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidIdentifierException
80
-     * @throws InvalidInterfaceException
81
-     */
82
-    public function createFromSubUnits($subunits_amount, $currency_code = '')
83
-    {
84
-        $currency = $this->currency_factory->createFromCode($currency_code);
85
-        return new Money(
86
-            // shift decimal BACK by number of places for currency
87
-            $subunits_amount * pow(10, $currency->decimalPlaces() * -1),
88
-            $currency,
89
-            $this->calculator(),
90
-            $this->formatters()
91
-        );
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * factory method that returns a Money object using the currency corresponding to the site's country
98
-     * example: CreateMoney::forSite(12.5)
99
-     *
100
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
101
-     *                                 example: $12.5 USD would equate to a standard amount of 12.50
102
-     * @return Money
103
-     * @throws EE_Error
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidIdentifierException
107
-     * @throws InvalidInterfaceException
108
-     */
109
-    public function createForSite($amount)
110
-    {
111
-        return new Money(
112
-            $amount,
113
-            $this->currency_factory->createFromCountryCode(),
114
-            $this->calculator(),
115
-            $this->formatters()
116
-        );
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * factory method that returns a Money object using the currency as specified by the supplied ISO country code
123
-     * example: CreateMoney::forCountry(12.5,'US')
124
-     *
125
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
126
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
127
-     * @param string           $CNT_ISO
128
-     * @return Money
129
-     * @throws EE_Error
130
-     * @throws InvalidArgumentException
131
-     * @throws InvalidDataTypeException
132
-     * @throws InvalidIdentifierException
133
-     * @throws InvalidInterfaceException
134
-     */
135
-    public function createForCountry($amount, $CNT_ISO)
136
-    {
137
-        return new Money(
138
-            $amount,
139
-            $this->currency_factory->createFromCountryCode($CNT_ISO),
140
-            $this->calculator(),
141
-            $this->formatters()
142
-        );
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * factory method that returns a Money object using the currency as specified by the supplied currency code
149
-     * example: CreateMoney::forCurrency(12.5, 'USD')
150
-     *
151
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
152
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
153
-     * @param string           $currency_code
154
-     * @return Money
155
-     * @throws EE_Error
156
-     * @throws InvalidArgumentException
157
-     * @throws InvalidDataTypeException
158
-     * @throws InvalidIdentifierException
159
-     * @throws InvalidInterfaceException
160
-     */
161
-    public function createForCurrency($amount, $currency_code)
162
-    {
163
-        return new Money(
164
-            $amount,
165
-            $this->currency_factory->createFromCode($currency_code),
166
-            $this->calculator(),
167
-            $this->formatters()
168
-        );
169
-    }
170
-
171
-
172
-
173
-
174
-    /**
175
-     * @return Calculator
176
-     */
177
-    public function calculator()
178
-    {
179
-        $this->initializeCalculators();
180
-        return $this->calculator;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * loops through a filterable array of Calculator services
187
-     * and selects the first one that is supported by the current server
188
-     */
189
-    protected function initializeCalculators()
190
-    {
191
-        if ($this->calculator instanceof Calculator) {
192
-            return;
193
-        }
194
-        $calculators = apply_filters(
195
-            'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeCalculators__Calculators_array',
196
-            array(
197
-                '\EventEspresso\core\services\currency\DefaultCalculator',
198
-            )
199
-        );
200
-        foreach ($calculators as $calculator) {
201
-            if (! class_exists($calculator)) {
202
-                continue;
203
-            }
204
-            $calculator = new $calculator();
205
-            if ($calculator instanceof Calculator && $calculator->isSupported()) {
206
-                $this->calculator = $calculator;
207
-                break;
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * @return MoneyFormatter[]
216
-     */
217
-    public function formatters()
218
-    {
219
-        $this->initializeFormatters();
220
-        return $this->formatters;
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * initializes a filterable array of MoneyFormatter services
227
-     */
228
-    protected function initializeFormatters()
229
-    {
230
-        if (! empty($this->formatters)) {
231
-            return;
232
-        }
233
-        $this->formatters = apply_filters(
234
-            'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeFormatters__MoneyFormatters_array',
235
-            array(
236
-                1 => new DecimalMoneyFormatter(),
237
-                2 => new ThousandsMoneyFormatter(),
238
-                3 => new CurrencySignMoneyFormatter(),
239
-                4 => new CurrencyCodeMoneyFormatter(),
240
-                5 => new InternationalMoneyFormatter(),
241
-            )
242
-        );
243
-    }
33
+	/**
34
+	 * @var CurrencyFactory $currency_factory
35
+	 */
36
+	protected $currency_factory;
37
+
38
+	/**
39
+	 * @var Calculator $calculator
40
+	 */
41
+	protected $calculator;
42
+
43
+	/**
44
+	 * @var MoneyFormatter[] $formatters
45
+	 */
46
+	protected $formatters;
47
+
48
+
49
+	/**
50
+	 * CreateMoney constructor.
51
+	 *
52
+	 * @param CurrencyFactory  $currency_factory
53
+	 * @param Calculator       $calculator
54
+	 * @param MoneyFormatter[] $formatters
55
+	 */
56
+	public function __construct(
57
+		CurrencyFactory $currency_factory,
58
+		Calculator $calculator = null,
59
+		array $formatters = array()
60
+	) {
61
+		$this->calculator = $calculator;
62
+		$this->formatters = $formatters;
63
+		$this->currency_factory = $currency_factory;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * factory method that returns a Money object using amount specified in the currency's subunits
70
+	 * example: for $12.50 USD use CreateMoney::fromSubUnits(1250, 'USD')
71
+	 *
72
+	 * @param int    $subunits_amount money amount IN THE SUBUNITS FOR THE CURRENCY ie: cents
73
+	 *                                example: $12.50 USD would equate to a subunits amount of 1250
74
+	 * @param string $currency_code
75
+	 * @return Money
76
+	 * @throws EE_Error
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidIdentifierException
80
+	 * @throws InvalidInterfaceException
81
+	 */
82
+	public function createFromSubUnits($subunits_amount, $currency_code = '')
83
+	{
84
+		$currency = $this->currency_factory->createFromCode($currency_code);
85
+		return new Money(
86
+			// shift decimal BACK by number of places for currency
87
+			$subunits_amount * pow(10, $currency->decimalPlaces() * -1),
88
+			$currency,
89
+			$this->calculator(),
90
+			$this->formatters()
91
+		);
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * factory method that returns a Money object using the currency corresponding to the site's country
98
+	 * example: CreateMoney::forSite(12.5)
99
+	 *
100
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
101
+	 *                                 example: $12.5 USD would equate to a standard amount of 12.50
102
+	 * @return Money
103
+	 * @throws EE_Error
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidIdentifierException
107
+	 * @throws InvalidInterfaceException
108
+	 */
109
+	public function createForSite($amount)
110
+	{
111
+		return new Money(
112
+			$amount,
113
+			$this->currency_factory->createFromCountryCode(),
114
+			$this->calculator(),
115
+			$this->formatters()
116
+		);
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * factory method that returns a Money object using the currency as specified by the supplied ISO country code
123
+	 * example: CreateMoney::forCountry(12.5,'US')
124
+	 *
125
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
126
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
127
+	 * @param string           $CNT_ISO
128
+	 * @return Money
129
+	 * @throws EE_Error
130
+	 * @throws InvalidArgumentException
131
+	 * @throws InvalidDataTypeException
132
+	 * @throws InvalidIdentifierException
133
+	 * @throws InvalidInterfaceException
134
+	 */
135
+	public function createForCountry($amount, $CNT_ISO)
136
+	{
137
+		return new Money(
138
+			$amount,
139
+			$this->currency_factory->createFromCountryCode($CNT_ISO),
140
+			$this->calculator(),
141
+			$this->formatters()
142
+		);
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * factory method that returns a Money object using the currency as specified by the supplied currency code
149
+	 * example: CreateMoney::forCurrency(12.5, 'USD')
150
+	 *
151
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
152
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
153
+	 * @param string           $currency_code
154
+	 * @return Money
155
+	 * @throws EE_Error
156
+	 * @throws InvalidArgumentException
157
+	 * @throws InvalidDataTypeException
158
+	 * @throws InvalidIdentifierException
159
+	 * @throws InvalidInterfaceException
160
+	 */
161
+	public function createForCurrency($amount, $currency_code)
162
+	{
163
+		return new Money(
164
+			$amount,
165
+			$this->currency_factory->createFromCode($currency_code),
166
+			$this->calculator(),
167
+			$this->formatters()
168
+		);
169
+	}
170
+
171
+
172
+
173
+
174
+	/**
175
+	 * @return Calculator
176
+	 */
177
+	public function calculator()
178
+	{
179
+		$this->initializeCalculators();
180
+		return $this->calculator;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * loops through a filterable array of Calculator services
187
+	 * and selects the first one that is supported by the current server
188
+	 */
189
+	protected function initializeCalculators()
190
+	{
191
+		if ($this->calculator instanceof Calculator) {
192
+			return;
193
+		}
194
+		$calculators = apply_filters(
195
+			'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeCalculators__Calculators_array',
196
+			array(
197
+				'\EventEspresso\core\services\currency\DefaultCalculator',
198
+			)
199
+		);
200
+		foreach ($calculators as $calculator) {
201
+			if (! class_exists($calculator)) {
202
+				continue;
203
+			}
204
+			$calculator = new $calculator();
205
+			if ($calculator instanceof Calculator && $calculator->isSupported()) {
206
+				$this->calculator = $calculator;
207
+				break;
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * @return MoneyFormatter[]
216
+	 */
217
+	public function formatters()
218
+	{
219
+		$this->initializeFormatters();
220
+		return $this->formatters;
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * initializes a filterable array of MoneyFormatter services
227
+	 */
228
+	protected function initializeFormatters()
229
+	{
230
+		if (! empty($this->formatters)) {
231
+			return;
232
+		}
233
+		$this->formatters = apply_filters(
234
+			'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeFormatters__MoneyFormatters_array',
235
+			array(
236
+				1 => new DecimalMoneyFormatter(),
237
+				2 => new ThousandsMoneyFormatter(),
238
+				3 => new CurrencySignMoneyFormatter(),
239
+				4 => new CurrencyCodeMoneyFormatter(),
240
+				5 => new InternationalMoneyFormatter(),
241
+			)
242
+		);
243
+	}
244 244
 
245 245
 
246 246
 }
Please login to merge, or discard this patch.
core/domain/values/currency/Currency.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -19,214 +19,214 @@
 block discarded – undo
19 19
 class Currency
20 20
 {
21 21
 
22
-    /**
23
-     * eg 'US'
24
-     *
25
-     * @var string $code
26
-     */
27
-    private $code;
28
-
29
-    /**
30
-     * @var Label $label
31
-     */
32
-    private $label;
33
-
34
-    /**
35
-     * currency sign
36
-     *
37
-     * @var string $sign
38
-     * eg '$'
39
-     */
40
-    private $sign;
41
-
42
-    /**
43
-     * Whether the currency sign should come before the number or not
44
-     *
45
-     * @var boolean $sign_b4
46
-     */
47
-    private $sign_b4;
48
-
49
-    /**
50
-     * How many digits should come after the decimal place
51
-     *
52
-     * @var int $decimal_places
53
-     */
54
-    private $decimal_places;
55
-
56
-    /**
57
-     * Symbol to use for decimal mark
58
-     *
59
-     * @var string $decimal_mark
60
-     * eg '.'
61
-     */
62
-    private $decimal_mark;
63
-
64
-    /**
65
-     * Symbol to use for thousands
66
-     *
67
-     * @var string $thousands
68
-     * eg ','
69
-     */
70
-    private $thousands;
71
-
72
-    /**
73
-     * Used to convert between the currency's units and subunits.
74
-     * subunits = units * 10 to-the-power-of $subunits_ratio
75
-     * @var int
76
-     */
77
-    private $subunit_order_of_mag_diff;
78
-
79
-
80
-
81
-    /**
82
-     * Currency constructor.
83
-     *
84
-     * @param string $code
85
-     * @param Label  $label
86
-     * @param string $sign
87
-     * @param bool   $sign_b4
88
-     * @param int    $decimal_places            the number of decimal places to use when
89
-     *                               DISPLAYING the currency
90
-     * @param string $decimal_mark
91
-     * @param string $thousands
92
-     * @param int    $subunit_order_of_mag_diff the difference between units and subunits
93
-     *                               is 10 to-the-power-of-this
94
-     */
95
-    public function __construct(
96
-        $code,
97
-        Label $label,
98
-        $sign,
99
-        $sign_b4,
100
-        $decimal_places,
101
-        $decimal_mark,
102
-        $thousands,
103
-        $subunit_order_of_mag_diff
104
-    ) {
105
-        $this->code           = $code;
106
-        $this->label          = $label;
107
-        $this->sign           = $sign;
108
-        $this->sign_b4        = $sign_b4;
109
-        $this->decimal_places = $decimal_places;
110
-        $this->decimal_mark   = $decimal_mark;
111
-        $this->thousands      = $thousands;
112
-        $this->subunit_order_of_mag_diff = $subunit_order_of_mag_diff;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * returns true if this currency is the same as the supplied currency
119
-     *
120
-     * @param Currency $other
121
-     * @return bool
122
-     */
123
-    public function equals(Currency $other)
124
-    {
125
-        return $this->code() === $other->code();
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @return string
132
-     */
133
-    public function code()
134
-    {
135
-        return $this->code;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * @return string
142
-     */
143
-    public function name()
144
-    {
145
-        return $this->label->singular();
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @return string
152
-     */
153
-    public function plural()
154
-    {
155
-        return $this->label->plural();
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * @return string
162
-     */
163
-    public function sign()
164
-    {
165
-        return $this->sign;
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * @return bool
172
-     */
173
-    public function signB4()
174
-    {
175
-        return $this->sign_b4;
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * @return int
182
-     */
183
-    public function decimalPlaces()
184
-    {
185
-        return $this->decimal_places;
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * @return string
192
-     */
193
-    public function decimalMark()
194
-    {
195
-        return $this->decimal_mark;
196
-    }
22
+	/**
23
+	 * eg 'US'
24
+	 *
25
+	 * @var string $code
26
+	 */
27
+	private $code;
28
+
29
+	/**
30
+	 * @var Label $label
31
+	 */
32
+	private $label;
33
+
34
+	/**
35
+	 * currency sign
36
+	 *
37
+	 * @var string $sign
38
+	 * eg '$'
39
+	 */
40
+	private $sign;
41
+
42
+	/**
43
+	 * Whether the currency sign should come before the number or not
44
+	 *
45
+	 * @var boolean $sign_b4
46
+	 */
47
+	private $sign_b4;
48
+
49
+	/**
50
+	 * How many digits should come after the decimal place
51
+	 *
52
+	 * @var int $decimal_places
53
+	 */
54
+	private $decimal_places;
55
+
56
+	/**
57
+	 * Symbol to use for decimal mark
58
+	 *
59
+	 * @var string $decimal_mark
60
+	 * eg '.'
61
+	 */
62
+	private $decimal_mark;
63
+
64
+	/**
65
+	 * Symbol to use for thousands
66
+	 *
67
+	 * @var string $thousands
68
+	 * eg ','
69
+	 */
70
+	private $thousands;
71
+
72
+	/**
73
+	 * Used to convert between the currency's units and subunits.
74
+	 * subunits = units * 10 to-the-power-of $subunits_ratio
75
+	 * @var int
76
+	 */
77
+	private $subunit_order_of_mag_diff;
78
+
79
+
80
+
81
+	/**
82
+	 * Currency constructor.
83
+	 *
84
+	 * @param string $code
85
+	 * @param Label  $label
86
+	 * @param string $sign
87
+	 * @param bool   $sign_b4
88
+	 * @param int    $decimal_places            the number of decimal places to use when
89
+	 *                               DISPLAYING the currency
90
+	 * @param string $decimal_mark
91
+	 * @param string $thousands
92
+	 * @param int    $subunit_order_of_mag_diff the difference between units and subunits
93
+	 *                               is 10 to-the-power-of-this
94
+	 */
95
+	public function __construct(
96
+		$code,
97
+		Label $label,
98
+		$sign,
99
+		$sign_b4,
100
+		$decimal_places,
101
+		$decimal_mark,
102
+		$thousands,
103
+		$subunit_order_of_mag_diff
104
+	) {
105
+		$this->code           = $code;
106
+		$this->label          = $label;
107
+		$this->sign           = $sign;
108
+		$this->sign_b4        = $sign_b4;
109
+		$this->decimal_places = $decimal_places;
110
+		$this->decimal_mark   = $decimal_mark;
111
+		$this->thousands      = $thousands;
112
+		$this->subunit_order_of_mag_diff = $subunit_order_of_mag_diff;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * returns true if this currency is the same as the supplied currency
119
+	 *
120
+	 * @param Currency $other
121
+	 * @return bool
122
+	 */
123
+	public function equals(Currency $other)
124
+	{
125
+		return $this->code() === $other->code();
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @return string
132
+	 */
133
+	public function code()
134
+	{
135
+		return $this->code;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * @return string
142
+	 */
143
+	public function name()
144
+	{
145
+		return $this->label->singular();
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @return string
152
+	 */
153
+	public function plural()
154
+	{
155
+		return $this->label->plural();
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * @return string
162
+	 */
163
+	public function sign()
164
+	{
165
+		return $this->sign;
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * @return bool
172
+	 */
173
+	public function signB4()
174
+	{
175
+		return $this->sign_b4;
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * @return int
182
+	 */
183
+	public function decimalPlaces()
184
+	{
185
+		return $this->decimal_places;
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * @return string
192
+	 */
193
+	public function decimalMark()
194
+	{
195
+		return $this->decimal_mark;
196
+	}
197 197
 
198 198
 
199 199
 
200
-    /**
201
-     * @return string
202
-     */
203
-    public function thousands()
204
-    {
205
-        return $this->thousands;
206
-    }
200
+	/**
201
+	 * @return string
202
+	 */
203
+	public function thousands()
204
+	{
205
+		return $this->thousands;
206
+	}
207 207
 
208 208
 
209 209
 
210
-    /**
211
-     * The difference between currency units and subunits
212
-     * is 10-to-the-power-of-this.
213
-     * DecimalMark is used for display, this is used for calculations
214
-     * @return int
215
-     */
216
-    public function subunitOrderOfMagnitudeDiff()
217
-    {
218
-        return $this->subunit_order_of_mag_diff;
219
-    }
210
+	/**
211
+	 * The difference between currency units and subunits
212
+	 * is 10-to-the-power-of-this.
213
+	 * DecimalMark is used for display, this is used for calculations
214
+	 * @return int
215
+	 */
216
+	public function subunitOrderOfMagnitudeDiff()
217
+	{
218
+		return $this->subunit_order_of_mag_diff;
219
+	}
220 220
 
221 221
 
222 222
 
223
-    /**
224
-     * @return string
225
-     */
226
-    public function __toString()
227
-    {
228
-        return $this->code();
229
-    }
223
+	/**
224
+	 * @return string
225
+	 */
226
+	public function __toString()
227
+	{
228
+		return $this->code();
229
+	}
230 230
 
231 231
 
232 232
 
Please login to merge, or discard this patch.
core/domain/values/currency/Money.php 2 patches
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -22,338 +22,338 @@
 block discarded – undo
22 22
 class Money
23 23
 {
24 24
 
25
-    /**
26
-     * number of decimal places to be added to currencies for internal computations,
27
-     * but removed before any output or formatting is applied.
28
-     * This allows us to avoid rounding errors during calculations.
29
-     */
30
-    const EXTRA_PRECISION = 3;
31
-
32
-    /**
33
-     * @var int $amount
34
-     */
35
-    private $amount;
36
-
37
-    /**
38
-     * @var Currency $currency
39
-     */
40
-    private $currency;
41
-
42
-    /**
43
-     * @var Calculator $calculator
44
-     */
45
-    protected $calculator;
46
-
47
-    /**
48
-     * @var MoneyFormatter[] $formatters
49
-     */
50
-    protected $formatters;
51
-
52
-
53
-
54
-    /**
55
-     * Money constructor.
56
-     *
57
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
58
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
59
-     * @param Currency         $currency
60
-     * @param Calculator       $calculator
61
-     * @param MoneyFormatter[] $formatters
62
-     * @throws InvalidDataTypeException
63
-     */
64
-    public function __construct($amount, Currency $currency, Calculator $calculator, array $formatters)
65
-    {
66
-        $this->currency   = $currency;
67
-        $this->amount     = $this->parseAmount($amount);
68
-        $this->calculator = $calculator;
69
-        $this->formatters = $formatters;
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * @return Calculator
76
-     */
77
-    protected function calculator()
78
-    {
79
-        return $this->calculator;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * @return MoneyFormatter[]
86
-     */
87
-    protected function formatters()
88
-    {
89
-        return $this->formatters;
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * Convert's a standard unit amount into the subunits of the currency
96
-     *
97
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
98
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
99
-     * @return integer                 in the currency's subunit
100
-     * @throws InvalidDataTypeException
101
-     */
102
-    private function parseAmount($amount)
103
-    {
104
-        if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
105
-            throw new InvalidDataTypeException(
106
-                '$amount',
107
-                $amount,
108
-                'integer (or float or string)'
109
-            );
110
-        }
111
-        if ($this->currency->decimalMark() !== '.') {
112
-            // remove thousands separator and replace decimal place with standard decimal.
113
-            $amount = str_replace(
114
-                array(
115
-                    $this->currency->thousands(),
116
-                    $this->currency->decimalMark(),
117
-                ),
118
-                array(
119
-                    '',
120
-                    '.',
121
-                ),
122
-                $amount
123
-            );
124
-        }
125
-        // remove any non numeric values but leave the decimal
126
-        $amount = (float) preg_replace('/([^0-9\\.])/', '', $amount);
127
-        // shift the decimal position by the number of decimal places used internally
128
-        // ex: 12.5 for a currency using 2 decimal places, would become 1250
129
-        // then if our extra internal precision was 3, it would become 1250000
130
-        $amount *= pow(10, $this->precision());
131
-        // then round up the remaining value if there is still a fractional amount left
132
-        $amount = round($amount);
133
-        return (int)$amount;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
140
-     *
141
-     * @param bool $positive
142
-     * @return integer
143
-     */
144
-    private function precision($positive = true)
145
-    {
146
-        $sign = $positive ? 1 : -1;
147
-        return ((int) $this->currency->subunitOrderOfMagnitudeDiff() + Money::EXTRA_PRECISION) * $sign;
148
-    }
149
-
150
-
151
-
152
-    /**
153
-     * Returns the money amount as an unformatted string
154
-     * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
155
-     * In the currency's standard units
156
-     *
157
-     * @return string
158
-     */
159
-    public function amount()
160
-    {
161
-        // shift the decimal position BACK by the number of decimal places used internally
162
-        // ex: 1250 for a currency using 2 decimal places, would become 12.50
163
-        $amount = (string) $this->amount * pow(10, $this->precision(false));
164
-        // then shave off our extra internal precision using the number of decimal places for the currency
165
-        $amount = round($amount, $this->currency->subunitOrderOfMagnitudeDiff());
166
-        return (string) $amount;
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * Returns the money SUBUNITS amount as an INTEGER
173
-     *
174
-     * @return integer
175
-     */
176
-    public function amountInSubunits()
177
-    {
178
-        // shift the decimal position BACK by the number of decimal places used internally
179
-        // for extra internal precision, but NOT for the number of decimals used by the currency
180
-        // ex: if our extra internal precision was 3, then 1250000 would become 1250
181
-        // and even if the currency used 2 decimal places, we would return 1250 and NOT 12.50
182
-        $amount = (string) $this->amount * pow(10, Money::EXTRA_PRECISION * -1);
183
-        // then shave off anything after the decimal
184
-        $amount = round($amount);
185
-        return (int) $amount;
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * applies formatting based on the specified formatting level
192
-     * corresponding to one of the constants on MoneyFormatter
193
-     *
194
-     * @param int $formatting_level
195
-     * @return string
196
-     */
197
-    public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS)
198
-    {
199
-        $formatted_amount = $this->amount();
200
-        $formatters       = $this->formatters();
201
-        // if we are applying thousands formatting...
202
-        if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) {
203
-            // then let's remove decimal formatting since it's included in thousands formatting
204
-            unset($formatters[ MoneyFormatter::DECIMAL_ONLY ]);
205
-        }
206
-        for ($x = 1; $x <= $formatting_level; $x++) {
207
-            if (isset($formatters[ $x ]) && $formatters[ $x ] instanceof MoneyFormatter) {
208
-                $formatted_amount = $formatters[ $x ]->format($formatted_amount, $this->currency);
209
-            }
210
-        }
211
-        return (string) apply_filters(
212
-            'FHEE__EventEspresso_core_domain_values_currency_Money__format__formatted_amount',
213
-            $formatted_amount,
214
-            $this
215
-        );
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * Returns the Currency object for this money
222
-     *
223
-     * @return Currency
224
-     */
225
-    public function currency()
226
-    {
227
-        return $this->currency;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * adds the supplied Money amount to this Money amount
234
-     * and returns a new Money object
235
-     *
236
-     * @param Money $other
237
-     * @return Money
238
-     * @throws InvalidArgumentException
239
-     */
240
-    public function add(Money $other)
241
-    {
242
-        $this->verifySameCurrency($other->currency());
243
-        return new Money(
244
-            $this->calculator()->add(
245
-                $this->amount(),
246
-                $other->amount()
247
-            ),
248
-            $this->currency(),
249
-            $this->calculator(),
250
-            $this->formatters()
251
-        );
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * subtracts the supplied Money amount from this Money amount
258
-     * and returns a new Money object
259
-     *
260
-     * @param Money $other
261
-     * @return Money
262
-     * @throws InvalidArgumentException
263
-     */
264
-    public function subtract(Money $other)
265
-    {
266
-        $this->verifySameCurrency($other->currency());
267
-        return new Money(
268
-            $this->calculator()->subtract(
269
-                $this->amount(),
270
-                $other->amount()
271
-            ),
272
-            $this->currency(),
273
-            $this->calculator(),
274
-            $this->formatters()
275
-        );
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * multiplies this Money amount by the supplied $multiplier
282
-     * and returns a new Money object
283
-     *
284
-     * @param float|int|string $multiplier
285
-     * @param int              $rounding_mode
286
-     * @return Money
287
-     * @throws InvalidDataTypeException
288
-     */
289
-    public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
290
-    {
291
-        return new Money(
292
-            $this->calculator()->multiply(
293
-                $this->amount(),
294
-                $multiplier,
295
-                $this->precision(),
296
-                $rounding_mode
297
-            ),
298
-            $this->currency(),
299
-            $this->calculator(),
300
-            $this->formatters()
301
-        );
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * divides this Money amount by the supplied $divisor
308
-     * and returns a new Money object
309
-     *
310
-     * @param float|int|string $divisor
311
-     * @param int              $rounding_mode
312
-     * @return Money
313
-     * @throws InvalidDataTypeException
314
-     */
315
-    public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
316
-    {
317
-        return new Money(
318
-            $this->calculator()->divide(
319
-                $this->amount(),
320
-                $divisor,
321
-                $this->precision(),
322
-                $rounding_mode
323
-            ),
324
-            $this->currency(),
325
-            $this->calculator(),
326
-            $this->formatters()
327
-        );
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * @param Currency $other_currency
334
-     * @throws InvalidArgumentException
335
-     */
336
-    public function verifySameCurrency(Currency $other_currency)
337
-    {
338
-        if ($this->currency()->equals($other_currency) !== true) {
339
-            throw new InvalidArgumentException(
340
-                esc_html__(
341
-                    'Currencies must be the same in order to add or subtract their values.',
342
-                    'event_espresso'
343
-                )
344
-            );
345
-        }
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * @return string
352
-     */
353
-    public function __toString()
354
-    {
355
-        return $this->format(MoneyFormatter::DECIMAL_ONLY);
356
-    }
25
+	/**
26
+	 * number of decimal places to be added to currencies for internal computations,
27
+	 * but removed before any output or formatting is applied.
28
+	 * This allows us to avoid rounding errors during calculations.
29
+	 */
30
+	const EXTRA_PRECISION = 3;
31
+
32
+	/**
33
+	 * @var int $amount
34
+	 */
35
+	private $amount;
36
+
37
+	/**
38
+	 * @var Currency $currency
39
+	 */
40
+	private $currency;
41
+
42
+	/**
43
+	 * @var Calculator $calculator
44
+	 */
45
+	protected $calculator;
46
+
47
+	/**
48
+	 * @var MoneyFormatter[] $formatters
49
+	 */
50
+	protected $formatters;
51
+
52
+
53
+
54
+	/**
55
+	 * Money constructor.
56
+	 *
57
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
58
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
59
+	 * @param Currency         $currency
60
+	 * @param Calculator       $calculator
61
+	 * @param MoneyFormatter[] $formatters
62
+	 * @throws InvalidDataTypeException
63
+	 */
64
+	public function __construct($amount, Currency $currency, Calculator $calculator, array $formatters)
65
+	{
66
+		$this->currency   = $currency;
67
+		$this->amount     = $this->parseAmount($amount);
68
+		$this->calculator = $calculator;
69
+		$this->formatters = $formatters;
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * @return Calculator
76
+	 */
77
+	protected function calculator()
78
+	{
79
+		return $this->calculator;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * @return MoneyFormatter[]
86
+	 */
87
+	protected function formatters()
88
+	{
89
+		return $this->formatters;
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * Convert's a standard unit amount into the subunits of the currency
96
+	 *
97
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
98
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
99
+	 * @return integer                 in the currency's subunit
100
+	 * @throws InvalidDataTypeException
101
+	 */
102
+	private function parseAmount($amount)
103
+	{
104
+		if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
105
+			throw new InvalidDataTypeException(
106
+				'$amount',
107
+				$amount,
108
+				'integer (or float or string)'
109
+			);
110
+		}
111
+		if ($this->currency->decimalMark() !== '.') {
112
+			// remove thousands separator and replace decimal place with standard decimal.
113
+			$amount = str_replace(
114
+				array(
115
+					$this->currency->thousands(),
116
+					$this->currency->decimalMark(),
117
+				),
118
+				array(
119
+					'',
120
+					'.',
121
+				),
122
+				$amount
123
+			);
124
+		}
125
+		// remove any non numeric values but leave the decimal
126
+		$amount = (float) preg_replace('/([^0-9\\.])/', '', $amount);
127
+		// shift the decimal position by the number of decimal places used internally
128
+		// ex: 12.5 for a currency using 2 decimal places, would become 1250
129
+		// then if our extra internal precision was 3, it would become 1250000
130
+		$amount *= pow(10, $this->precision());
131
+		// then round up the remaining value if there is still a fractional amount left
132
+		$amount = round($amount);
133
+		return (int)$amount;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
140
+	 *
141
+	 * @param bool $positive
142
+	 * @return integer
143
+	 */
144
+	private function precision($positive = true)
145
+	{
146
+		$sign = $positive ? 1 : -1;
147
+		return ((int) $this->currency->subunitOrderOfMagnitudeDiff() + Money::EXTRA_PRECISION) * $sign;
148
+	}
149
+
150
+
151
+
152
+	/**
153
+	 * Returns the money amount as an unformatted string
154
+	 * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
155
+	 * In the currency's standard units
156
+	 *
157
+	 * @return string
158
+	 */
159
+	public function amount()
160
+	{
161
+		// shift the decimal position BACK by the number of decimal places used internally
162
+		// ex: 1250 for a currency using 2 decimal places, would become 12.50
163
+		$amount = (string) $this->amount * pow(10, $this->precision(false));
164
+		// then shave off our extra internal precision using the number of decimal places for the currency
165
+		$amount = round($amount, $this->currency->subunitOrderOfMagnitudeDiff());
166
+		return (string) $amount;
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * Returns the money SUBUNITS amount as an INTEGER
173
+	 *
174
+	 * @return integer
175
+	 */
176
+	public function amountInSubunits()
177
+	{
178
+		// shift the decimal position BACK by the number of decimal places used internally
179
+		// for extra internal precision, but NOT for the number of decimals used by the currency
180
+		// ex: if our extra internal precision was 3, then 1250000 would become 1250
181
+		// and even if the currency used 2 decimal places, we would return 1250 and NOT 12.50
182
+		$amount = (string) $this->amount * pow(10, Money::EXTRA_PRECISION * -1);
183
+		// then shave off anything after the decimal
184
+		$amount = round($amount);
185
+		return (int) $amount;
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * applies formatting based on the specified formatting level
192
+	 * corresponding to one of the constants on MoneyFormatter
193
+	 *
194
+	 * @param int $formatting_level
195
+	 * @return string
196
+	 */
197
+	public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS)
198
+	{
199
+		$formatted_amount = $this->amount();
200
+		$formatters       = $this->formatters();
201
+		// if we are applying thousands formatting...
202
+		if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) {
203
+			// then let's remove decimal formatting since it's included in thousands formatting
204
+			unset($formatters[ MoneyFormatter::DECIMAL_ONLY ]);
205
+		}
206
+		for ($x = 1; $x <= $formatting_level; $x++) {
207
+			if (isset($formatters[ $x ]) && $formatters[ $x ] instanceof MoneyFormatter) {
208
+				$formatted_amount = $formatters[ $x ]->format($formatted_amount, $this->currency);
209
+			}
210
+		}
211
+		return (string) apply_filters(
212
+			'FHEE__EventEspresso_core_domain_values_currency_Money__format__formatted_amount',
213
+			$formatted_amount,
214
+			$this
215
+		);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * Returns the Currency object for this money
222
+	 *
223
+	 * @return Currency
224
+	 */
225
+	public function currency()
226
+	{
227
+		return $this->currency;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * adds the supplied Money amount to this Money amount
234
+	 * and returns a new Money object
235
+	 *
236
+	 * @param Money $other
237
+	 * @return Money
238
+	 * @throws InvalidArgumentException
239
+	 */
240
+	public function add(Money $other)
241
+	{
242
+		$this->verifySameCurrency($other->currency());
243
+		return new Money(
244
+			$this->calculator()->add(
245
+				$this->amount(),
246
+				$other->amount()
247
+			),
248
+			$this->currency(),
249
+			$this->calculator(),
250
+			$this->formatters()
251
+		);
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * subtracts the supplied Money amount from this Money amount
258
+	 * and returns a new Money object
259
+	 *
260
+	 * @param Money $other
261
+	 * @return Money
262
+	 * @throws InvalidArgumentException
263
+	 */
264
+	public function subtract(Money $other)
265
+	{
266
+		$this->verifySameCurrency($other->currency());
267
+		return new Money(
268
+			$this->calculator()->subtract(
269
+				$this->amount(),
270
+				$other->amount()
271
+			),
272
+			$this->currency(),
273
+			$this->calculator(),
274
+			$this->formatters()
275
+		);
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * multiplies this Money amount by the supplied $multiplier
282
+	 * and returns a new Money object
283
+	 *
284
+	 * @param float|int|string $multiplier
285
+	 * @param int              $rounding_mode
286
+	 * @return Money
287
+	 * @throws InvalidDataTypeException
288
+	 */
289
+	public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
290
+	{
291
+		return new Money(
292
+			$this->calculator()->multiply(
293
+				$this->amount(),
294
+				$multiplier,
295
+				$this->precision(),
296
+				$rounding_mode
297
+			),
298
+			$this->currency(),
299
+			$this->calculator(),
300
+			$this->formatters()
301
+		);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * divides this Money amount by the supplied $divisor
308
+	 * and returns a new Money object
309
+	 *
310
+	 * @param float|int|string $divisor
311
+	 * @param int              $rounding_mode
312
+	 * @return Money
313
+	 * @throws InvalidDataTypeException
314
+	 */
315
+	public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
316
+	{
317
+		return new Money(
318
+			$this->calculator()->divide(
319
+				$this->amount(),
320
+				$divisor,
321
+				$this->precision(),
322
+				$rounding_mode
323
+			),
324
+			$this->currency(),
325
+			$this->calculator(),
326
+			$this->formatters()
327
+		);
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * @param Currency $other_currency
334
+	 * @throws InvalidArgumentException
335
+	 */
336
+	public function verifySameCurrency(Currency $other_currency)
337
+	{
338
+		if ($this->currency()->equals($other_currency) !== true) {
339
+			throw new InvalidArgumentException(
340
+				esc_html__(
341
+					'Currencies must be the same in order to add or subtract their values.',
342
+					'event_espresso'
343
+				)
344
+			);
345
+		}
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * @return string
352
+	 */
353
+	public function __toString()
354
+	{
355
+		return $this->format(MoneyFormatter::DECIMAL_ONLY);
356
+	}
357 357
 }
358 358
 // End of file Money.php
359 359
 // Location: core/entities/money/Money.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     private function parseAmount($amount)
103 103
     {
104
-        if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
104
+        if ( ! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
105 105
             throw new InvalidDataTypeException(
106 106
                 '$amount',
107 107
                 $amount,
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         $amount *= pow(10, $this->precision());
131 131
         // then round up the remaining value if there is still a fractional amount left
132 132
         $amount = round($amount);
133
-        return (int)$amount;
133
+        return (int) $amount;
134 134
     }
135 135
 
136 136
 
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
         // if we are applying thousands formatting...
202 202
         if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) {
203 203
             // then let's remove decimal formatting since it's included in thousands formatting
204
-            unset($formatters[ MoneyFormatter::DECIMAL_ONLY ]);
204
+            unset($formatters[MoneyFormatter::DECIMAL_ONLY]);
205 205
         }
206 206
         for ($x = 1; $x <= $formatting_level; $x++) {
207
-            if (isset($formatters[ $x ]) && $formatters[ $x ] instanceof MoneyFormatter) {
208
-                $formatted_amount = $formatters[ $x ]->format($formatted_amount, $this->currency);
207
+            if (isset($formatters[$x]) && $formatters[$x] instanceof MoneyFormatter) {
208
+                $formatted_amount = $formatters[$x]->format($formatted_amount, $this->currency);
209 209
             }
210 210
         }
211 211
         return (string) apply_filters(
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +809 added lines, -809 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderInterface;
6 6
 
7 7
 if (! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -22,814 +22,814 @@  discard block
 block discarded – undo
22 22
 class EE_Dependency_Map
23 23
 {
24 24
 
25
-    /**
26
-     * This means that the requested class dependency is not present in the dependency map
27
-     */
28
-    const not_registered = 0;
29
-
30
-    /**
31
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
-     */
33
-    const load_new_object = 1;
34
-
35
-    /**
36
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
-     */
39
-    const load_from_cache = 2;
40
-
41
-    /**
42
-     * When registering a dependency,
43
-     * this indicates to keep any existing dependencies that already exist,
44
-     * and simply discard any new dependencies declared in the incoming data
45
-     */
46
-    const KEEP_EXISTING_DEPENDENCIES = 0;
47
-
48
-    /**
49
-     * When registering a dependency,
50
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
-     */
52
-    const OVERWRITE_DEPENDENCIES = 1;
53
-
54
-
55
-
56
-    /**
57
-     * @type EE_Dependency_Map $_instance
58
-     */
59
-    protected static $_instance;
60
-
61
-    /**
62
-     * @type EE_Request $request
63
-     */
64
-    protected $_request;
65
-
66
-    /**
67
-     * @type EE_Response $response
68
-     */
69
-    protected $_response;
70
-
71
-    /**
72
-     * @type LoaderInterface $loader
73
-     */
74
-    protected $loader;
75
-
76
-    /**
77
-     * @type array $_dependency_map
78
-     */
79
-    protected $_dependency_map = array();
80
-
81
-    /**
82
-     * @type array $_class_loaders
83
-     */
84
-    protected $_class_loaders = array();
85
-
86
-    /**
87
-     * @type array $_aliases
88
-     */
89
-    protected $_aliases = array();
90
-
91
-
92
-
93
-    /**
94
-     * EE_Dependency_Map constructor.
95
-     *
96
-     * @param EE_Request  $request
97
-     * @param EE_Response $response
98
-     */
99
-    protected function __construct(EE_Request $request, EE_Response $response)
100
-    {
101
-        $this->_request = $request;
102
-        $this->_response = $response;
103
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
-        do_action('EE_Dependency_Map____construct');
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     * @throws InvalidArgumentException
113
-     */
114
-    public function initialize()
115
-    {
116
-        $this->_register_core_dependencies();
117
-        $this->_register_core_class_loaders();
118
-        $this->_register_core_aliases();
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @singleton method used to instantiate class object
125
-     * @access    public
126
-     * @param EE_Request  $request
127
-     * @param EE_Response $response
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
131
-    {
132
-        // check if class object is instantiated, and instantiated properly
133
-        if (! self::$_instance instanceof EE_Dependency_Map) {
134
-            self::$_instance = new EE_Dependency_Map($request, $response);
135
-        }
136
-        return self::$_instance;
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @param LoaderInterface $loader
143
-     */
144
-    public function setLoader(LoaderInterface $loader)
145
-    {
146
-        $this->loader = $loader;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param string $class
153
-     * @param array  $dependencies
154
-     * @param int    $overwrite
155
-     * @return bool
156
-     */
157
-    public static function register_dependencies(
158
-        $class,
159
-        array $dependencies,
160
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
-    ) {
162
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Assigns an array of class names and corresponding load sources (new or cached)
169
-     * to the class specified by the first parameter.
170
-     * IMPORTANT !!!
171
-     * The order of elements in the incoming $dependencies array MUST match
172
-     * the order of the constructor parameters for the class in question.
173
-     * This is especially important when overriding any existing dependencies that are registered.
174
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
-     *
176
-     * @param string $class
177
-     * @param array  $dependencies
178
-     * @param int    $overwrite
179
-     * @return bool
180
-     */
181
-    public function registerDependencies(
182
-        $class,
183
-        array $dependencies,
184
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
-    ) {
186
-        $class = trim($class, '\\');
187
-        $registered = false;
188
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
189
-            self::$_instance->_dependency_map[ $class ] = array();
190
-        }
191
-        // we need to make sure that any aliases used when registering a dependency
192
-        // get resolved to the correct class name
193
-        foreach ((array)$dependencies as $dependency => $load_source) {
194
-            $alias = self::$_instance->get_alias($dependency);
195
-            if (
196
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
-            ) {
199
-                unset($dependencies[$dependency]);
200
-                $dependencies[$alias] = $load_source;
201
-                $registered = true;
202
-            }
203
-        }
204
-        // now add our two lists of dependencies together.
205
-        // using Union (+=) favours the arrays in precedence from left to right,
206
-        // so $dependencies is NOT overwritten because it is listed first
207
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
-        // Union is way faster than array_merge() but should be used with caution...
209
-        // especially with numerically indexed arrays
210
-        $dependencies += self::$_instance->_dependency_map[ $class ];
211
-        // now we need to ensure that the resulting dependencies
212
-        // array only has the entries that are required for the class
213
-        // so first count how many dependencies were originally registered for the class
214
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
-        // if that count is non-zero (meaning dependencies were already registered)
216
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
217
-            // then truncate the  final array to match that count
218
-            ? array_slice($dependencies, 0, $dependency_count)
219
-            // otherwise just take the incoming array because nothing previously existed
220
-            : $dependencies;
221
-        return $registered;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * @param string $class_name
228
-     * @param string $loader
229
-     * @return bool
230
-     * @throws DomainException
231
-     */
232
-    public static function register_class_loader($class_name, $loader = 'load_core')
233
-    {
234
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
-            throw new DomainException(
236
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
-            );
238
-        }
239
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
240
-        if (
241
-            ! is_callable($loader)
242
-            && (
243
-                strpos($loader, 'load_') !== 0
244
-                || ! method_exists('EE_Registry', $loader)
245
-            )
246
-        ) {
247
-            throw new DomainException(
248
-                sprintf(
249
-                    esc_html__(
250
-                        '"%1$s" is not a valid loader method on EE_Registry.',
251
-                        'event_espresso'
252
-                    ),
253
-                    $loader
254
-                )
255
-            );
256
-        }
257
-        $class_name = self::$_instance->get_alias($class_name);
258
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
-            self::$_instance->_class_loaders[$class_name] = $loader;
260
-            return true;
261
-        }
262
-        return false;
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * @return array
269
-     */
270
-    public function dependency_map()
271
-    {
272
-        return $this->_dependency_map;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * returns TRUE if dependency map contains a listing for the provided class name
279
-     *
280
-     * @param string $class_name
281
-     * @return boolean
282
-     */
283
-    public function has($class_name = '')
284
-    {
285
-        // all legacy models have the same dependencies
286
-        if (strpos($class_name, 'EEM_') === 0) {
287
-            $class_name = 'LEGACY_MODELS';
288
-        }
289
-        return isset($this->_dependency_map[$class_name]) ? true : false;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
-     *
297
-     * @param string $class_name
298
-     * @param string $dependency
299
-     * @return bool
300
-     */
301
-    public function has_dependency_for_class($class_name = '', $dependency = '')
302
-    {
303
-        // all legacy models have the same dependencies
304
-        if (strpos($class_name, 'EEM_') === 0) {
305
-            $class_name = 'LEGACY_MODELS';
306
-        }
307
-        $dependency = $this->get_alias($dependency);
308
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
-            ? true
310
-            : false;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
-     *
318
-     * @param string $class_name
319
-     * @param string $dependency
320
-     * @return int
321
-     */
322
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
-    {
324
-        // all legacy models have the same dependencies
325
-        if (strpos($class_name, 'EEM_') === 0) {
326
-            $class_name = 'LEGACY_MODELS';
327
-        }
328
-        $dependency = $this->get_alias($dependency);
329
-        return $this->has_dependency_for_class($class_name, $dependency)
330
-            ? $this->_dependency_map[$class_name][$dependency]
331
-            : EE_Dependency_Map::not_registered;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param string $class_name
338
-     * @return string | Closure
339
-     */
340
-    public function class_loader($class_name)
341
-    {
342
-        // all legacy models use load_model()
343
-        if(strpos($class_name, 'EEM_') === 0){
344
-            return 'load_model';
345
-        }
346
-        $class_name = $this->get_alias($class_name);
347
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @return array
354
-     */
355
-    public function class_loaders()
356
-    {
357
-        return $this->_class_loaders;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * adds an alias for a classname
364
-     *
365
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
366
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
-     */
369
-    public function add_alias($class_name, $alias, $for_class = '')
370
-    {
371
-        if ($for_class !== '') {
372
-            if (! isset($this->_aliases[$for_class])) {
373
-                $this->_aliases[$for_class] = array();
374
-            }
375
-            $this->_aliases[$for_class][$class_name] = $alias;
376
-        }
377
-        $this->_aliases[$class_name] = $alias;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * returns TRUE if the provided class name has an alias
384
-     *
385
-     * @param string $class_name
386
-     * @param string $for_class
387
-     * @return bool
388
-     */
389
-    public function has_alias($class_name = '', $for_class = '')
390
-    {
391
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
-               || (
393
-                   isset($this->_aliases[$class_name])
394
-                   && ! is_array($this->_aliases[$class_name])
395
-               );
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * returns alias for class name if one exists, otherwise returns the original classname
402
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
403
-     *  for example:
404
-     *      if the following two entries were added to the _aliases array:
405
-     *          array(
406
-     *              'interface_alias'           => 'some\namespace\interface'
407
-     *              'some\namespace\interface'  => 'some\namespace\classname'
408
-     *          )
409
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
-     *      to load an instance of 'some\namespace\classname'
411
-     *
412
-     * @param string $class_name
413
-     * @param string $for_class
414
-     * @return string
415
-     */
416
-    public function get_alias($class_name = '', $for_class = '')
417
-    {
418
-        if (! $this->has_alias($class_name, $for_class)) {
419
-            return $class_name;
420
-        }
421
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
-        }
424
-        return $this->get_alias($this->_aliases[$class_name]);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
-     * This is done by using the following class constants:
433
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
435
-     */
436
-    protected function _register_core_dependencies()
437
-    {
438
-        $this->_dependency_map = array(
439
-            'EE_Request_Handler'                                                                                          => array(
440
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EE_System'                                                                                                   => array(
443
-                'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
-                'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
-                'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
-                'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_Session'                                                                                                  => array(
450
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
-            ),
453
-            'EE_Cart'                                                                                                     => array(
454
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
455
-            ),
456
-            'EE_Front_Controller'                                                                                         => array(
457
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
-            ),
461
-            'EE_Messenger_Collection_Loader'                                                                              => array(
462
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
-            ),
464
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
465
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
-            ),
467
-            'EE_Message_Resource_Manager'                                                                                 => array(
468
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
-            ),
472
-            'EE_Message_Factory'                                                                                          => array(
473
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
-            ),
475
-            'EE_messages'                                                                                                 => array(
476
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
-            ),
478
-            'EE_Messages_Generator'                                                                                       => array(
479
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_Messages_Processor'                                                                                       => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Queue'                                                                                           => array(
488
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
-            ),
490
-            'EE_Messages_Template_Defaults'                                                                               => array(
491
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
495
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
-            ),
498
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
-            ),
501
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
-            ),
512
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
-            ),
515
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
552
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EE_Data_Migration_Class_Base'                                                                                => array(
555
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
-            ),
558
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
559
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
-            ),
562
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
563
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
567
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
-            ),
570
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
571
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
-            ),
574
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
575
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
-            ),
604
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
-            ),
616
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
-            ),
619
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
620
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
-            ),
622
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
623
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
-            ),
625
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
626
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
627
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
630
-                null,
631
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
632
-            ),
633
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
634
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
635
-            ),
636
-            'LEGACY_MODELS'                                                   => array(
637
-                null,
638
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EE_Module_Request_Router' => array(
641
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EE_Registration_Processor' => array(
644
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\services\currency\CurrencyFactory' => array(
647
-                'EEM_Country'                                           => EE_Dependency_Map::load_from_cache,
648
-                'EE_Organization_Config'                                => EE_Dependency_Map::load_from_cache,
649
-                'EventEspresso\core\services\currency\CurrencySubunits' => EE_Dependency_Map::load_from_cache
650
-            ),
651
-            'EventEspresso\core\services\currency\MoneyFactory' => array(
652
-                'EventEspresso\core\services\currency\CurrencyFactory'  => EE_Dependency_Map::load_from_cache,
653
-                'EventEspresso\core\services\currency\Calculator'       => EE_Dependency_Map::load_from_cache,
654
-                array(),
655
-            ),
656
-        );
657
-    }
658
-
659
-
660
-
661
-    /**
662
-     * Registers how core classes are loaded.
663
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
664
-     *        'EE_Request_Handler' => 'load_core'
665
-     *        'EE_Messages_Queue'  => 'load_lib'
666
-     *        'EEH_Debug_Tools'    => 'load_helper'
667
-     * or, if greater control is required, by providing a custom closure. For example:
668
-     *        'Some_Class' => function () {
669
-     *            return new Some_Class();
670
-     *        },
671
-     * This is required for instantiating dependencies
672
-     * where an interface has been type hinted in a class constructor. For example:
673
-     *        'Required_Interface' => function () {
674
-     *            return new A_Class_That_Implements_Required_Interface();
675
-     *        },
676
-     *
677
-     * @throws InvalidInterfaceException
678
-     * @throws InvalidDataTypeException
679
-     * @throws InvalidArgumentException
680
-     */
681
-    protected function _register_core_class_loaders()
682
-    {
683
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
684
-        //be used in a closure.
685
-        $request = &$this->_request;
686
-        $response = &$this->_response;
687
-        // $loader = &$this->loader;
688
-        $this->_class_loaders = array(
689
-            //load_core
690
-            'EE_Capabilities'                      => 'load_core',
691
-            'EE_Encryption'                        => 'load_core',
692
-            'EE_Front_Controller'                  => 'load_core',
693
-            'EE_Module_Request_Router'             => 'load_core',
694
-            'EE_Registry'                          => 'load_core',
695
-            'EE_Request'                           => function () use (&$request) {
696
-                return $request;
697
-            },
698
-            'EE_Response'                          => function () use (&$response) {
699
-                return $response;
700
-            },
701
-            'EE_Request_Handler'                   => 'load_core',
702
-            'EE_Session'                           => 'load_core',
703
-            'EE_Cron_Tasks'                        => 'load_core',
704
-            'EE_System'                            => 'load_core',
705
-            'EE_Maintenance_Mode'                  => 'load_core',
706
-            'EE_Register_CPTs'                     => 'load_core',
707
-            'EE_Admin'                             => 'load_core',
708
-            //load_lib
709
-            'EE_Message_Resource_Manager'          => 'load_lib',
710
-            'EE_Message_Type_Collection'           => 'load_lib',
711
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
712
-            'EE_Messenger_Collection'              => 'load_lib',
713
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
714
-            'EE_Messages_Processor'                => 'load_lib',
715
-            'EE_Message_Repository'                => 'load_lib',
716
-            'EE_Messages_Queue'                    => 'load_lib',
717
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
718
-            'EE_Message_Template_Group_Collection' => 'load_lib',
719
-            'EE_Payment_Method_Manager'            => 'load_lib',
720
-            'EE_Messages_Generator'                => function () {
721
-                return EE_Registry::instance()->load_lib(
722
-                    'Messages_Generator',
723
-                    array(),
724
-                    false,
725
-                    false
726
-                );
727
-            },
728
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
729
-                return EE_Registry::instance()->load_lib(
730
-                    'Messages_Template_Defaults',
731
-                    $arguments,
732
-                    false,
733
-                    false
734
-                );
735
-            },
736
-            //load_model
737
-            // 'EEM_Attendee'                         => 'load_model',
738
-            // 'EEM_Message_Template_Group'           => 'load_model',
739
-            // 'EEM_Message_Template'                 => 'load_model',
740
-            //load_helper
741
-            'EEH_Parse_Shortcodes'                 => function () {
742
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
743
-                    return new EEH_Parse_Shortcodes();
744
-                }
745
-                return null;
746
-            },
747
-            'EE_Template_Config'                   => function () {
748
-                return EE_Config::instance()->template_settings;
749
-            },
750
-            'EE_Currency_Config'                   => function () {
751
-                return EE_Config::instance()->currency;
752
-            },
753
-            'EE_Registration_Config'                   => function () {
754
-                return EE_Config::instance()->registration;
755
-            },
756
-            'EE_Organization_Config'                   => function () {
757
-                return EE_Config::instance()->organization;
758
-            },
759
-            'EventEspresso\core\services\loaders\Loader' => function () {
760
-                return LoaderFactory::getLoader();
761
-            },
762
-        );
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * can be used for supplying alternate names for classes,
769
-     * or for connecting interface names to instantiable classes
770
-     */
771
-    protected function _register_core_aliases()
772
-    {
773
-        $this->_aliases = array(
774
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
775
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
776
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
777
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
778
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
779
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
780
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
781
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
782
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
783
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
784
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
785
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
786
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
787
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
788
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
789
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
790
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
791
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
792
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
793
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
794
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
795
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
796
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
797
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
798
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
799
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
800
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
801
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
802
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
803
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
804
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
805
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
806
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
807
-            'NoticeConverterInterface'                                                    => 'EventEspresso\core\services\notices\NoticeConverterInterface',
808
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
809
-            'NoticesContainerInterface'                                                   => 'EventEspresso\core\services\notices\NoticesContainerInterface',
810
-            'EventEspresso\core\services\notices\NoticesContainerInterface'               => 'EventEspresso\core\services\notices\NoticesContainer',
811
-            'EventEspresso\core\services\currency\Calculator'                             => 'EventEspresso\core\services\currency\DefaultCalculator',
812
-        );
813
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
814
-            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
815
-        }
816
-    }
817
-
818
-
819
-
820
-    /**
821
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
822
-     * request Primarily used by unit tests.
823
-     *
824
-     * @throws InvalidDataTypeException
825
-     * @throws InvalidInterfaceException
826
-     * @throws InvalidArgumentException
827
-     */
828
-    public function reset()
829
-    {
830
-        $this->_register_core_class_loaders();
831
-        $this->_register_core_dependencies();
832
-    }
25
+	/**
26
+	 * This means that the requested class dependency is not present in the dependency map
27
+	 */
28
+	const not_registered = 0;
29
+
30
+	/**
31
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
+	 */
33
+	const load_new_object = 1;
34
+
35
+	/**
36
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
+	 */
39
+	const load_from_cache = 2;
40
+
41
+	/**
42
+	 * When registering a dependency,
43
+	 * this indicates to keep any existing dependencies that already exist,
44
+	 * and simply discard any new dependencies declared in the incoming data
45
+	 */
46
+	const KEEP_EXISTING_DEPENDENCIES = 0;
47
+
48
+	/**
49
+	 * When registering a dependency,
50
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
+	 */
52
+	const OVERWRITE_DEPENDENCIES = 1;
53
+
54
+
55
+
56
+	/**
57
+	 * @type EE_Dependency_Map $_instance
58
+	 */
59
+	protected static $_instance;
60
+
61
+	/**
62
+	 * @type EE_Request $request
63
+	 */
64
+	protected $_request;
65
+
66
+	/**
67
+	 * @type EE_Response $response
68
+	 */
69
+	protected $_response;
70
+
71
+	/**
72
+	 * @type LoaderInterface $loader
73
+	 */
74
+	protected $loader;
75
+
76
+	/**
77
+	 * @type array $_dependency_map
78
+	 */
79
+	protected $_dependency_map = array();
80
+
81
+	/**
82
+	 * @type array $_class_loaders
83
+	 */
84
+	protected $_class_loaders = array();
85
+
86
+	/**
87
+	 * @type array $_aliases
88
+	 */
89
+	protected $_aliases = array();
90
+
91
+
92
+
93
+	/**
94
+	 * EE_Dependency_Map constructor.
95
+	 *
96
+	 * @param EE_Request  $request
97
+	 * @param EE_Response $response
98
+	 */
99
+	protected function __construct(EE_Request $request, EE_Response $response)
100
+	{
101
+		$this->_request = $request;
102
+		$this->_response = $response;
103
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
+		do_action('EE_Dependency_Map____construct');
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 * @throws InvalidArgumentException
113
+	 */
114
+	public function initialize()
115
+	{
116
+		$this->_register_core_dependencies();
117
+		$this->_register_core_class_loaders();
118
+		$this->_register_core_aliases();
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @singleton method used to instantiate class object
125
+	 * @access    public
126
+	 * @param EE_Request  $request
127
+	 * @param EE_Response $response
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
131
+	{
132
+		// check if class object is instantiated, and instantiated properly
133
+		if (! self::$_instance instanceof EE_Dependency_Map) {
134
+			self::$_instance = new EE_Dependency_Map($request, $response);
135
+		}
136
+		return self::$_instance;
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @param LoaderInterface $loader
143
+	 */
144
+	public function setLoader(LoaderInterface $loader)
145
+	{
146
+		$this->loader = $loader;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param string $class
153
+	 * @param array  $dependencies
154
+	 * @param int    $overwrite
155
+	 * @return bool
156
+	 */
157
+	public static function register_dependencies(
158
+		$class,
159
+		array $dependencies,
160
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
+	) {
162
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Assigns an array of class names and corresponding load sources (new or cached)
169
+	 * to the class specified by the first parameter.
170
+	 * IMPORTANT !!!
171
+	 * The order of elements in the incoming $dependencies array MUST match
172
+	 * the order of the constructor parameters for the class in question.
173
+	 * This is especially important when overriding any existing dependencies that are registered.
174
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
+	 *
176
+	 * @param string $class
177
+	 * @param array  $dependencies
178
+	 * @param int    $overwrite
179
+	 * @return bool
180
+	 */
181
+	public function registerDependencies(
182
+		$class,
183
+		array $dependencies,
184
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
+	) {
186
+		$class = trim($class, '\\');
187
+		$registered = false;
188
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
189
+			self::$_instance->_dependency_map[ $class ] = array();
190
+		}
191
+		// we need to make sure that any aliases used when registering a dependency
192
+		// get resolved to the correct class name
193
+		foreach ((array)$dependencies as $dependency => $load_source) {
194
+			$alias = self::$_instance->get_alias($dependency);
195
+			if (
196
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
+			) {
199
+				unset($dependencies[$dependency]);
200
+				$dependencies[$alias] = $load_source;
201
+				$registered = true;
202
+			}
203
+		}
204
+		// now add our two lists of dependencies together.
205
+		// using Union (+=) favours the arrays in precedence from left to right,
206
+		// so $dependencies is NOT overwritten because it is listed first
207
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
+		// Union is way faster than array_merge() but should be used with caution...
209
+		// especially with numerically indexed arrays
210
+		$dependencies += self::$_instance->_dependency_map[ $class ];
211
+		// now we need to ensure that the resulting dependencies
212
+		// array only has the entries that are required for the class
213
+		// so first count how many dependencies were originally registered for the class
214
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
+		// if that count is non-zero (meaning dependencies were already registered)
216
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
217
+			// then truncate the  final array to match that count
218
+			? array_slice($dependencies, 0, $dependency_count)
219
+			// otherwise just take the incoming array because nothing previously existed
220
+			: $dependencies;
221
+		return $registered;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * @param string $class_name
228
+	 * @param string $loader
229
+	 * @return bool
230
+	 * @throws DomainException
231
+	 */
232
+	public static function register_class_loader($class_name, $loader = 'load_core')
233
+	{
234
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
+			throw new DomainException(
236
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
+			);
238
+		}
239
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
240
+		if (
241
+			! is_callable($loader)
242
+			&& (
243
+				strpos($loader, 'load_') !== 0
244
+				|| ! method_exists('EE_Registry', $loader)
245
+			)
246
+		) {
247
+			throw new DomainException(
248
+				sprintf(
249
+					esc_html__(
250
+						'"%1$s" is not a valid loader method on EE_Registry.',
251
+						'event_espresso'
252
+					),
253
+					$loader
254
+				)
255
+			);
256
+		}
257
+		$class_name = self::$_instance->get_alias($class_name);
258
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
+			self::$_instance->_class_loaders[$class_name] = $loader;
260
+			return true;
261
+		}
262
+		return false;
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * @return array
269
+	 */
270
+	public function dependency_map()
271
+	{
272
+		return $this->_dependency_map;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * returns TRUE if dependency map contains a listing for the provided class name
279
+	 *
280
+	 * @param string $class_name
281
+	 * @return boolean
282
+	 */
283
+	public function has($class_name = '')
284
+	{
285
+		// all legacy models have the same dependencies
286
+		if (strpos($class_name, 'EEM_') === 0) {
287
+			$class_name = 'LEGACY_MODELS';
288
+		}
289
+		return isset($this->_dependency_map[$class_name]) ? true : false;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
+	 *
297
+	 * @param string $class_name
298
+	 * @param string $dependency
299
+	 * @return bool
300
+	 */
301
+	public function has_dependency_for_class($class_name = '', $dependency = '')
302
+	{
303
+		// all legacy models have the same dependencies
304
+		if (strpos($class_name, 'EEM_') === 0) {
305
+			$class_name = 'LEGACY_MODELS';
306
+		}
307
+		$dependency = $this->get_alias($dependency);
308
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
+			? true
310
+			: false;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
+	 *
318
+	 * @param string $class_name
319
+	 * @param string $dependency
320
+	 * @return int
321
+	 */
322
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
+	{
324
+		// all legacy models have the same dependencies
325
+		if (strpos($class_name, 'EEM_') === 0) {
326
+			$class_name = 'LEGACY_MODELS';
327
+		}
328
+		$dependency = $this->get_alias($dependency);
329
+		return $this->has_dependency_for_class($class_name, $dependency)
330
+			? $this->_dependency_map[$class_name][$dependency]
331
+			: EE_Dependency_Map::not_registered;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param string $class_name
338
+	 * @return string | Closure
339
+	 */
340
+	public function class_loader($class_name)
341
+	{
342
+		// all legacy models use load_model()
343
+		if(strpos($class_name, 'EEM_') === 0){
344
+			return 'load_model';
345
+		}
346
+		$class_name = $this->get_alias($class_name);
347
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @return array
354
+	 */
355
+	public function class_loaders()
356
+	{
357
+		return $this->_class_loaders;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * adds an alias for a classname
364
+	 *
365
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
366
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
+	 */
369
+	public function add_alias($class_name, $alias, $for_class = '')
370
+	{
371
+		if ($for_class !== '') {
372
+			if (! isset($this->_aliases[$for_class])) {
373
+				$this->_aliases[$for_class] = array();
374
+			}
375
+			$this->_aliases[$for_class][$class_name] = $alias;
376
+		}
377
+		$this->_aliases[$class_name] = $alias;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * returns TRUE if the provided class name has an alias
384
+	 *
385
+	 * @param string $class_name
386
+	 * @param string $for_class
387
+	 * @return bool
388
+	 */
389
+	public function has_alias($class_name = '', $for_class = '')
390
+	{
391
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
+			   || (
393
+				   isset($this->_aliases[$class_name])
394
+				   && ! is_array($this->_aliases[$class_name])
395
+			   );
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * returns alias for class name if one exists, otherwise returns the original classname
402
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
403
+	 *  for example:
404
+	 *      if the following two entries were added to the _aliases array:
405
+	 *          array(
406
+	 *              'interface_alias'           => 'some\namespace\interface'
407
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
408
+	 *          )
409
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
+	 *      to load an instance of 'some\namespace\classname'
411
+	 *
412
+	 * @param string $class_name
413
+	 * @param string $for_class
414
+	 * @return string
415
+	 */
416
+	public function get_alias($class_name = '', $for_class = '')
417
+	{
418
+		if (! $this->has_alias($class_name, $for_class)) {
419
+			return $class_name;
420
+		}
421
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
+		}
424
+		return $this->get_alias($this->_aliases[$class_name]);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
+	 * This is done by using the following class constants:
433
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
435
+	 */
436
+	protected function _register_core_dependencies()
437
+	{
438
+		$this->_dependency_map = array(
439
+			'EE_Request_Handler'                                                                                          => array(
440
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EE_System'                                                                                                   => array(
443
+				'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
+				'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
+				'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
+				'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_Session'                                                                                                  => array(
450
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
+			),
453
+			'EE_Cart'                                                                                                     => array(
454
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
455
+			),
456
+			'EE_Front_Controller'                                                                                         => array(
457
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
+			),
461
+			'EE_Messenger_Collection_Loader'                                                                              => array(
462
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
+			),
464
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
465
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
+			),
467
+			'EE_Message_Resource_Manager'                                                                                 => array(
468
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
+			),
472
+			'EE_Message_Factory'                                                                                          => array(
473
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
+			),
475
+			'EE_messages'                                                                                                 => array(
476
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
+			),
478
+			'EE_Messages_Generator'                                                                                       => array(
479
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_Messages_Processor'                                                                                       => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Queue'                                                                                           => array(
488
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
+			),
490
+			'EE_Messages_Template_Defaults'                                                                               => array(
491
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
495
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
+			),
498
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
+			),
501
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
+			),
512
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
+			),
515
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
552
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EE_Data_Migration_Class_Base'                                                                                => array(
555
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
+			),
558
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
559
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
+			),
562
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
563
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
567
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
+			),
570
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
571
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
+			),
574
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
575
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
+			),
604
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
+			),
616
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
+			),
619
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
620
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
+			),
622
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
623
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
+			),
625
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
626
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
627
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
630
+				null,
631
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
632
+			),
633
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
634
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
635
+			),
636
+			'LEGACY_MODELS'                                                   => array(
637
+				null,
638
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EE_Module_Request_Router' => array(
641
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EE_Registration_Processor' => array(
644
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\services\currency\CurrencyFactory' => array(
647
+				'EEM_Country'                                           => EE_Dependency_Map::load_from_cache,
648
+				'EE_Organization_Config'                                => EE_Dependency_Map::load_from_cache,
649
+				'EventEspresso\core\services\currency\CurrencySubunits' => EE_Dependency_Map::load_from_cache
650
+			),
651
+			'EventEspresso\core\services\currency\MoneyFactory' => array(
652
+				'EventEspresso\core\services\currency\CurrencyFactory'  => EE_Dependency_Map::load_from_cache,
653
+				'EventEspresso\core\services\currency\Calculator'       => EE_Dependency_Map::load_from_cache,
654
+				array(),
655
+			),
656
+		);
657
+	}
658
+
659
+
660
+
661
+	/**
662
+	 * Registers how core classes are loaded.
663
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
664
+	 *        'EE_Request_Handler' => 'load_core'
665
+	 *        'EE_Messages_Queue'  => 'load_lib'
666
+	 *        'EEH_Debug_Tools'    => 'load_helper'
667
+	 * or, if greater control is required, by providing a custom closure. For example:
668
+	 *        'Some_Class' => function () {
669
+	 *            return new Some_Class();
670
+	 *        },
671
+	 * This is required for instantiating dependencies
672
+	 * where an interface has been type hinted in a class constructor. For example:
673
+	 *        'Required_Interface' => function () {
674
+	 *            return new A_Class_That_Implements_Required_Interface();
675
+	 *        },
676
+	 *
677
+	 * @throws InvalidInterfaceException
678
+	 * @throws InvalidDataTypeException
679
+	 * @throws InvalidArgumentException
680
+	 */
681
+	protected function _register_core_class_loaders()
682
+	{
683
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
684
+		//be used in a closure.
685
+		$request = &$this->_request;
686
+		$response = &$this->_response;
687
+		// $loader = &$this->loader;
688
+		$this->_class_loaders = array(
689
+			//load_core
690
+			'EE_Capabilities'                      => 'load_core',
691
+			'EE_Encryption'                        => 'load_core',
692
+			'EE_Front_Controller'                  => 'load_core',
693
+			'EE_Module_Request_Router'             => 'load_core',
694
+			'EE_Registry'                          => 'load_core',
695
+			'EE_Request'                           => function () use (&$request) {
696
+				return $request;
697
+			},
698
+			'EE_Response'                          => function () use (&$response) {
699
+				return $response;
700
+			},
701
+			'EE_Request_Handler'                   => 'load_core',
702
+			'EE_Session'                           => 'load_core',
703
+			'EE_Cron_Tasks'                        => 'load_core',
704
+			'EE_System'                            => 'load_core',
705
+			'EE_Maintenance_Mode'                  => 'load_core',
706
+			'EE_Register_CPTs'                     => 'load_core',
707
+			'EE_Admin'                             => 'load_core',
708
+			//load_lib
709
+			'EE_Message_Resource_Manager'          => 'load_lib',
710
+			'EE_Message_Type_Collection'           => 'load_lib',
711
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
712
+			'EE_Messenger_Collection'              => 'load_lib',
713
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
714
+			'EE_Messages_Processor'                => 'load_lib',
715
+			'EE_Message_Repository'                => 'load_lib',
716
+			'EE_Messages_Queue'                    => 'load_lib',
717
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
718
+			'EE_Message_Template_Group_Collection' => 'load_lib',
719
+			'EE_Payment_Method_Manager'            => 'load_lib',
720
+			'EE_Messages_Generator'                => function () {
721
+				return EE_Registry::instance()->load_lib(
722
+					'Messages_Generator',
723
+					array(),
724
+					false,
725
+					false
726
+				);
727
+			},
728
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
729
+				return EE_Registry::instance()->load_lib(
730
+					'Messages_Template_Defaults',
731
+					$arguments,
732
+					false,
733
+					false
734
+				);
735
+			},
736
+			//load_model
737
+			// 'EEM_Attendee'                         => 'load_model',
738
+			// 'EEM_Message_Template_Group'           => 'load_model',
739
+			// 'EEM_Message_Template'                 => 'load_model',
740
+			//load_helper
741
+			'EEH_Parse_Shortcodes'                 => function () {
742
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
743
+					return new EEH_Parse_Shortcodes();
744
+				}
745
+				return null;
746
+			},
747
+			'EE_Template_Config'                   => function () {
748
+				return EE_Config::instance()->template_settings;
749
+			},
750
+			'EE_Currency_Config'                   => function () {
751
+				return EE_Config::instance()->currency;
752
+			},
753
+			'EE_Registration_Config'                   => function () {
754
+				return EE_Config::instance()->registration;
755
+			},
756
+			'EE_Organization_Config'                   => function () {
757
+				return EE_Config::instance()->organization;
758
+			},
759
+			'EventEspresso\core\services\loaders\Loader' => function () {
760
+				return LoaderFactory::getLoader();
761
+			},
762
+		);
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * can be used for supplying alternate names for classes,
769
+	 * or for connecting interface names to instantiable classes
770
+	 */
771
+	protected function _register_core_aliases()
772
+	{
773
+		$this->_aliases = array(
774
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
775
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
776
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
777
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
778
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
779
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
780
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
781
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
782
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
783
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
784
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
785
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
786
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
787
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
788
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
789
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
790
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
791
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
792
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
793
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
794
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
795
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
796
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
797
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
798
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
799
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
800
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
801
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
802
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
803
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
804
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
805
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
806
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
807
+			'NoticeConverterInterface'                                                    => 'EventEspresso\core\services\notices\NoticeConverterInterface',
808
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
809
+			'NoticesContainerInterface'                                                   => 'EventEspresso\core\services\notices\NoticesContainerInterface',
810
+			'EventEspresso\core\services\notices\NoticesContainerInterface'               => 'EventEspresso\core\services\notices\NoticesContainer',
811
+			'EventEspresso\core\services\currency\Calculator'                             => 'EventEspresso\core\services\currency\DefaultCalculator',
812
+		);
813
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
814
+			$this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
815
+		}
816
+	}
817
+
818
+
819
+
820
+	/**
821
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
822
+	 * request Primarily used by unit tests.
823
+	 *
824
+	 * @throws InvalidDataTypeException
825
+	 * @throws InvalidInterfaceException
826
+	 * @throws InvalidArgumentException
827
+	 */
828
+	public function reset()
829
+	{
830
+		$this->_register_core_class_loaders();
831
+		$this->_register_core_dependencies();
832
+	}
833 833
 
834 834
 
835 835
 }
Please login to merge, or discard this patch.