HEX
Server: LiteSpeed
System: Linux premium260.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: aliazzsr (627)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/aliazzsr/api.crm.vqode.com/components/actions/ValidateAction.php
<?php
namespace app\components\actions;

use app\components\BaseModel;
use yii\rest\Action;
use yii\web\NotFoundHttpException;

/**
 * Class ValidateAction
 * @package app\components\actions
 * @property BaseModel $modelClass
 */
class ValidateAction extends Action
{
    /**
     * @var string the scenario to be assigned to the model before it is validated and updated.
     */
    public $scenario = BaseModel::SCENARIO_STRICT_VALIDATE;

    /**
     * Validates model attributes  passed.
     *
     * @param integer $id model identifier
     * @return BaseModel
     * @throws \yii\base\InvalidConfigException
     * @throws NotFoundHttpException
     */
    public function run($id = null)
    {
        /** @var BaseModel $model */
        $model = $id ? $this->findModel($id) : new $this->modelClass();

        if(!$model) {
            throw new NotFoundHttpException();
        }

        if ($this->checkAccess) {
            call_user_func($this->checkAccess, $this->id, $model);
        }

        $params = \Yii::$app->getRequest()->getBodyParams();

        $model->scenario = $this->scenario;
        $model->load($params, '');
        $model->validate(array_keys($params));

        return $model;
    }
}