Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\VarDumper\Caster; |
| 13 | |
| 14 | use Symfony\Component\VarDumper\Cloner\Stub; |
| 15 | |
| 16 | /** |
| 17 | * @author Nicolas Grekas <p@tchwork.com> |
| 18 | * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> |
| 19 | * |
| 20 | * @final |
| 21 | */ |
| 22 | class IntlCaster |
| 23 | { |
| 24 | public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub $stub, bool $isNested) |
| 25 | { |
| 26 | $a += [ |
| 27 | Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(), |
| 28 | Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(), |
| 29 | ]; |
| 30 | |
| 31 | return self::castError($c, $a); |
| 32 | } |
| 33 | |
| 34 | public static function castNumberFormatter(\NumberFormatter $c, array $a, Stub $stub, bool $isNested, int $filter = 0) |
| 35 | { |
| 36 | $a += [ |
| 37 | Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(), |
| 38 | Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(), |
| 39 | ]; |
| 40 | |
| 41 | if ($filter & Caster::EXCLUDE_VERBOSE) { |
| 42 | $stub->cut += 3; |
| 43 | |
| 44 | return self::castError($c, $a); |
| 45 | } |
| 46 | |
| 47 | $a += [ |
| 48 | Caster::PREFIX_VIRTUAL.'attributes' => new EnumStub( |
| 49 | [ |
| 50 | 'PARSE_INT_ONLY' => $c->getAttribute(\NumberFormatter::PARSE_INT_ONLY), |
| 51 | 'GROUPING_USED' => $c->getAttribute(\NumberFormatter::GROUPING_USED), |
| 52 | 'DECIMAL_ALWAYS_SHOWN' => $c->getAttribute(\NumberFormatter::DECIMAL_ALWAYS_SHOWN), |
| 53 | 'MAX_INTEGER_DIGITS' => $c->getAttribute(\NumberFormatter::MAX_INTEGER_DIGITS), |
| 54 | 'MIN_INTEGER_DIGITS' => $c->getAttribute(\NumberFormatter::MIN_INTEGER_DIGITS), |
| 55 | 'INTEGER_DIGITS' => $c->getAttribute(\NumberFormatter::INTEGER_DIGITS), |
| 56 | 'MAX_FRACTION_DIGITS' => $c->getAttribute(\NumberFormatter::MAX_FRACTION_DIGITS), |
| 57 | 'MIN_FRACTION_DIGITS' => $c->getAttribute(\NumberFormatter::MIN_FRACTION_DIGITS), |
| 58 | 'FRACTION_DIGITS' => $c->getAttribute(\NumberFormatter::FRACTION_DIGITS), |
| 59 | 'MULTIPLIER' => $c->getAttribute(\NumberFormatter::MULTIPLIER), |
| 60 | 'GROUPING_SIZE' => $c->getAttribute(\NumberFormatter::GROUPING_SIZE), |
| 61 | 'ROUNDING_MODE' => $c->getAttribute(\NumberFormatter::ROUNDING_MODE), |
| 62 | 'ROUNDING_INCREMENT' => $c->getAttribute(\NumberFormatter::ROUNDING_INCREMENT), |
| 63 | 'FORMAT_WIDTH' => $c->getAttribute(\NumberFormatter::FORMAT_WIDTH), |
| 64 | 'PADDING_POSITION' => $c->getAttribute(\NumberFormatter::PADDING_POSITION), |
| 65 | 'SECONDARY_GROUPING_SIZE' => $c->getAttribute(\NumberFormatter::SECONDARY_GROUPING_SIZE), |
| 66 | 'SIGNIFICANT_DIGITS_USED' => $c->getAttribute(\NumberFormatter::SIGNIFICANT_DIGITS_USED), |
| 67 | 'MIN_SIGNIFICANT_DIGITS' => $c->getAttribute(\NumberFormatter::MIN_SIGNIFICANT_DIGITS), |
| 68 | 'MAX_SIGNIFICANT_DIGITS' => $c->getAttribute(\NumberFormatter::MAX_SIGNIFICANT_DIGITS), |
| 69 | 'LENIENT_PARSE' => $c->getAttribute(\NumberFormatter::LENIENT_PARSE), |
| 70 | ] |
| 71 | ), |
| 72 | Caster::PREFIX_VIRTUAL.'text_attributes' => new EnumStub( |
| 73 | [ |
| 74 | 'POSITIVE_PREFIX' => $c->getTextAttribute(\NumberFormatter::POSITIVE_PREFIX), |
| 75 | 'POSITIVE_SUFFIX' => $c->getTextAttribute(\NumberFormatter::POSITIVE_SUFFIX), |
| 76 | 'NEGATIVE_PREFIX' => $c->getTextAttribute(\NumberFormatter::NEGATIVE_PREFIX), |
| 77 | 'NEGATIVE_SUFFIX' => $c->getTextAttribute(\NumberFormatter::NEGATIVE_SUFFIX), |
| 78 | 'PADDING_CHARACTER' => $c->getTextAttribute(\NumberFormatter::PADDING_CHARACTER), |
| 79 | 'CURRENCY_CODE' => $c->getTextAttribute(\NumberFormatter::CURRENCY_CODE), |
| 80 | 'DEFAULT_RULESET' => $c->getTextAttribute(\NumberFormatter::DEFAULT_RULESET), |
| 81 | 'PUBLIC_RULESETS' => $c->getTextAttribute(\NumberFormatter::PUBLIC_RULESETS), |
| 82 | ] |
| 83 | ), |
| 84 | Caster::PREFIX_VIRTUAL.'symbols' => new EnumStub( |
| 85 | [ |
| 86 | 'DECIMAL_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL), |
| 87 | 'GROUPING_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL), |
| 88 | 'PATTERN_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::PATTERN_SEPARATOR_SYMBOL), |
| 89 | 'PERCENT_SYMBOL' => $c->getSymbol(\NumberFormatter::PERCENT_SYMBOL), |
| 90 | 'ZERO_DIGIT_SYMBOL' => $c->getSymbol(\NumberFormatter::ZERO_DIGIT_SYMBOL), |
| 91 | 'DIGIT_SYMBOL' => $c->getSymbol(\NumberFormatter::DIGIT_SYMBOL), |
| 92 | 'MINUS_SIGN_SYMBOL' => $c->getSymbol(\NumberFormatter::MINUS_SIGN_SYMBOL), |
| 93 | 'PLUS_SIGN_SYMBOL' => $c->getSymbol(\NumberFormatter::PLUS_SIGN_SYMBOL), |
| 94 | 'CURRENCY_SYMBOL' => $c->getSymbol(\NumberFormatter::CURRENCY_SYMBOL), |
| 95 | 'INTL_CURRENCY_SYMBOL' => $c->getSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL), |
| 96 | 'MONETARY_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL), |
| 97 | 'EXPONENTIAL_SYMBOL' => $c->getSymbol(\NumberFormatter::EXPONENTIAL_SYMBOL), |
| 98 | 'PERMILL_SYMBOL' => $c->getSymbol(\NumberFormatter::PERMILL_SYMBOL), |
| 99 | 'PAD_ESCAPE_SYMBOL' => $c->getSymbol(\NumberFormatter::PAD_ESCAPE_SYMBOL), |
| 100 | 'INFINITY_SYMBOL' => $c->getSymbol(\NumberFormatter::INFINITY_SYMBOL), |
| 101 | 'NAN_SYMBOL' => $c->getSymbol(\NumberFormatter::NAN_SYMBOL), |
| 102 | 'SIGNIFICANT_DIGIT_SYMBOL' => $c->getSymbol(\NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL), |
| 103 | 'MONETARY_GROUPING_SEPARATOR_SYMBOL' => $c->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL), |
| 104 | ] |
| 105 | ), |
| 106 | ]; |
| 107 | |
| 108 | return self::castError($c, $a); |
| 109 | } |
| 110 | |
| 111 | public static function castIntlTimeZone(\IntlTimeZone $c, array $a, Stub $stub, bool $isNested) |
| 112 | { |
| 113 | $a += [ |
| 114 | Caster::PREFIX_VIRTUAL.'display_name' => $c->getDisplayName(), |
| 115 | Caster::PREFIX_VIRTUAL.'id' => $c->getID(), |
| 116 | Caster::PREFIX_VIRTUAL.'raw_offset' => $c->getRawOffset(), |
| 117 | ]; |
| 118 | |
| 119 | if ($c->useDaylightTime()) { |
| 120 | $a += [ |
| 121 | Caster::PREFIX_VIRTUAL.'dst_savings' => $c->getDSTSavings(), |
| 122 | ]; |
| 123 | } |
| 124 | |
| 125 | return self::castError($c, $a); |
| 126 | } |
| 127 | |
| 128 | public static function castIntlCalendar(\IntlCalendar $c, array $a, Stub $stub, bool $isNested, int $filter = 0) |
| 129 | { |
| 130 | $a += [ |
| 131 | Caster::PREFIX_VIRTUAL.'type' => $c->getType(), |
| 132 | Caster::PREFIX_VIRTUAL.'first_day_of_week' => $c->getFirstDayOfWeek(), |
| 133 | Caster::PREFIX_VIRTUAL.'minimal_days_in_first_week' => $c->getMinimalDaysInFirstWeek(), |
| 134 | Caster::PREFIX_VIRTUAL.'repeated_wall_time_option' => $c->getRepeatedWallTimeOption(), |
| 135 | Caster::PREFIX_VIRTUAL.'skipped_wall_time_option' => $c->getSkippedWallTimeOption(), |
| 136 | Caster::PREFIX_VIRTUAL.'time' => $c->getTime(), |
| 137 | Caster::PREFIX_VIRTUAL.'in_daylight_time' => $c->inDaylightTime(), |
| 138 | Caster::PREFIX_VIRTUAL.'is_lenient' => $c->isLenient(), |
| 139 | Caster::PREFIX_VIRTUAL.'time_zone' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getTimeZone()) : $c->getTimeZone(), |
| 140 | ]; |
| 141 | |
| 142 | return self::castError($c, $a); |
| 143 | } |
| 144 | |
| 145 | public static function castIntlDateFormatter(\IntlDateFormatter $c, array $a, Stub $stub, bool $isNested, int $filter = 0) |
| 146 | { |
| 147 | $a += [ |
| 148 | Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(), |
| 149 | Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(), |
| 150 | Caster::PREFIX_VIRTUAL.'calendar' => $c->getCalendar(), |
| 151 | Caster::PREFIX_VIRTUAL.'time_zone_id' => $c->getTimeZoneId(), |
| 152 | Caster::PREFIX_VIRTUAL.'time_type' => $c->getTimeType(), |
| 153 | Caster::PREFIX_VIRTUAL.'date_type' => $c->getDateType(), |
| 154 | Caster::PREFIX_VIRTUAL.'calendar_object' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getCalendarObject()) : $c->getCalendarObject(), |
| 155 | Caster::PREFIX_VIRTUAL.'time_zone' => ($filter & Caster::EXCLUDE_VERBOSE) ? new CutStub($c->getTimeZone()) : $c->getTimeZone(), |
| 156 | ]; |
| 157 | |
| 158 | return self::castError($c, $a); |
| 159 | } |
| 160 | |
| 161 | private static function castError(object $c, array $a): array |
| 162 | { |
| 163 | if ($errorCode = $c->getErrorCode()) { |
| 164 | $a += [ |
| 165 | Caster::PREFIX_VIRTUAL.'error_code' => $errorCode, |
| 166 | Caster::PREFIX_VIRTUAL.'error_message' => $c->getErrorMessage(), |
| 167 | ]; |
| 168 | } |
| 169 | |
| 170 | return $a; |
| 171 | } |
| 172 | } |