PHP code example of annotation / enumeration

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

    

annotation / enumeration example snippets


use Annotation\Enumeration\Attributes\Enumeration;

class User
{
    use HasEnumeration;

    #[Enumeration([
        'WAIT' => '待审核',
        'PASSED' => '成功',
        'FAILED' => '失败',
    ])]
    public function status()
    {
        //return $this->getAttributeEnumeration('status');
    }

}

$user = new User();

$user->status();

$user->getAttributeEnumerations();
//[
//    'status' => [
//        'wait' => '待审核',
//        'passed' => '成功',
//        'failed' => '失败',
//    ],
//];

$user->getAttributeEnumeration('status', 'WAIT', '--');
// 待审核

$user->getAttributeEnumeration('status', '', '--');
// --

$user->getEnumeration($user->getAttributeEnumeration('status'), 'PASSED', '--');
// 成功