Skip to content

Commit

Permalink
- Added Config dependency.
Browse files Browse the repository at this point in the history
- Added TypeParser dependency.
- Modified Formatter to be instantiated class.
- Updated PHPUnit.
- Updated tests.
- Updated README.
  • Loading branch information
elusivecodes committed Nov 17, 2024
1 parent 7dfa9fd commit 8dfb338
Show file tree
Hide file tree
Showing 5 changed files with 2,324 additions and 2,103 deletions.
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Table Of Contents
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)


Expand All @@ -24,6 +25,41 @@ use Fyre\Utility\Formatter;
```


## Basic Usage

- `$typeParser` is a [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser).
- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).

```php
$formatter = new Formatter($typeParser, $config);
```

Default configuration options will be resolved from the "*App*" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).

- `$options` is an array containing configuration options.
- `locale` is a string representing the default locale, and will default to the system default.
- `timeZone` is a string representing the default time zone, and will default to the system default.
- `currency` is a string representing the default currency, and will default to "*USD*".

```php
$container->use(Config::class)->set('App', $options);
```

**Autoloading**

It is recommended to bind the *Formatter* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```php
$container->singleton(Formatter::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```php
$formatter = $container->use(Formatter::class);
```


## Methods

**Currency**
Expand All @@ -36,7 +72,7 @@ Format a value as a currency string.
- `$currency` is a string representing the currency, and will default to the *Formatter* default currency.

```php
$currency = Formatter::currency($value, $options);
$currency = $formatter->currency($value, $options);
```

**Date**
Expand All @@ -50,7 +86,7 @@ Format a [*DateTime*](https://github.com/elusivecodes/FyreDateTime) as a date st
- `$format` is a string representing the format, and will default to the [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser) default date user format.

```php
$date = Formatter::date($value, $options);
$date = $formatter->date($value, $options);
```

**Date/Time**
Expand All @@ -64,31 +100,31 @@ Format a [*DateTime*](https://github.com/elusivecodes/FyreDateTime) as a date/ti
- `$format` is a string representing the format, and will default to the [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser) default datetime user format.

```php
$datetime = Formatter::datetime($value, $options);
$datetime = $formatter->datetime($value, $options);
```

**Get Default Currency**

Get the default currency.

```php
$defaultCurrency = Formatter::getDefaultCurrency();
$defaultCurrency = $formatter->getDefaultCurrency();
```

**Get Default Locale**

Get the default locale.

```php
$defaultLocale = Formatter::getDefaultLocale();
$defaultLocale = $formatter->getDefaultLocale();
```

**Get Default Time Zone**

Get the default time zone.

```php
$defaultTimeZone = Formatter::getDefaultTimeZone();
$defaultTimeZone = $formatter->getDefaultTimeZone();
```

**Number**
Expand All @@ -100,7 +136,7 @@ Format a value as a number string.
- `$locale` is a string representing the locale, and will default to the *Formatter* default locale.

```php
$number = Formatter::number($value, $options);
$number = $formatter->number($value, $options);
```

**Percent**
Expand All @@ -112,7 +148,7 @@ Format a value as a percent string.
- `$locale` is a string representing the locale, and will default to the *Formatter* default locale.

```php
$percent = Formatter::percent($value, $options);
$percent = $formatter->percent($value, $options);
```

**Set Default Currency**
Expand All @@ -122,7 +158,7 @@ Set the default currency.
- `$currency` is a string representing the currency code, or a *Closure* that returns the currency code.

```php
Formatter::setDefaultCurrency($currency);
$formatter->setDefaultCurrency($currency);
```

**Set Default Locale**
Expand All @@ -132,7 +168,7 @@ Set the default locale.
- `$locale` is a string representing the locale, or a *Closure* that returns the locale.

```php
Formatter::setDefaultLocale($locale);
$formatter->setDefaultLocale($locale);
```

**Set Default Time Zone**
Expand All @@ -142,7 +178,7 @@ Set the default time zone.
- `$timeZone` is a string representing the time zone, or a *Closure* that returns the time zone.

```php
Formatter::setDefaultTimeZone($timeZone);
$formatter->setDefaultTimeZone($timeZone);
```

**Time**
Expand All @@ -156,5 +192,5 @@ Format a [*DateTime*](https://github.com/elusivecodes/FyreDateTime) as a time st
- `$format` is a string representing the format, and will default to the [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser) default time user format.

```php
$time = Formatter::time($value, $options);
$time = $formatter->time($value, $options);
```
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
}
},
"require": {
"fyre/config": "^4.1",
"fyre/datetime": "^3.0",
"fyre/typeparser": "^3.0"
"fyre/typeparser": "^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.59",
"fyre/php-cs-fixer-config": "^1.0",
"phpunit/phpunit": "^10"
"phpunit/phpunit": "^11"
},
"scripts": {
"cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff",
Expand Down
Loading

0 comments on commit 8dfb338

Please sign in to comment.