coercive / app
Coercive App
Installs: 1 061
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-curl: *
- ext-intl: *
- ext-json: *
- coercive/session: ^0
Requires (Dev)
- phpunit/phpunit: ^12
- dev-master
- 0.0.47
- 0.0.46
- 0.0.45
- 0.0.44
- 0.0.43
- 0.0.42
- 0.0.41
- 0.0.40
- 0.0.39
- 0.0.38
- 0.0.37
- 0.0.36
- 0.0.35
- 0.0.34
- 0.0.33
- 0.0.32
- 0.0.30
- 0.0.29
- 0.0.28
- 0.0.27
- 0.0.26
- 0.0.25
- 0.0.24
- 0.0.23
- 0.0.22
- 0.0.21
- 0.0.20
- 0.0.19
- 0.0.18
- 0.0.17
- 0.0.16
- 0.0.15
- 0.0.14
- 0.0.13
- 0.0.12
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- 0.0.0
This package is auto-updated.
Last update: 2025-09-30 08:13:26 UTC
README
!!! IN WORKS !!!
Get
composer require coercive/app
Usage
# in works ...
Currency
Load class with basic config
$config = (new Config) ->setLanguage('fr_FR') ->setCurrency('EUR') ->setPriceDigits(2); $currency = new Currency($config);
Detect decimal
$currency->hasDecimal(3.50) # > true $currency->hasDecimal(3.00) # > false
Format
echo $currency->format(13.756) # > 13,76 € echo $currency->format(13.000, false) # > 13,00 echo $currency->format(13.000, true, true) # > 13 € $currency->setTruncate(true); echo $currency->format(13.000, false) # > 13
Jason
JSON encode with float handler
$data = [528.56 * 100]; echo json_encode($data); # > [52855.99999999999] echo new Jason($data, JSON_NUMERIC_CHECK); # > [52856]
Decimal option
$data = ['52855.99999999999', 52855.99, 52855.99999999999, 528.56 * 100]; $jason = new Jason($data, JSON_NUMERIC_CHECK); $jason->setDecimals(2); echo $jason; # > [52855.99999999999,52855.99,52856,52856]
Truncate option
$data = ['52855.99999999999', 52855.99, 52855.99999999999, 528.56 * 100]; $jason = new Jason($data, JSON_NUMERIC_CHECK); $jason->setTruncate(true); echo $jason; # > [52855.99999999999,52855.99,52855.99,52855.99]
Locale
Load class with minimal config
$config = (new Config) ->setLanguage('fr_FR') ->setLanguages(['fr_FR', 'en_GB']); $locale = new Locale($config);
StrfTime backward compatibility
$config->setLanguage('fr_FR'); echo $locale->strftime('2025-09-16 09:32:17'); # > mardi 16 septembre 2025 09:32:17 $config->setLanguage('en_GB'); echo $locale->strftime('2025-09-16 09:32:17'); # > Tuesday 16 September 2025 09:32:17 $locale->setLocale('fr_FR'); echo $locale->strftime('2025-09-16 09:32:17', '%c'); # > mardi 16 septembre 2025 à 09:32:17 temps universel coordonné $locale->setLocale(); echo $locale->strftime('2025-09-16 09:32:17', '%x'); # > Tuesday, 16 September 2025 $locale->setLocale(); echo $locale->strftime('2025-09-16 09:32:17', '%X'); # > '09:32:17 Coordinated Universal Time
Use new system IntlDateFormatter with ICU format
$locale->setLocale(); echo $locale->format($example, 'EEEE'); # > Tuesday $locale->setLocale('fr_FR'); echo $locale->format($example, 'EEE e dd ww'); # > mar. 2 16 38
Export array of day names
$locale->setLocale('fr_FR'); $days = $locale->getDayNames(1); foreach ($days as $day) { echo $day['full'] . "\n\n"; }
Export array of month names
$locale->setLocale('fr_FR'); $months = $locale->getMonthNames(); foreach ($months as $month) { echo $month['full'] . "\n\n"; }
ReCaptcha handler
Load class and set your keys
$recaptcha = new ReCaptcha; $recaptcha ->setPublicKey("RECAPTCHA_PUBLIC_KEY") ->setPrivateKey("RECAPTCHA_SECRET_KEY")
Check if your token is valid
if (!$recaptcha->validateAndPersist($_POST['inputTokenToCheck'])) { die('invalid'); }
Optional: by default is V2 ; set threshold if you wan't to use reCaptcha V3
$recaptcha->threshold(0.5)
Optional: use storage data to optimize your quota
$recaptcha->setStoreCallback(function($result) { /* your storage logic here */ }) $recaptcha->setRetrieveCallback(function() { /* your retrieve logic here */ }) /* use `validateAndPersist()` to trigger your callbacks */ $recaptcha->validateAndPersist($_POST['inputTokenToCheck'])
Full example with session storage logic
$recaptcha ->setPublicKey("RECAPTCHA_PUBLIC_KEY") ->setPrivateKey("RECAPTCHA_SECRET_KEY") ->threshold(0.5) ->setStoreCallback(function($result) { $_SESSION['recaptcha']['result'] = $result; $_SESSION['recaptcha']['timestamp'] = time(); }) ->setRetrieveCallback(function () { if(!isset($_SESSION['recaptcha'])) { return null; } if(($_SESSION['recaptcha']['timestamp'] ?? 0) + (24 * 60 * 60) < time()) { return null; # example 1 day in second before recheck } return $_SESSION['recaptcha']['result'] ?? false; });
SqlTableName handler
Load class and set your environment name, and the prefix/sufix options.
$table = new SqlTableName('prod', ['test' => 'TEST_'], ['prod' => '_PROD']);
Get your table name with backticks
echo $table->database('HELLO')->table('WORLD'); # => `HELLO_PROD`.`WORLD`
Change your environment
$table->env('test'); echo $table->database('HELLO')->table('WORLD'); # => `TEST_HELLO`.`WORLD`
Add an alias
$table->alias('happy'); echo $table->database('HELLO')->table('WORLD'); # => `TEST_HELLO`.`WORLD` as happy
You can deactivate backticks in constructor, or in separated method
$table->backtick(false); echo $table->database('HELLO')->table('WORLD'); # => TEST_HELLO.WORLD