PHP code example of fsmdev / constants-collection

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

    

fsmdev / constants-collection example snippets


use Fsmdev\ConstantsCollection\ConstantsCollection;

class PostStatus extends ConstantsCollection
{
    const EDITED = 1;
    const PUBLISHED = 2;
    const DELETED = 3;
}

$post = new Post();
$post->status = PostStatus::PUBLISHED;

class Post
{
    public function isPublished()
    {
        return $this->status == PostStatus::PUBLISHED;
    }
}

# class PostStatus

protected static function propertiesName()
{
    return [
        self::EDITED => 'Edited',
        self::PUBLISHED => 'Published',
        self::DELETED => 'Deleted',
    ];
}

protected static function propertiesIndicatorClass()
{
    return [
        self::EDITED => 'text-warning',
        self::PUBLISHED => 'text-success',
        self::DELETED => 'text-danger',
    ];
}

$status = PostStatus::value('Edited');