HEX
Server: LiteSpeed
System: Linux d8 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: wbwebdes (3015)
PHP: 8.1.31
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/wbwebdes/domains/survey.wb-webdesign.com/private_html/application/models/PluginDynamic.php
<?php

/**
 * Dynamic model used by plugins to access their table(s).
 */
class PluginDynamic extends LSActiveRecord
{
    private static $models = array();

    /** @var CActiveRecordMetaData $md meta data*/
    private $md;

    /** @var null|string $tableName */
    protected $tableName;

    /**
     * @param string $sTableName
     * @param string $scenario
     * @throws Exception
     */
    public function __construct($sTableName = null, $scenario = 'insert')
    {
        if (!isset($sTableName)) {
            //Yii::trace('sTableName missing.');
            throw new Exception('sTableName missing.');
        }
        $this->tableName = $sTableName;
        parent::__construct($scenario);
    }

    /** @inheritdoc */
    protected function instantiate($attributes = null)
    {
        $class = get_class($this);
        $model = new $class($this->tableName(), null);
        return $model;
    }

    /**
     * We have a custom implementation here since the parents' implementation
     * does not create a new model for each table name.
     *
     * @param string $className Table name
     * @return Plugin
     */
    public static function model($className = null)
    {
        if (isset($className)) {
            if (!isset(self::$models[$className])) {
                $model = self::$models[$className] = new PluginDynamic($className, null);
                $model->md = new CActiveRecordMetaData($model);
                $model->attachBehaviors($model->behaviors());
            }
            return self::$models[$className];
        }
        return null;
    }

    /** @inheritdoc */
    public function tableName()
    {
        return $this->tableName;
    }

    /**
     * Override
     * @return CActiveRecordMetaData the meta for this AR class.
     */
    public function getMetaData()
    {
        if ($this->md !== null) {
            return $this->md;
        } else {
            /** @var CActiveRecordMetaData $md */
            $md = self::model($this->tableName())->md;
            return $this->md = $md;
        }
    }
}