Download the PHP package lastdragon-ru/lara-asp-formatter without Composer
On this page you can find all versions of the php package lastdragon-ru/lara-asp-formatter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lastdragon-ru/lara-asp-formatter
More information about lastdragon-ru/lara-asp-formatter
Files in lastdragon-ru/lara-asp-formatter
Package lara-asp-formatter
Short Description The Awesome Set of Packages for Laravel - The Formatter.
License MIT
Homepage https://github.com/LastDragon-ru/lara-asp
Informations about the package lara-asp-formatter
(Laravel) Intl Formatter
This package provides a customizable wrapper around Intl formatters to use it inside Laravel application. And also allows defining own.
[include:artisan]: <lara-asp-documentator:requirements "{$directory}">
Requirements
Requirement | Constraint | Supported by |
---|---|---|
PHP | ^8.4 |
HEAD ⋯ 8.0.0 |
^8.3 |
HEAD ⋯ 5.0.0 |
|
^8.2 |
7.2.0 ⋯ 2.0.0 |
|
^8.1 |
6.4.2 ⋯ 2.0.0 |
|
^8.0 |
4.6.0 ⋯ 2.0.0 |
|
^8.0.0 |
1.1.2 ⋯ 0.12.0 |
|
>=8.0.0 |
0.11.0 ⋯ 0.4.0 |
|
>=7.4.0 |
0.3.0 ⋯ 0.1.0 |
|
Laravel | ^12.0.1 |
HEAD ⋯ 9.0.0 |
^11.0.8 |
8.1.1 ⋯ 8.0.0 |
|
^11.0.0 |
7.2.0 ⋯ 6.2.0 |
|
^10.34.0 |
7.2.0 ⋯ 6.2.0 |
|
^10.0.0 |
6.1.0 ⋯ 2.1.0 |
|
^9.21.0 |
5.6.0 ⋯ 5.0.0-beta.1 |
|
^9.0.0 |
5.0.0-beta.0 ⋯ 0.12.0 |
|
^8.22.1 |
3.0.0 ⋯ 0.2.0 |
|
^8.0 |
0.1.0 |
Installation
Configuration
Config can be used to customize formats. Before this, you need to publish it via the following command, and then you can edit config/lara-asp-formatter.php
.
Usage
[!NOTE]
The resolved formats are cached, thus run-time changes in the configuration will not be applied. You can
clone
the formatter instance to reset the internal cache.
The Formatter
to see built-in formats 🤗
The $default->integer(123.454321)
is:
The $default->decimal(123.454321)
is:
The $locale->decimal(123.454321)
is:
You can also define separate setting for each locale:
The $default->date($datetime)
is:
The $locale->date($datetime)
is:
Adding new formats
You just need to create a class that implements Formatter
class.
[!NOTE]
The instance will be created through container with the following additional arguments:
$formatter
:Formatter
- the current formatter instance (can be used to get locale/timezone).$options
(array) - formatter options defined inside app config (may containnull
s).
The app()->make(Formatter::class)->uppercase('string')
is:
Notes about built-in formats
Currency
By default, the Formatter
use locale currency. You can redefine it globally through config, specify for the call, and/or add a macros for another currency.
The $formatter->eur($value)
is:
The $formatter->currency($value)
is:
The $formatter->currency($value, 'EUR')
is:
Duration
To format duration you can use built-in Intl formatter, but it doesn't support fraction seconds and have a different format between locales (for example, 12345
seconds is 3:25:45
in en_US
locale, and 12 345
in ru_RU
). These reasons make it difficult to use it in real applications. To make duration()
more useful, the alternative syntax was added and used by default.
The syntax is the same as ICU Date/Time format syntax.
Symbol | Meaning |
---|---|
y |
years |
M |
months |
d |
days |
H |
hours |
m |
minutes |
s |
seconds |
S |
fractional seconds |
z |
negative sign (default - ) |
' |
escape for text |
'' |
two single quotes produce one |
The $default->duration(123.454321)
is:
The $locale->duration(123.4543)
is:
The $locale->duration(1234543)
is:
To use Intl Formatter, you need to change the duration format in the config:
The $default->duration($value)
is:
The $locale->duration($value)
is:
Upgrading
Please follow Upgrade Guide.
Contributing
This package is the part of Awesome Set of Packages for Laravel. Please use the main repository to report issues, send pull requests, or ask questions.
"\LastDragon_ru\LaraASP\Formatter\Contracts\Format"
"\LastDragon_ru\LaraASP\Formatter\Formatter"
All versions of lara-asp-formatter with dependencies
ext-bcmath Version *
ext-intl Version *
ext-mbstring Version *
illuminate/macroable Version ^12.0.1
illuminate/support Version ^12.0.1
lastdragon-ru/lara-asp-core Version self.version
symfony/polyfill-php84 Version ^1.31