PHP code example of k1low / stateful-enum

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

    

k1low / stateful-enum example snippets


class BugsTable extends Table
{
    const STATUS_UNASSIGNED = 'unassigned';
    const STATUS_ASSIGNED = 'assigned';
    const STATUS_RESOLVED = 'resolved';
    const STATUS_CLOSED = 'closed';

    public $transitions = [
        'status' => [
            'assign' => [
                'from' => self::STATUS_UNASSIGNED,
                'to' => self::STATUS_ASSIGNED
            ],
            'resolve' => [
                [self::STATUS_ASSIGNED, self::STATUS_UNASSIGNED], // from
                self::STATUS_RESOLVED // to
            ],
            'close' => [
                [self::STATUS_ASSIGNED, self::STATUS_UNASSIGNED, self::STATUS_RESOLVED],
                self::STATUS_CLOSED
            ],
        ]
    ];

    public function initialize(array $config)
    {
        $this->primaryKey('id');
        $this->addBehavior('StatefulEnum.StatefulEnum');
    }
}