PHP code example of maisner / enum

1. Go to this page and download the library: Download maisner/enum library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maisner / enum example snippets


 declare(strict_types = 1);

use Maisner\Enum\AbstractEnum;

class TypeEnum extends AbstractEnum {

	public const TEMPERATURE = 'temperature';

	public const HUMIDITY = 'humidity';

	/**
	 * @return array|string[]
	 */
	protected static function allowedValues(): array {
		return [
			self::TEMPERATURE,
			self::HUMIDITY
		];
	}

	/**
	 * @return TypeEnum
	 */
	public static function TEMPERATURE(): self {
		return new self(self::TEMPERATURE);
	}

	/**
	 * @return TypeEnum
	 */
	public static function HUMIDITY(): self {
		return new self(self::HUMIDITY);
	}
}

$type = TypeEnum::TEMPERATURE();

$type->getValue();	//temperature
(string)$type;		//temperature