/** * Gets an option value. * * @param string $name * @param mixed $default * @throws \InvalidArgumentException * @return mixed */ public function get($name, $default = null) { $name = trim($name); if (empty($name)) { throw new \InvalidArgumentException('Empty option name given.'); } if (empty($this->ignore) && ($ignore = $this->cache->fetch($this->prefix . 'Ignore'))) { $this->ignore = $ignore ?: []; } if (isset($this->ignore[$name]) || !$this->connection->isConnected()) { return $default; } $this->initialize(true); if (isset($this->options[$name])) { return $this->options[$name]; } if ($option = $this->cache->fetch($this->prefix . $name)) { return $this->options[$name] = json_decode($option, true); } if ($option = $this->connection->fetchAssoc("SELECT value FROM {$this->table} WHERE name = ?", [$name])) { $this->cache->save($this->prefix . $name, $option['value']); return $this->options[$name] = json_decode($option['value'], true); } $this->ignore[$name] = true; $this->cache->save($this->prefix . 'Ignore', $this->ignore); return $default; }