The database frequently changes the "status status" field, so how to maintain the program more conveniently

in actual projects, customers often clap their heads and decide to add and delete some status fields.
take a chestnut, for example, to publish an article, the initial status status field has only two, one is the "unpublished" status, and the other is the "published" status.
later, the customer asked to add a "under review" status, and then asked to add a "deleted".
status changes, along with a series of methods such as data statistics, operation log, integral calculation, query filtering, and so on, or even worse, some judgments made using this status status field also have to change.
so the question is how to encapsulate status fields to optimize? Or what should other methods pay attention to when calling this field?


I have also encountered that at first there were only one or two states, but then there were more and more statuses.
later I wrote status into a class, similar to a demo

that I wrote below.
class Status
{
    public static $all_status = array(
        0 => array(
            'label' => '',
            'value' => 0,
            'point' => 1,  -sharp 
            'private' => true  -sharp 
        ),
        1 => array(
            'label' => '',
            'value' => 1,
            'point' => 2,  -sharp 
            'private' => true  -sharp 
        ),
        2 => array(
            'label' => '',
            'value' => 2,
            'point' => 10,  -sharp 
            'private' => false  -sharp 
        ),
    );

    public function __construct($status)
    {
        $this->status = self::$all_status[$status];
    }

    /**  */
    public function canShow()
    {
        if($this->status['private'] === false) {
            return true;
        }
        return false;
    }

    /**  */
    public function canDoSomething()
    {
        -sharp ...
        return true;
    }
}

$article = array(
    'content' => '',
    'title' => '',
    'status' => 2
);
$statusObj = new Status($article['status']);
if($statusObj->canShow()){
    showArticle($article)
}

in this way, you can make fewer changes when you add or subtract status . If there is a better way, by the way, @ me

.
Menu