PHP code example of sirius-program / sirius-helpers

1. Go to this page and download the library: Download sirius-program/sirius-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sirius-program / sirius-helpers example snippets


return [
    'country_code' => env('COUNTRY_CODE', 'ID'),
    'currency_locale' => env('CURRENCY_LOCALE', 'id_ID'),
];

// use Sirius class
$sirius = new Sirius();

// or use the helper function
sirius();

// use Sirius class
$sirius = new Sirius();
$helper = $sirius->string();

// or use the helper function
sirius()->string();

// use StringHelpers class
$helper = new StringHelpers();

// or use the helper function
sString();

echo sirius()->string('text you want to encrypt @ 123')->encrypt(salt: 'sirius');

echo sirius()->string('MwTMh2laUQDG09O9ZsVCv2c8pON/3IlIHf+8Dq55gkg=')->decrypt(salt: 'sirius');

echo sirius()->string('MwTMh2laUQDG09O9ZsVCv2c8pON/3IlIHf+8Dq55gkg=')->urlSafe();

echo sirius()->string('MwTMh2laUQDG09O9ZsVCv2c8pON_3IlIHf.8Dq55gkg-')->urlUnsafe();

print_r(sirius()->string('+62 812-3')->isPartOfPhoneNumber())

print_r(sirius()->string('+62 812-3aa')->isPartOfPhoneNumber())

echo sirius()->string('+628123456789')->toPhoneNumber();

echo sirius()->string('+62 812-3456-789')->sanitizePhoneNumber(zeroPrefix: true);

echo sirius()->string('Sirius Helpers by Sirius Program')->toInitials();

echo sirius()->string('Sirius Helpers by Sirius Program')->toInitials(length: 0);

echo sirius()->string('+628123456789')
    ->toPhoneNumber() // +62 812-3456-789
    ->sanitizePhoneNumber(zeroPrefix: true) // 08123456789
    ->encrypt() // OWb2zHt440dxKnH5jLkklg==
    ->urlSafe() // OWb2zHt440dxKnH5jLkklg--
    ->urlUnsafe() // OWb2zHt440dxKnH5jLkklg==
    ->decrypt() // 08123456789
    ->toStr(); // will convert the text into Laravel's Stringable instance

echo sirius()->string('any text')
    ->encrypt()
    ->dump()
    ->decrypt()
    ->dd();

// use Sirius class
$sirius = new Sirius();
$helper = $sirius->number();

// or use the helper function
sirius()->number();

// use NumberHelpers class
$helper = new NumberHelpers();

// or use the helper function
sNumber();

echo sirius()->number(1234.56)->toInt();

echo sirius()->number('1234.56')->toFloat();

echo sirius()->number(1234567.89)->format();

echo sirius()->number(1234567.89)->format(currencyLocale: 'en_US');

echo sirius()->number(1234)->toRoman();

echo sirius()->number(1234567.89)->toCurrency();

echo sirius()->number(1234567.89)->toCurrency(currencyLocale: 'en_US');

echo sirius()->number(1234567.89)->toCent();

echo sirius()->number(123.456.789)->fromCent();

echo sirius()->number(1234567.89)->spell();

echo sirius()->number(1234567.89)->spell(currencyLocale: 'en_US');

echo sirius()->number(1234567.89)->toCurrency(currencyLocale: 'en_US')->spell();

echo sirius()->number(10000.05)->toCurrency()->getOriginal();

echo sirius()->number(10000)
    ->toCurrency() // Rp10.000
    ->spell() // sepuluh ribu rupiah
    ->getOriginal(); // 10000

echo sirius()->number(10000.05)
    ->toCurrency()
    ->dump()
    ->spell()
    ->dd();

// use Sirius class
$sirius = new Sirius();
$helper = $sirius->dateTime();

// or use the helper function
sirius()->dateTime();

// use DateTimeHelpers class
$helper = new DateTimeHelpers();

// or use the helper function
sDateTime();

echo sirius()->dateTime(12)->toLongMonth();

echo sirius()->dateTime('2024-01-01')->toShortMonth();

echo sirius()->dateTime(6)->toLongDay();

echo sirius()->dateTime('2024-01-01')->toShortDay();

echo sirius()->dateTime('2024-01-01')->toCarbon('Y-m-d')->getOriginal();

echo sirius()->dateTime('2024-01-01 01:01:01')
    ->toDateTime() // will be converted into PHP's DateTime object
    ->format('Y-m-d') // 2024-01-01
    ->toLongMonth() // January
    ->getOriginal(); // 2024-01-01 01:01:01

echo sirius()->dateTime('2024-01-01 01:01:01')
    ->toDateTime()
    ->format('Y-m-d')
    ->dump()
    ->toLongMonth()
    ->dd()

$months = DateTimeHelpers::getAllMonths();

[
    1 => "January",
    2 => "February",
    3 => "March",
    4 => "April",
    5 => "May",
    6 => "June",
    7 => "July",
    8 => "August",
    9 => "September",
    10 => "October",
    11 => "November",
    12 => "December",
]

$days = DateTimeHelpers::getAllDays();

[
    0 => "Sunday",
    1 => "Monday",
    2 => "Tuesday",
    3 => "Wednesday",
    4 => "Thursday",
    5 => "Friday",
    6 => "Saturday",
]

$days = DateTimeHelpers::getAllDays(startingDay: DateTimeHelpers::START_WITH_MONDAY);

[
    1 => "Monday",
    2 => "Tuesday",
    3 => "Wednesday",
    4 => "Thursday",
    5 => "Friday",
    6 => "Saturday",
    7 => "Sunday",
]

echo SiriusProgram\SiriusHelpers\Sirius::calculateDistanceInMeters(-7.3197956, 112.765537, -7.3231706, 112.7578611);

print_r(SiriusProgram\SiriusHelpers\Sirius::setNullIfBlank([0, 1, '', 2, null, 3, []]));

print_r(SiriusProgram\SiriusHelpers\Sirius::getCountryDetail('ID'));
bash
php artisan vendor:publish --tag="sirius-helpers-config"
bash
php artisan about
bash
SiriusHelpers Version ................................................................ 1.1.7