/** * query ip division * @return null|string[] null or division array */ public function query() { if ($this->validate()) { $ip = ip2long($this->ip); $results = []; foreach (['full' => Full::className(), 'mini' => Mini::className(), 'china' => China::className(), 'world' => World::className()] as $name => $index) { $results[$name] = $this->getResultFromModel($index, $ip); } return $results; } return null; }
/** * @param $type * @return Full|Mini|China|World * @throws NotFoundHttpException */ protected function getIndexClass($type) { switch ($type) { case 'full': return Full::className(); case 'mini': return Mini::className(); case 'china': return China::className(); case 'world': return World::className(); default: throw new NotFoundHttpException("Type {$type} not found"); } }
/** * @return \yii\db\ActiveQuery */ public function getChina() { return $this->getIndex(China::className()); }