ldc-enum/tests/Enums/Days.php

78 lines
1.5 KiB
PHP
Raw Normal View History

2021-03-01 07:55:10 +01:00
<?php
namespace Kwaadpepper\Enum\Tests\Enums;
2021-09-11 11:09:10 +02:00
use Kwaadpepper\Enum\BaseEnumRoutable;
2021-03-01 07:55:10 +01:00
/**
* @method static self none()
* @method static self mon()
* @method static self tue()
* @method static self wed()
* @method static self thu()
* @method static self fri()
* @method static self sat()
* @method static self sun()
*/
2021-09-11 11:09:10 +02:00
final class Days extends BaseEnumRoutable
2021-03-01 07:55:10 +01:00
{
2023-05-30 09:27:27 +02:00
/**
* All values
*
* @return array
*/
2021-03-01 07:55:10 +01:00
protected static function values(): array
{
return [
2021-09-12 00:12:49 +02:00
'none' => 1,
'mon' => 1 << 1,
'tue' => 1 << 2,
'wed' => 1 << 3,
'thu' => 1 << 4,
'fri' => 1 << 5,
'sat' => 1 << 6,
'sun' => 1 << 7,
2021-03-01 07:55:10 +01:00
];
}
2023-05-30 09:27:27 +02:00
/**
* All labels
*
* @return array
*/
2021-03-01 07:55:10 +01:00
protected static function labels(): array
{
return [
'none' => 'None',
'mon' => 'Monday',
'tue' => 'Tuesday',
'wed' => 'Wednesday',
'thu' => 'Thursday',
'fri' => 'Friday',
'sat' => 'Saturday',
'sun' => 'Sunday'
];
}
2023-05-30 09:27:27 +02:00
/**
* Output the value as a string
*
* @return string
*/
2021-03-01 07:55:10 +01:00
public function __toString(): string
{
2021-09-11 11:09:10 +02:00
return (string)$this->label;
2021-03-01 07:55:10 +01:00
}
/**
* Checks if days contain this day
*
2023-05-30 09:27:27 +02:00
* @param integer $days
2021-03-01 07:55:10 +01:00
* @return boolean
*/
public function has(int $days)
{
return (bool)($this->value & $days);
}
}