k1low/stateful-enum

Simple stateful enum plugin for CakePHP 3

Fund package maintenance!
k1LoW

Installs: 2 531

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 2

Open Issues: 0

Type:cakephp-plugin

v0.1.0 2016-04-06 06:03 UTC

This package is auto-updated.

Last update: 2024-12-06 09:56:18 UTC


README

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require k1low/stateful-enum

Usage

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');
    }
}

So, This plugin set build state rules automatically.

References

This plugin is inspired by https://github.com/amatsuda/stateful_enum