79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
use Kwaadpepper\Enum\BaseEnum;
|
|
|
|
/**
|
|
* @method static self noLetter()
|
|
* @method static self aLetter()
|
|
* @method static self bLetter()
|
|
* @method static self cLetter()
|
|
* @method static self dLetter()
|
|
* @method static self eLetter()
|
|
*/
|
|
final class NutriscoreEnum extends BaseEnum
|
|
{
|
|
/**
|
|
* Enum values
|
|
*
|
|
* @return array
|
|
*/
|
|
protected static function values(): array
|
|
{
|
|
return [
|
|
'noLetter' => 0,
|
|
'aLetter' => 1,
|
|
'bLetter' => 2,
|
|
'cLetter' => 3,
|
|
'dLetter' => 4,
|
|
'eLetter' => 5
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Enum labels
|
|
*
|
|
* @return array
|
|
*/
|
|
protected static function labels(): array
|
|
{
|
|
return [
|
|
'noLetter' => 'N/A',
|
|
'aLetter' => 'A',
|
|
'bLetter' => 'B',
|
|
'cLetter' => 'C',
|
|
'dLetter' => 'D',
|
|
'eLetter' => 'E'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Enum stickers associés
|
|
*
|
|
* @return array
|
|
*/
|
|
protected static function stickers(): array
|
|
{
|
|
return [
|
|
'noLetter' => '',
|
|
'aLetter' => \asset('build/assets/images/nutriscore/logo-nutriscore-A.png'),
|
|
'bLetter' => \asset('build/assets/images/nutriscore/logo-nutriscore-B.png'),
|
|
'cLetter' => \asset('build/assets/images/nutriscore/logo-nutriscore-C.png'),
|
|
'dLetter' => \asset('build/assets/images/nutriscore/logo-nutriscore-D.png'),
|
|
'eLetter' => \asset('build/assets/images/nutriscore/logo-nutriscore-E.png'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param string $attribute
|
|
* @return integer|string
|
|
*/
|
|
public function __get(string $attribute)
|
|
{
|
|
if ($attribute === 'sticker') {
|
|
return $this->stickers()[$this->getDefinition()] ?? null;
|
|
}
|
|
return parent::__get($attribute);
|
|
}
|
|
}
|