/** * @throws \Exception */ public function missingMethod(ModelInterface $model, $method, $arguments = null) { if (!method_exists($this, $method)) { return null; } if (!$this->db) { if ($model->getDi()->has('db')) { $this->db = $model->getDi()->get('db'); } else { throw new \Exception('Undefined database handler.'); } } $this->setOwner($model); $result = call_user_func_array(array($this, $method), $arguments); if ($result === null) { return ''; } return $result; }
/** * Gets DB handler. * * @param ModelInterface $model * @return AdapterInterface * @throws Exception */ private function getDbHandler(ModelInterface $model) { if (!$this->db instanceof AdapterInterface) { if ($model->getDi()->has('db')) { $db = $model->getDi()->getShared('db'); if (!$db instanceof AdapterInterface) { throw new Exception('The "db" service which was obtained from DI is invalid adapter.'); } $this->db = $db; } else { throw new Exception('Undefined database handler.'); } } return $this->db; }