yii\db\Schema::getTableSchema PHP Method

getTableSchema() public method

Obtains the metadata for the named table.
public getTableSchema ( string $name, boolean $refresh = false ) : null | yii\db\TableSchema
$name string table name. The table name may contain schema name if any. Do not quote the table name.
$refresh boolean whether to reload the table schema even if it is found in the cache.
return null | yii\db\TableSchema table metadata. Null if the named table does not exist.
    public function getTableSchema($name, $refresh = false)
    {
        if (array_key_exists($name, $this->_tables) && !$refresh) {
            return $this->_tables[$name];
        }
        $db = $this->db;
        $realName = $this->getRawTableName($name);
        if ($db->enableSchemaCache && !in_array($name, $db->schemaCacheExclude, true)) {
            /* @var $cache Cache */
            $cache = is_string($db->schemaCache) ? Yii::$app->get($db->schemaCache, false) : $db->schemaCache;
            if ($cache instanceof Cache) {
                $key = $this->getCacheKey($name);
                if ($refresh || ($table = $cache->get($key)) === false) {
                    $this->_tables[$name] = $table = $this->loadTableSchema($realName);
                    if ($table !== null) {
                        $cache->set($key, $table, $db->schemaCacheDuration, new TagDependency(['tags' => $this->getCacheTag()]));
                    }
                } else {
                    $this->_tables[$name] = $table;
                }
                return $this->_tables[$name];
            }
        }
        return $this->_tables[$name] = $this->loadTableSchema($realName);
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 public function getTableSchema($name, $refresh = false)
 {
     // Internal table name is uppercase and
     // to ensure the consistency of the key cache
     return parent::getTableSchema(strtoupper($name), $refresh);
 }