Skip to content

Commit

Permalink
Standar New Version
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunate authored and rmunate committed Dec 5, 2023
1 parent 3077e3d commit 9363b47
Show file tree
Hide file tree
Showing 18 changed files with 1,044 additions and 481 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ To whom we thank for supporting making programming easier.
- [Alejandro Diaz](https://github.com/alejandrodiazpinilla) (Readme And Icon)
- [Frank Sepulveda](https://github.com/socieboy) (Ordinal Texts)
- [Ngô Quốc Đạt](https://github.com/datlechin) (Vietnamese Language)
- [Mustafa Yusuf Özcan](https://github.com/mustafayusufozcan) (Turkish Language)

## License
This project is under the [MIT License](https://choosealicense.com/licenses/mit/).
Expand Down
46 changes: 9 additions & 37 deletions config/spell-number.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
| Global Configuration for Number to Words Conversion.
|--------------------------------------------------------------------------
|
| See https://rmunate.github.io/SpellNumber/
| Define a global configuration to make the translation of values to words easier and faster.
| Visit https://rmunate.github.io/SpellNumber/ for detailed documentation.
| Define a global configuration to facilitate and expedite the translation of values to words.
|
*/

Expand All @@ -20,27 +20,11 @@
|--------------------------------------------------------------------------
|
| Define the language over which values will be translated to words.
| Remember that you only have the following options available:
| 'de', 'en', 'es', 'fa', 'fr', 'hi', 'it', 'pl', 'pt', 'ro'.
|
*/

'locale' => 'en',

/*
|--------------------------------------------------------------------------
| Try using a "locale" not listed in the previous option.
|--------------------------------------------------------------------------
|
| If you want to use an option different from those previously listed,
| you must set the following indicator to true, so that the conversion to the supplied
| location can be attempted. To list possible additional options to use with the package,
| you can run the function SpellNumber::getAllLocales();
|
*/

'specific_locale' => false,

/*
|--------------------------------------------------------------------------
| Define the Currency.
Expand Down Expand Up @@ -83,11 +67,14 @@

/*
|--------------------------------------------------------------------------
| Sometimes you need to replace certain things in the number to words outputs.
| Global Output Replacements
|--------------------------------------------------------------------------
|
| If so, it's very easy to do.
| Use the structure of an associative array to apply these replacements to your outputs.
| If you need to make any replacements to the translation output, which is common
| in cases with abbreviated numbers or other language contractions, you can
| easily do so here through an associative array.
|
| Remember that the main index should match the locale you are using.
|
*/

Expand All @@ -97,19 +84,4 @@
// ],
],

/*
|--------------------------------------------------------------------------
| Encountered a specific adjustment in the number to words output?.
|--------------------------------------------------------------------------
|
| Here, you have the option to adjust whatever you need, the best part!
| This adjustment will apply to all your number to words outputs.
|
*/

'callback_output' => function ($data) {
// Your logic here...

return $data->getWords();
},
];
];
80 changes: 61 additions & 19 deletions src/Bases/BaseSpellNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Rmunate\Utilities\Validator\SpellNumberValidator;

abstract class BaseSpellNumber
{
{
/**
* Creates an instance of the child class with the provided value for conversion.
*
Expand All @@ -17,7 +17,7 @@ abstract class BaseSpellNumber
*
* @return static An instance of the child class.
*/
public static function value($value)
public static function value(mixed $value)
{
$type = SpellNumberValidator::check('mixed', $value)->result();

Expand All @@ -33,7 +33,7 @@ public static function value($value)
*
* @return static An instance of the child class.
*/
public static function integer($value)
public static function integer(int $value)
{
SpellNumberValidator::check('integer', $value)->result();

Expand All @@ -49,13 +49,37 @@ public static function integer($value)
*
* @return static An instance of the child class.
*/
public static function float($value)
public static function float(string|float $value)
{
SpellNumberValidator::check('double', $value)->result();

return new static($value, 'double');
}

/**
* Creates an instance of the child class with the provided text value for conversion.
*
* @param string $text The text value to be processed.
*
* @return static An instance of the child class configured for text processing.
*/
public static function text(string $text)
{
return new static($text, 'text');
}

/**
* Creates an instance of the child class with the provided date value for conversion.
*
* @param string $date The date value to be processed.
*
* @return static An instance of the child class configured for date processing.
*/
public static function date(string $date)
{
return new static($date, 'date');
}

/**
* Returns the list of available premises according to PHP.
*
Expand Down Expand Up @@ -93,24 +117,42 @@ public static function getAvailableLanguages()
}

/**
* DEPRECATED - Delete Method Soon
* Retrieves a list of all available locales supported by the NumberFormatter class.
* This method allows querying the constants existing within SpellNumber
* along with their values for use in the package.
*
* @return array An array containing all available locales.
*/
public static function getLocales()
{
return self::getAvailableLocales();
}

/**
* DEPRECATED - Delete Method Soon
* Retrieves a list of all available TimeZones by the NumberFormatter class.
* @param string|null $category The optional category of constants to retrieve.
*
* @return array An array containing all available locales.
* @return mixed
*/
public static function getLanguages()
public static function getConstants(?string $category = null)
{
return self::getAvailableLanguages();
$data = [
"spell" => [
"SpellNumber::TO_LETTERS" => "%value-to-letters",
"SpellNumber::TO_ORDINAL" => "%value-to-ordinal",
"SpellNumber::TO_MONEY" => "%value-to-money",
"SpellNumber::TO_CLOCK" => "%value-to-clock",
"SpellNumber::TO_SCIENTIFIC" => "%value-to-scientific",
"SpellNumber::TO_PERCENT" => "%value-to-percent",
"SpellNumber::TO_CURRENCY" => "%value-to-currency",
"SpellNumber::TO_SUMMARY" => "%value-to-summary",
"SpellNumber::TO_ROMAN_NUMERAL" => "%value-to-roman-numeral",
],
"ordinal-numbers" => [
"SpellNumber::ORDINAL_DEFAULT" => '%spellout-ordinal',
"SpellNumber::ORDINAL_FEMALE" => '%spellout-ordinal-feminine',
"SpellNumber::ORDINAL_MALE" => '%spellout-ordinal-masculine',
],
"date" => [
"SpellNumber::DATE_SHORT" => "%date-format-short",
"SpellNumber::DATE_MEDIUM" => "%date-format-medium",
"SpellNumber::DATE_LONG" => "%date-format-long",
"SpellNumber::DATE_FULL" => "%date-format-full",
],
];

$output = !empty($category) ? ($data[$category] ?? []) : $data;

return json_decode(json_encode($output), false);
}
}
7 changes: 0 additions & 7 deletions src/Bases/BaseSpellNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

namespace Rmunate\Utilities\Bases;

/**
* This class serves as a base validator for common data types.
*
* @method static BaseValidator mixed().
* @method static BaseValidator integer().
* @method static BaseValidator float().
*/
abstract class BaseSpellNumberValidator
{
/**
Expand Down
114 changes: 0 additions & 114 deletions src/Callback/DataResponse.php

This file was deleted.

Loading

0 comments on commit 9363b47

Please sign in to comment.