67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
use App\Enums\Contact\ContactFormType;
|
|
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
|
|
|
enum StaticRoutesEnum: int
|
|
{
|
|
use BaseEnum;
|
|
|
|
// Set all cases for each static routes.
|
|
case collaborator = 1;
|
|
case breeder = 2;
|
|
case professional = 3;
|
|
case restauration = 4;
|
|
case export = 5;
|
|
case finance = 6;
|
|
case commitments = 7;
|
|
case product = 8;
|
|
case info = 9;
|
|
case press = 10;
|
|
case search = 11;
|
|
|
|
/**
|
|
* Get array of each route with his matching value.
|
|
*
|
|
* @param callable|null $callback
|
|
* @return array
|
|
*/
|
|
public static function getRoutes(?callable $callback = null): array
|
|
{
|
|
$dataKeyValue = array_merge(ContactFormType::getLabelisedRoutes(), [
|
|
self::search->name => (object) [
|
|
'label' => trans('front.search.title'),
|
|
'route' => '/recherche?texte=LDC',
|
|
]
|
|
]);
|
|
return collect($dataKeyValue)
|
|
->reject(fn($item) => is_null($item->label) || is_null($item->route))
|
|
->map(function ($item, $key) {
|
|
$targetEnum = collect(self::cases())
|
|
->first(fn($enum) => $enum->name === $key);
|
|
|
|
return (object) [
|
|
'label' => ucfirst($item->label),
|
|
'value' => $targetEnum->value,
|
|
'route' => $item->route,
|
|
];
|
|
})
|
|
->when(!is_null($callback), fn ($collection) => $collection->filter($callback))
|
|
->values()
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* Get the url of a given enum value.
|
|
*
|
|
* @param integer $value
|
|
* @return string|null
|
|
*/
|
|
public static function getRoute(int $value): ?string
|
|
{
|
|
$collect = collect(self::getRoutes(fn ($route) => $route->value == $value));
|
|
return $collect->isEmpty() ? null : $collect->first()->route;
|
|
}
|
|
}
|