Upgrade Guide from Version 3.x to 4.x
Short Number 4 brought a complete rewrite of the source code with improved configurations. The upgrade is very simple and requires only a few changes in your code. Follow this guide to upgrade your application from version 3.x to 4.x. Most of the steps here you're likely going to skip, as they are only applicable if you're using specific configurations or features.
Possible Steps
Some steps are marked with possible, as they may not apply to you if you're not using the specific configurations or features mentioned.
Step 1: Composer File
In your composer.json file, update the version of the serhii/short-number package to the version 4:
{
"require": {
"serhii/short-number": "^4.0"
}
}Step 2: Composer Update
Then run the following command to update the package:
composer update serhii/short-number:^4.0Step 3: Rename Method
The method conv on the Serhii\ShortNumber\Number class was renamed to short:
use Serhii\ShortNumber\Number;
echo Number::conv(1000);
echo Number::short(1000); Its behavior remains the same, but the name was changed to better reflect its purpose.
Step 4: Named Argument possible
If you are using a named argument for the second argument of Lang::set(), rename custom_translations to overwrites:
use Serhii\ShortNumber\Lang;
Lang::set('en', overwrites: [
Lang::set('en', custom_translations: [
'thousand' => 'kilo',
'million' => 'mega',
'billion' => 'bill',
]);Step 5: Change Overwrites possible
If you use Short Number's overwrites feature to replace default translations, change the way you define the overwrites. Here are the old and new approaches:
use Serhii\ShortNumber\Lang;
Lang::set('en', custom_translations: [
'thousand' => 'kilo',
'million' => 'mil',
'billion' => 'bil',
'trillion' => 'tril',
]);use Serhii\ShortNumber\Lang;
Lang::set('en', overwrites: [
'k' => 'kilo',
'm' => 'mil',
'b' => 'bil',
't' => 'tril',
]);You can also overwrite quadrillions with q key, but quadrillions weren't supported in the previous version.
Step 6: Delete Class possible
If you have been using the Serhii\ShortNumber\Rule class directly in your code — which was neither documented nor recommended — you will need to get rid of it completely. It wasn't a part of the public API.
$rule = new Rule('thousand', [Rule::THOUSAND, Rule::MILLION - 1]);
$output = $rule->formatNumber($number);