| @@ 72-90 (lines=19) @@ | ||
| 69 | public static function fromCountryCode($CNT_ISO = null) |
|
| 70 | { |
|
| 71 | $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : CreateCurrency::getSiteCountryIso(); |
|
| 72 | if(isset(CreateCurrency::$countries_by_iso_code[$CNT_ISO])) { |
|
| 73 | $country = CreateCurrency::$countries_by_iso_code[ $CNT_ISO ]; |
|
| 74 | } else { |
|
| 75 | /** @var EE_Country $country */ |
|
| 76 | $country = CreateCurrency::countryModel()->get_one_by_ID($CNT_ISO); |
|
| 77 | if (! $country instanceof EE_Country) { |
|
| 78 | throw new InvalidArgumentException( |
|
| 79 | sprintf( |
|
| 80 | esc_html__( |
|
| 81 | 'A valid country could not be found for the "%1$s" country code;', |
|
| 82 | 'event_espresso' |
|
| 83 | ), |
|
| 84 | $CNT_ISO |
|
| 85 | ) |
|
| 86 | ); |
|
| 87 | } |
|
| 88 | CreateCurrency::$countries_by_iso_code[ $CNT_ISO ] = $country; |
|
| 89 | CreateCurrency::$countries_by_currency[ $country->currency_code() ] = $country; |
|
| 90 | } |
|
| 91 | return new Currency( |
|
| 92 | $country->currency_code(), |
|
| 93 | new Label( |
|
| @@ 121-139 (lines=19) @@ | ||
| 118 | */ |
|
| 119 | public static function fromCode($code) |
|
| 120 | { |
|
| 121 | if (isset(CreateCurrency::$countries_by_currency[ $code ])) { |
|
| 122 | $country = CreateCurrency::$countries_by_currency[ $code ]; |
|
| 123 | } else { |
|
| 124 | /** @var EE_Country $country */ |
|
| 125 | $country = CreateCurrency::countryModel()->get_one(array(array('CNT_cur_code' => $code))); |
|
| 126 | if (! $country instanceof EE_Country) { |
|
| 127 | throw new InvalidArgumentException( |
|
| 128 | sprintf( |
|
| 129 | esc_html__( |
|
| 130 | 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 131 | 'event_espresso' |
|
| 132 | ), |
|
| 133 | $code |
|
| 134 | ) |
|
| 135 | ); |
|
| 136 | } |
|
| 137 | CreateCurrency::$countries_by_iso_code[ $country->ID() ] = $country; |
|
| 138 | CreateCurrency::$countries_by_currency[$code ] = $country; |
|
| 139 | } |
|
| 140 | return new Currency( |
|
| 141 | $country->currency_code(), |
|
| 142 | new Label( |
|