Merge branch 'vanilla-php' into 'develop'
refactor: ♻️ update enum trait toLabels method
See merge request ldc-web/projets/crm!22
This commit is contained in:
commit
ea360d9263
3 changed files with 249 additions and 244 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Traits\Enums;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Doctrine\Inflector\InflectorFactory;
|
||||
|
||||
trait BaseEnum
|
||||
{
|
||||
|
|
@ -53,8 +53,8 @@ trait BaseEnum
|
|||
if (!\is_null($labels) and !isset($labels[$enum->name])) {
|
||||
throw new \Error('Missing definition label ' . self::class . " for {$enum->name}");
|
||||
}
|
||||
$array = array_merge($array, [$enum->name => \trans(
|
||||
!\is_null($labels) ? $labels[$enum->name] : Str::ucfirst($enum->name)
|
||||
$array = array_merge($array, [$enum->name => __(
|
||||
!\is_null($labels) ? $labels[$enum->name] : ucfirst($enum->name)
|
||||
)]);
|
||||
}, self::cases());
|
||||
self::setCache('labels', $array);
|
||||
|
|
@ -99,14 +99,15 @@ trait BaseEnum
|
|||
if (empty(self::getCache('enums'))) {
|
||||
$definitions = self::getCustomDefinitions();
|
||||
$array = [];
|
||||
\array_map(function ($enum) use (&$array, $definitions) {
|
||||
$inflector = InflectorFactory::create()->build();
|
||||
\array_map(function ($enum) use (&$array, $definitions, $inflector) {
|
||||
$baseArray = [
|
||||
'name' => $enum->name,
|
||||
'label' => $enum->label(),
|
||||
'value' => $enum->value,
|
||||
];
|
||||
foreach ($definitions as $index => $elements) {
|
||||
$index = Str::lower(Str::singular($index));
|
||||
$index = $inflector->singularize(strtolower($index));
|
||||
if (!isset($elements[$enum->name])) {
|
||||
throw new \Error("Missing definition {$index} " . self::class . " for {$enum->name}");
|
||||
}
|
||||
|
|
@ -115,7 +116,7 @@ trait BaseEnum
|
|||
$array = array_merge($array, [$enum->name => (object)$baseArray]);
|
||||
}, self::cases());
|
||||
self::setCache('enums', $array);
|
||||
}
|
||||
} //end if
|
||||
return self::getCache('enums');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ldc/ldccrm",
|
||||
"version": "4.0.1",
|
||||
"version": "4.0.4",
|
||||
"type": "project",
|
||||
"description": "LDC CRM",
|
||||
"license": "MIT",
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
"axlon/laravel-postal-code-validation": "^3.2",
|
||||
"diglactic/laravel-breadcrumbs": "^8.1",
|
||||
"doctrine/dbal": "^3.0",
|
||||
"doctrine/inflector": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"laravel/framework": "^10.0",
|
||||
"laravel/tinker": "^2.8",
|
||||
|
|
|
|||
477
composer.lock
generated
477
composer.lock
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue