code: public function validateDb()
      {
          if (Yii::$app->hasComponent($this->db) === false) {
              $this->addError('db', 'There is no application component named "db".');
          } elseif (!Yii::$app->getComponent($this->db) instanceof Connection) {
              $this->addError('db', 'The "db" application component must be a DB connection instance.');
          }
      }
docs: Validates the [[db]] attribute.