PHP code example of typiqally / enum

1. Go to this page and download the library: Download typiqally/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/ */

    

typiqally / enum example snippets


use Typiqally\Enum\Enum;

/**
 * @method static self NORTH()
 * @method static self EAST()
 * @method static self SOUTH()
 * @method static self WEST()
 */
class Direction extends Enum
{
}

public function walk(Direction $direction): void {
    //Walk logic
}

$this->walk(Direction::NORTH());

use Typiqally\Enum\Enum;

/**
 * @method static self NORTH()
 * @method static self EAST()
 * @method static self SOUTH()
 * @method static self WEST()
 */
class Direction extends Enum
{
    protected static function values(): array
    {
        return [
            'NORTH' => [
                'degrees' => 0 | 360
            ],
            'EAST' => [
                'degrees' => 90
            ],
            'SOUTH' => [
                'degrees' => 180
            ],
            'WEST' => [
                'degrees' => 270
            ]
        ];
    }

    public function getDegrees(): int
    {
        return $this->value['degrees'];
    }
}

public function walk(Direction $direction): void {
    $degrees = $direction->getDegrees();
}

$this->walk(Direction::NORTH());