chore: ⬆️ bump to v4.0.3
This commit is contained in:
parent
a4f962c9a7
commit
b0eb36daed
5 changed files with 61 additions and 50 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
### All notable changes to `CRM CLient V4` will be documented in this file.
|
||||
|
||||
# version 4.0.3
|
||||
- chore: :arrow_up: bump to v4.0.3
|
||||
|
||||
# version 4.0.2
|
||||
- chore: :arrow_up: bump to v4.0.2
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "4.0.2",
|
||||
"version": "4.0.3",
|
||||
"timestampTimeout": 30,
|
||||
"apiRequestRatePerMinute": 256,
|
||||
"servicesDBCache": 10
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"type": "library",
|
||||
"description": "LDC CRM Client V4",
|
||||
"license": "MIT",
|
||||
"version": "4.0.2",
|
||||
"version": "4.0.3",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jérémy Munsch",
|
||||
|
|
|
|||
|
|
@ -517,33 +517,30 @@ enum Country: int
|
|||
* Get valid countries label.
|
||||
*
|
||||
* @return array<string>
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getValidCountriesLabel(): array
|
||||
{
|
||||
return collect(self::getValidCountries())->map(function (self $country) {
|
||||
return \array_map(function (self $country) {
|
||||
return $country->label();
|
||||
})->all();
|
||||
}, self::getValidCountries());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid countries value.
|
||||
*
|
||||
* @return array<string|integer>
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getValidCountriesValues(): array
|
||||
{
|
||||
return collect(self::getValidCountries())->map(function (self $country) {
|
||||
return \array_map(function (self $country) {
|
||||
return $country->value();
|
||||
})->all();
|
||||
}, self::getValidCountries());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Alpha 2 ISO code of valid countries
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getValidIsoAplha2Codes(): array
|
||||
{
|
||||
|
|
@ -554,7 +551,6 @@ enum Country: int
|
|||
* Get valid countries
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function getValidCountries(): array
|
||||
{
|
||||
|
|
@ -606,7 +602,6 @@ enum Country: int
|
|||
/**
|
||||
* @param string $attribute
|
||||
* @return integer|string|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function get(string $attribute): int|string|null
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,15 +48,16 @@ trait BaseEnum
|
|||
{
|
||||
if (empty(self::getCache('labels'))) {
|
||||
$labels = self::getLabelsConstant();
|
||||
self::setCache('labels', \collect(self::cases())
|
||||
->mapWithKeys(function ($enum) use ($labels) {
|
||||
if (!\is_null($labels) and !isset($labels[$enum->name])) {
|
||||
throw new \Error('Missing definition label ' . self::class . " for {$enum->name}");
|
||||
}
|
||||
return [$enum->name => \trans(
|
||||
!\is_null($labels) ? $labels[$enum->name] : Str::ucfirst($enum->name)
|
||||
)];
|
||||
})->all());
|
||||
$array = [];
|
||||
\array_map(function ($enum) use (&$array, $labels) {
|
||||
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)
|
||||
)]);
|
||||
}, self::cases());
|
||||
self::setCache('labels', $array);
|
||||
}
|
||||
return self::getCache('labels');
|
||||
}
|
||||
|
|
@ -69,8 +70,11 @@ trait BaseEnum
|
|||
public static function toValues(): array
|
||||
{
|
||||
if (empty(self::getCache('values'))) {
|
||||
self::setCache('values', \collect(self::cases())
|
||||
->mapWithKeys(fn ($enum) => [$enum->name => $enum->value])->all());
|
||||
$array = [];
|
||||
\array_map(function ($enum) use (&$array) {
|
||||
$array = array_merge($array, [$enum->name => $enum->value]);
|
||||
}, self::cases());
|
||||
self::setCache('values', $array);
|
||||
}
|
||||
return self::getCache('values');
|
||||
}
|
||||
|
|
@ -94,22 +98,23 @@ trait BaseEnum
|
|||
{
|
||||
if (empty(self::getCache('enums'))) {
|
||||
$definitions = self::getCustomDefinitions();
|
||||
self::setCache('enums', \collect(self::cases())
|
||||
->mapWithKeys(function ($enum) use ($definitions) {
|
||||
$baseArray = [
|
||||
'name' => $enum->name,
|
||||
'label' => $enum->label(),
|
||||
'value' => $enum->value,
|
||||
];
|
||||
foreach ($definitions as $index => $elements) {
|
||||
$index = Str::lower(Str::singular($index));
|
||||
if (!isset($elements[$enum->name])) {
|
||||
throw new \Error("Missing definition {$index} " . self::class . " for {$enum->name}");
|
||||
}
|
||||
$baseArray[$index] = $elements[$enum->name];
|
||||
$array = [];
|
||||
\array_map(function ($enum) use (&$array, $definitions) {
|
||||
$baseArray = [
|
||||
'name' => $enum->name,
|
||||
'label' => $enum->label(),
|
||||
'value' => $enum->value,
|
||||
];
|
||||
foreach ($definitions as $index => $elements) {
|
||||
$index = Str::lower(Str::singular($index));
|
||||
if (!isset($elements[$enum->name])) {
|
||||
throw new \Error("Missing definition {$index} " . self::class . " for {$enum->name}");
|
||||
}
|
||||
return [$enum->name => (object)$baseArray];
|
||||
})->all());
|
||||
$baseArray[$index] = $elements[$enum->name];
|
||||
}
|
||||
$array = array_merge($array, [$enum->name => (object)$baseArray]);
|
||||
}, self::cases());
|
||||
self::setCache('enums', $array);
|
||||
}
|
||||
return self::getCache('enums');
|
||||
}
|
||||
|
|
@ -118,13 +123,12 @@ trait BaseEnum
|
|||
* Fetch enum using value.
|
||||
*
|
||||
* @param \LDC\LDCCRM\Traits\BaseEnum|integer|string $value
|
||||
* @param string $field
|
||||
* @param string $field
|
||||
* @return \LDC\LDCCRM\Traits\BaseEnum|null
|
||||
*/
|
||||
public static function make(self|int|string $value, string $field = 'value'): self|null
|
||||
{
|
||||
return !\is_object($value) ?
|
||||
\collect(self::cases())->keyBy($field)->get($value) : $value;
|
||||
return !\is_object($value) ? self::cases()[array_search($value, array_column(self::cases(), $field))] : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,8 +208,8 @@ trait BaseEnum
|
|||
{
|
||||
if (!isset($GLOBALS[self::class])) {
|
||||
$GLOBALS[self::class] = [
|
||||
'props' => [
|
||||
'enums' => [],
|
||||
'props' => [
|
||||
'enums' => [],
|
||||
'values' => [],
|
||||
'labels' => []
|
||||
],
|
||||
|
|
@ -241,17 +245,26 @@ trait BaseEnum
|
|||
{
|
||||
// ? Has custom props in cache ?
|
||||
if (!isset($GLOBALS[self::class]) or \is_null($GLOBALS[self::class]['customProps'])) {
|
||||
$names = \collect(self::cases())->keyBy('name');
|
||||
$names = [];
|
||||
\array_map(function (self $enum) use (&$names) {
|
||||
$names = array_merge($names, [$enum->name => $enum]);
|
||||
}, self::cases());
|
||||
|
||||
$GLOBALS[self::class]['customProps'] = \collect((new \ReflectionClass(self::class))->getConstants())
|
||||
->filter(function (mixed $constant, string $key) use ($names) {
|
||||
if ($key === 'LABELS' or !\is_array($constant)) {
|
||||
$GLOBALS[self::class]['customProps'] = \array_map(
|
||||
function (mixed $enum) use ($names) {
|
||||
if (!\is_array($enum)) {
|
||||
return false;
|
||||
}
|
||||
return \collect($constant)->keys()
|
||||
->filter(fn (string $name) => $names->has($name))->count();
|
||||
})->all();
|
||||
}
|
||||
return count(\array_filter(
|
||||
$enum,
|
||||
function (string $name) use ($names) {
|
||||
return array_key_exists($name, $names);
|
||||
}
|
||||
));
|
||||
},
|
||||
array_flip((new \ReflectionClass(self::class))->getConstants()),
|
||||
);
|
||||
} //end if
|
||||
return $GLOBALS[self::class]['customProps'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue