Skip to content

Commit 3712ba3

Browse files
committed
prepare new release
1 parent d99ca70 commit 3712ba3

11 files changed

+161
-76
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
All Notable changes to `bakame/laravel-intl-formatter` will be documented in this file
44

5+
## [0.2.0] - 2022-06-06
6+
7+
58
## [0.1.0] - 2022-06-04
69

710
**Initial release!**
811

12+
[Next]: https://github.com/bakame-php/laravel-intl-formatter/compare/0.2.0...main
13+
[0.2.0]: https://github.com/bakame-php/laravel-intl-formatter/compare/0.1.0...0.2.0
914
[0.1.0]: https://github.com/bakame-php/laravel-intl-formatter/releases/tag/0.1.0

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Laravel Intl Formatter
33

44
[![Author](http://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/nyamsprod)
55
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
6-
[![Build](https://github.com/bakame-php/laravel-intl-extra/workflows/build/badge.svg)](https://github.com/bakame-php/laravel-intl-extra/actions?query=workflow%3A%22build%22)
7-
[![Latest Version](https://img.shields.io/github/release/bakame-php/laravel-intl-extra.svg?style=flat-square)](https://github.com/bakame-php/laravel-intl-extra/releases)
8-
[![Total Downloads](https://img.shields.io/packagist/dt/bakame/laravel-intl-extra.svg?style=flat-square)](https://packagist.org/packages/bakame/laravel-intl-extra)
6+
[![Build](https://github.com/bakame-php/laravel-intl-formatter/workflows/build/badge.svg)](https://github.com/bakame-php/laravel-intl-formatter/actions?query=workflow%3A%22build%22)
7+
[![Latest Version](https://img.shields.io/github/release/bakame-php/laravel-intl-formatter.svg?style=flat-square)](https://github.com/bakame-php/laravel-intl-formatter/releases)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/bakame/laravel-intl-formatter.svg?style=flat-square)](https://packagist.org/packages/bakame/laravel-intl-formatter)
99
[![Sponsor development of this project](https://img.shields.io/badge/sponsor%20this%20package-%E2%9D%A4-ff69b4.svg?style=flat-square)](https://github.com/sponsors/nyamsprod)
1010

1111
This is a Laravel port of the [Twig Intl Extension](https://github.com/twigphp/intl-extra) package.
@@ -164,7 +164,7 @@ echo view($templatePath, $templateData)->render();
164164
Formats a number;
165165

166166
```blade
167-
format number: {{ format_number($number, $attrs, $locale) }}
167+
format number: {{ format_number($number, $locale, $attrs) }}
168168
```
169169

170170
```php
@@ -187,7 +187,7 @@ echo view($templatePath, $templateData)->render();
187187
Formats a date and time;
188188

189189
```blade
190-
format datetime: {{ format_datetime($date, $dateFormat, $timeFormat, $pattern, $timezone, $calendar, $locale) }}
190+
format datetime: {{ format_datetime($date, $locale, $timezone, $dateFormat, $timeFormat, $pattern, $calendar) }}
191191
```
192192

193193
```php
@@ -209,7 +209,7 @@ echo view($templatePath, $templateData)->render();
209209
Formats a the date portion of a datetime;
210210

211211
```blade
212-
format date: {{ format_date($date, $dateFormat, $pattern, $timezone, $calendar, $locale) }}
212+
format date: {{ format_date($date, $locale, $timezone, $dateFormat, $pattern, $calendar) }}
213213
```
214214

215215
```php
@@ -230,7 +230,7 @@ echo view($templatePath, $templateData)->render();
230230
Formats the time portion of a datetime;
231231

232232
```blade
233-
format time: {{ format_time($date, $timeFormat, $pattern, $timezone, $calendar, $locale) }}
233+
format time: {{ format_time($date, $locale, $timezone, $timeFormat, $pattern, $calendar) }}
234234
```
235235

236236
```php
@@ -262,7 +262,7 @@ In PHP8+, you can use named parameters to improve functions usages as they tend
262262
```php
263263
<?php
264264

265-
echo format_datetime('2019-08-07 23:39:12', 'mediun', 'medium', '', null, 'gregorian', 'fr');
265+
echo format_datetime('2019-08-07 23:39:12', 'fr', null, medium', 'medium', '', 'gregorian', 'fr');
266266
```
267267

268268
**In PHP8+**
@@ -302,7 +302,7 @@ Credits
302302
-------
303303

304304
- [ignace nyamagana butera](https://github.com/nyamsprod)
305-
- [All Contributors](https://github.com/bakame-php/laravel-intl-extra/contributors)
305+
- [All Contributors](https://github.com/bakame-php/laravel-intl-formatter/contributors)
306306

307307
Attribution
308308
-------

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"php": "^7.4 || ^8.0",
4040
"illuminate/config": "^8.0 || ^9.0",
4141
"illuminate/support": "^8.0 || ^9.0",
42-
"bakame/intl-formatter": "0.1.0"
42+
"bakame/intl-formatter": "~0.2.0"
4343
},
4444
"require-dev": {
4545
"friendsofphp/php-cs-fixer": "^3.8",
@@ -74,10 +74,10 @@
7474
},
7575
"laravel": {
7676
"providers": [
77-
"Provider"
77+
"Bakame\\Intl\\Laravel\\Provider"
7878
],
7979
"aliases": {
80-
"Formatter": "Bakame\\Int\\Laravel\\Formatter"
80+
"Formatter": "Bakame\\Intl\\Laravel\\Formatter"
8181
}
8282
}
8383
},

config/bakame-intl-formatter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
| Expected: ?string
4444
*/
4545
'pattern' => null,
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Calendar
49+
|--------------------------------------------------------------------------
50+
|
51+
| Calendar to use (gregorian, traditional)
52+
*/
53+
'calendar' => 'gregorian',
4654
],
4755
'number' => [
4856
/*

src/Factory.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bakame\Intl\Laravel;
6+
7+
use Bakame\Intl\DateFactory;
8+
use Bakame\Intl\DateResolver;
9+
use Bakame\Intl\Formatter;
10+
use Bakame\Intl\NumberFactory;
11+
12+
final class Factory
13+
{
14+
private DateFactory $dateFactory;
15+
private NumberFactory $numberFactory;
16+
17+
public function __construct(DateFactory $dateFactory, NumberFactory $numberFactory)
18+
{
19+
$this->dateFactory = $dateFactory;
20+
$this->numberFactory = $numberFactory;
21+
}
22+
23+
/**
24+
* @param array{
25+
* date:array{
26+
* dateFormat:string,
27+
* timeFormat:string,
28+
* calendar:string,
29+
* pattern?:?string
30+
* },
31+
* number:array{
32+
* style:string,
33+
* attributes:array<string, int|float|string>,
34+
* textAttributes:array<string, string>,
35+
* symbolAttributes:array<string, string>,
36+
* pattern?:?string
37+
* }
38+
* } $settings
39+
*/
40+
public static function fromAssociative(array $settings): self
41+
{
42+
return new self(
43+
DateFactory::fromAssociative($settings['date']),
44+
NumberFactory::fromAssociative($settings['number'])
45+
);
46+
}
47+
48+
public function newInstance(DateResolver $dateResolver): Formatter
49+
{
50+
return new Formatter(
51+
$this->dateFactory,
52+
$this->numberFactory,
53+
$dateResolver
54+
);
55+
}
56+
}

src/Formatter.php renamed to src/IntlFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Illuminate\Support\Facades\Facade;
88

9-
final class Formatter extends Facade
9+
final class IntlFormatter extends Facade
1010
{
1111
/**
1212
* Get the registered name of the component.

src/Provider.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
namespace Bakame\Intl\Laravel;
66

7-
use Bakame\Intl\Configuration;
87
use Bakame\Intl\DateResolver;
98
use Bakame\Intl\Formatter;
10-
use Bakame\Intl\SystemDateResolver;
119
use Illuminate\Support\Carbon;
1210
use Illuminate\Support\ServiceProvider;
1311

1412
final class Provider extends ServiceProvider
1513
{
14+
public function boot(): void
15+
{
16+
$this->offerPublishing();
17+
}
18+
1619
public function register(): void
1720
{
1821
parent::register();
@@ -22,15 +25,28 @@ public function register(): void
2225
}
2326

2427
$this->mergeConfigFrom(BKM_INTL_FORMATTER.'/config/bakame-intl-formatter.php', 'bakame.intl.formatter.settings');
25-
$this->app->singleton('bakame.date.resolver', fn (): DateResolver => SystemDateResolver::fromTimeZone(
28+
$this->app->singleton('bakame.date.resolver', fn (): DateResolver => DateResolver::fromTimeZone(
2629
Carbon::now()->getTimezone()
2730
));
28-
$this->app->singleton('bakame.intl.formatter.config', fn ($app): Configuration => Configuration::fromApplication(
31+
32+
$this->app->singleton('bakame.intl.formatter.factory', fn ($app): Factory => Factory::fromAssociative(
2933
$app->make('config')->get('bakame.intl.formatter.settings')
3034
));
31-
$this->app->singleton('bakame.intl.formatter', fn ($app): Formatter => new Formatter(
32-
$app->make('bakame.intl.formatter.config'),
33-
$app->make('bakame.date.resolver')
34-
));
35+
36+
$this->app->singleton(
37+
'bakame.intl.formatter',
38+
fn ($app): Formatter => $app->make('bakame.intl.formatter.factory')->newInstance(
39+
$app->make('bakame.date.resolver')
40+
)
41+
);
42+
}
43+
44+
protected function offerPublishing(): void
45+
{
46+
if ($this->app->runningInConsole()) {
47+
$this->publishes([
48+
BKM_INTL_FORMATTER.'/config/bakame-intl-formatter.php' => config_path('bakame-intl-formatter.php'),
49+
], 'config');
50+
}
3551
}
3652
}

0 commit comments

Comments
 (0)