PHP code example of php-arsenal / doctrine-odm-enum-type-bundle

1. Go to this page and download the library: Download php-arsenal/doctrine-odm-enum-type-bundle 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/ */

    

php-arsenal / doctrine-odm-enum-type-bundle example snippets




namespace YourNamespace\Enum;

use MyCLabs\Enum\Enum;

final class ActionEnum extends Enum
{
    private const CREATE = 'create';
    private const READ = 'read';
    private const UPDATE = 'update';
    private const DELETE = 'delete';
}




namespace YourNamespace\Entity;

use YourNamespace\Enum\ActionEnum;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ORM\Document()
 */
class User
{
    /**
     * @ODM\Field(type=ActionEnum::class, name="action")
     */
    protected $action;
    
    public function __construct() {
        $this->action = ActionEnum::CREATE();
    }

    public function getAction(): ActionEnum
    {
        return $this->action;
    }

    public function setAction(ActionEnum $action): void
    {
        $this->action = $action;
    }
}