chore: ⬆️ update laravel-common to v4.1.0
This commit is contained in:
parent
1aaadb88d0
commit
ded7cd7266
18 changed files with 22 additions and 332 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\ActivityLogs;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ActivityLogsEventEnum: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ApiError: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ApiStatus: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ArcadiaMailType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ArcadiaOrderType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimMessageType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimResponseType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimStatus: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Claims;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ClaimType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum Country: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum CustomerExportType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Pagination;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ItemsPerPaginationEnum: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum QuestionType: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Theme;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum BootstrapThemeEnum: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums\Users;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
||||
|
||||
enum RoleEnum: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,310 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Traits\Enums;
|
||||
|
||||
use Doctrine\Inflector\InflectorFactory;
|
||||
|
||||
trait BaseEnum
|
||||
{
|
||||
// * GENERIC METHODS
|
||||
/**
|
||||
* Get enum value.
|
||||
*
|
||||
* @return string|integer
|
||||
*/
|
||||
public function value(): string|int
|
||||
{
|
||||
return self::toValues()[$this->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enum label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return self::toLabels()[$this->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enum name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
// * STATIC FETCH METHODS
|
||||
|
||||
/**
|
||||
* Get enum labels.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function toLabels(): array
|
||||
{
|
||||
if (empty(self::getCache('labels'))) {
|
||||
$labels = self::getLabelsConstant();
|
||||
$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 => __(
|
||||
!\is_null($labels) ? $labels[$enum->name] : ucfirst($enum->name)
|
||||
)]);
|
||||
}, self::cases());
|
||||
self::setCache('labels', $array);
|
||||
}
|
||||
return self::getCache('labels');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enum values.
|
||||
*
|
||||
* @return array<integer|string>
|
||||
*/
|
||||
public static function toValues(): array
|
||||
{
|
||||
if (empty(self::getCache('values'))) {
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function all(): array
|
||||
{
|
||||
return self::cases();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enums.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toArray(): array
|
||||
{
|
||||
if (empty(self::getCache('enums'))) {
|
||||
$definitions = self::getCustomDefinitions();
|
||||
$array = [];
|
||||
$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 = $inflector->singularize(strtolower($index));
|
||||
if (!isset($elements[$enum->name])) {
|
||||
throw new \Error("Missing definition {$index} " . self::class . " for {$enum->name}");
|
||||
}
|
||||
$baseArray[$index] = $elements[$enum->name];
|
||||
}
|
||||
$array = array_merge($array, [$enum->name => (object)$baseArray]);
|
||||
}, self::cases());
|
||||
self::setCache('enums', $array);
|
||||
} //end if
|
||||
return self::getCache('enums');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch enum using value.
|
||||
*
|
||||
* @param \App\Traits\Enums\BaseEnum|integer|string $value
|
||||
* @param string $field
|
||||
* @return \App\Traits\Enums\BaseEnum|null
|
||||
*/
|
||||
public static function make(self|int|string $value, string $field = 'value'): self|null
|
||||
{
|
||||
return !\is_object($value) ? self::cases()[array_search($value, array_column(self::cases(), $field))] : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if 2 enum are equals.
|
||||
*
|
||||
* @param object ...$others
|
||||
* @return boolean
|
||||
* @throws \Error If provided element are not enums taht extends BaseEnum.
|
||||
*/
|
||||
public function equals(object ...$others): bool
|
||||
{
|
||||
foreach ($others as $other) {
|
||||
if (!\in_array(BaseEnum::class, $this->classUsesRecursive($other))) {
|
||||
throw new \Error(__METHOD__ .
|
||||
' requires $enum to use ' . BaseEnum::class);
|
||||
}
|
||||
if (
|
||||
get_class($this) === get_class($other)
|
||||
&& $this->value === $other->value
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize to json.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
// * CACHE
|
||||
|
||||
/**
|
||||
* Get cache array.
|
||||
*
|
||||
* @param string $index
|
||||
* @return array
|
||||
*/
|
||||
private static function getCache(string $index): array
|
||||
{
|
||||
self::initCache();
|
||||
if (!isset($GLOBALS[self::class]['props'][$index])) {
|
||||
$GLOBALS[self::class]['props'][$index] = [];
|
||||
}
|
||||
return $GLOBALS[self::class]['props'][$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache array.
|
||||
*
|
||||
* @param string $index
|
||||
* @param array $items
|
||||
* @return void
|
||||
*/
|
||||
private static function setCache(string $index, array $items): void
|
||||
{
|
||||
self::initCache();
|
||||
if (!isset($GLOBALS[self::class]['props'][$index])) {
|
||||
$GLOBALS[self::class]['props'][$index] = [];
|
||||
}
|
||||
$GLOBALS[self::class]['props'][$index] = $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init cache if needed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function initCache(): void
|
||||
{
|
||||
if (!isset($GLOBALS[self::class])) {
|
||||
$GLOBALS[self::class] = [
|
||||
'props' => [
|
||||
'enums' => [],
|
||||
'values' => [],
|
||||
'labels' => []
|
||||
],
|
||||
'customProps' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// * PRIVATE
|
||||
|
||||
/**
|
||||
* Fetch the LABELS constant if exists.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
private static function getLabelsConstant(): array|null
|
||||
{
|
||||
$class_name = self::class;
|
||||
try {
|
||||
$constant_reflex = new \ReflectionClassConstant($class_name, 'LABELS');
|
||||
return $constant_reflex->getValue();
|
||||
} catch (\ReflectionException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom constants.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getCustomDefinitions(): array
|
||||
{
|
||||
// ? Has custom props in cache ?
|
||||
if (!isset($GLOBALS[self::class]) or \is_null($GLOBALS[self::class]['customProps'])) {
|
||||
$names = [];
|
||||
\array_map(function (self $enum) use (&$names) {
|
||||
$names = array_merge($names, [$enum->name => $enum]);
|
||||
}, self::cases());
|
||||
|
||||
$GLOBALS[self::class]['customProps'] = \array_filter(
|
||||
(new \ReflectionClass(self::class))->getConstants(),
|
||||
function (mixed $constant, string $key) use ($names) {
|
||||
if ($key === 'LABELS' or !\is_array($constant)) {
|
||||
return false;
|
||||
}
|
||||
return count(\array_filter(
|
||||
array_flip($constant),
|
||||
function (string $name) use ($names) {
|
||||
return array_key_exists($name, $names);
|
||||
}
|
||||
));
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
} //end if
|
||||
return $GLOBALS[self::class]['customProps'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all traits used by a class, its parent classes and trait of their traits.
|
||||
*
|
||||
* @param object|string $class
|
||||
* @return array
|
||||
*/
|
||||
private function classUsesRecursive($class)
|
||||
{
|
||||
if (is_object($class)) {
|
||||
$class = get_class($class);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach (array_reverse(class_parents($class) ?: []) + [$class => $class] as $class) {
|
||||
$results += $this->traitUsesRecursive($class);
|
||||
}
|
||||
|
||||
return array_unique($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all traits used by a trait and its traits.
|
||||
*
|
||||
* @param object|string $trait
|
||||
* @return array
|
||||
*/
|
||||
private function traitUsesRecursive($trait)
|
||||
{
|
||||
$traits = class_uses($trait) ?: [];
|
||||
|
||||
foreach ($traits as $trait) {
|
||||
$traits += $this->traitUsesRecursive($trait);
|
||||
}
|
||||
|
||||
return $traits;
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
"sentry/sentry-laravel": "^4.10",
|
||||
"uwil/admin-secure-laravel": "^3.0",
|
||||
"uwil/k8s-laravel": "^1.4",
|
||||
"uwil/laravel-common": "^3.4"
|
||||
"uwil/laravel-common": "^4.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^7.2",
|
||||
|
|
|
|||
12
composer.lock
generated
12
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ee8bdd66e3ddef5e410f2b2a7d852c2b",
|
||||
"content-hash": "0009b353976d02e41558711de87179a6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "24slides/laravel-saml2",
|
||||
|
|
@ -7859,16 +7859,16 @@
|
|||
},
|
||||
{
|
||||
"name": "uwil/laravel-common",
|
||||
"version": "3.4.3",
|
||||
"version": "4.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "git@lab.s-web.fr:ldc-web/projets/laravel-common.git",
|
||||
"reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df"
|
||||
"reference": "01af52e206e690d511752e9f6a52c8b2c537ca8a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://lab.s-web.fr/api/v4/projects/215/packages/composer/archives/uwil/laravel-common.zip?sha=e4d69be567729f0e32379b4ed1ed8cd0dc3746df",
|
||||
"reference": "e4d69be567729f0e32379b4ed1ed8cd0dc3746df",
|
||||
"url": "https://lab.s-web.fr/api/v4/projects/215/packages/composer/archives/uwil/laravel-common.zip?sha=01af52e206e690d511752e9f6a52c8b2c537ca8a",
|
||||
"reference": "01af52e206e690d511752e9f6a52c8b2c537ca8a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -7876,7 +7876,7 @@
|
|||
"kwaadpepper/image-resizer": "^3.0",
|
||||
"laravel/framework": "~11|~12",
|
||||
"mews/purifier": "^3.4",
|
||||
"php": "~8.3",
|
||||
"php": "^8.3",
|
||||
"sentry/sentry-laravel": "^4.10"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue