Skip to content

Commit

Permalink
Added Civilities enum
Browse files Browse the repository at this point in the history
  • Loading branch information
forxer committed Jun 10, 2024
1 parent 68d93eb commit 133bbe8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

10.1.0 (2024-06-10)
-------------------

- Added Civilities enum


10.0.3 (2024-05-29)
-------------------

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Includes a set of useful tools for the Laravel framework.
* [Helpers](#helpers)
* [Blade directives](#blade-directives)
* [Components](#components)
* [Enums](#enums)

Installation
------------
Expand Down Expand Up @@ -306,3 +307,17 @@ In your forms you can indicate the required fields for example in this way:
```blade
{!! trans('misc.info_required_fields'); !!} <x-required-field-marker />
```

Enums
-----

### Civilities

An enumeration to handle civilities is available with `Axn\ToolKit\Enums\Civilities`


```php
use Axn\ToolKit\Enums\Civilities;
```

@todo: need to document this
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": "^8.2",
"composer/semver": "^3.0.0",
"forxer/generic-term-translations-for-laravel": "^1.6.0",
"forxer/generic-term-translations-for-laravel": "^1.8",
"laravel/framework": "^10.0 || ^11.0"
},
"require-dev": {
Expand Down
1 change: 0 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"blank_line_before_statement": {
"statements": [
"break",
"case",
"continue",
"declare",
Expand Down
48 changes: 48 additions & 0 deletions src/Enums/Civilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Axn\ToolKit\Enums;

enum Civilities: int
{
case None = 0;

case Mrs = 1;

case Mr = 2;

public function title(): string
{
return self::titles()[$this->value];
}

public function abbr(): string
{
return self::abbreviations()[$this->value];
}

/**
* Returns an array of human readable values.
*/
public static function titles(): array
{
return [
self::None->value => '',
self::Mrs->value => trans('civilities.mrs'),
self::Mr->value => trans('civilities.mr'),
];
}

/**
* Returns an array of bootstrap colors values.
*/
public static function abbreviations(): array
{
return [
self::None->value => '',
self::Mrs->value => trans('civilities.mrs_abbr'),
self::Mr->value => trans('civilities.mr_abbr'),
];
}
}

0 comments on commit 133bbe8

Please sign in to comment.