yf_wrapper_search classSearch wrapper: _class('wrapper_search')->search($params, $error) and the rest of the yf_search_driver contract, passed to the driver named by $driver (classes/search/yf_search_driver_<name>). Settings: $PROJECT_CONF['wrapper_search'] for this class, $PROJECT_CONF['search_driver_<name>'] for the driver. $error_message / last_error can carry the raw database or backend error: for logs and developers, never show them to visitors.
| File | plugins/search/classes/yf_wrapper_search.class.php |
|---|---|
| Use | _class('wrapper_search') |
A site sets them in its config with $PROJECT_CONF['wrapper_search']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$REMOVED_DRIVERSarray<string,string> |
|
driver name => why it is gone; such a driver answers false after one warning |
$_connection |
null |
|
$_connection_driverstring |
'' |
Driver name of the current connection: a different driver value reconnects |
$_removed_warnedarray<string,bool> |
[] |
|
$driver |
'db_like' |
|
$last_errorstring |
'' |
Error of the last call that failed |
public function connect()
The driver object (connected lazily by its own methods), or null for a removed or missing driver.
public function connect()
{
$name = (string) $this->driver;
if ($this->_connection && $this->_connection_driver === $name) {
return $this->_connection;
}
$this->_connection = null;
if (isset($this->REMOVED_DRIVERS[$name])) {
if ( ! isset($this->_removed_warned[$name])) {
$this->_removed_warned[$name] = true;
trigger_error('SEARCH: driver "' . $name . '" ' . $this->REMOVED_DRIVERS[$name], E_USER_WARNING);
}
$this->last_error = 'search driver "' . $name . '" removed';
return null;
}
$driver = preg_match('~^[a-z0-9_]+$~i', $name) ? _class_safe('search_driver_' . $name, 'classes/search/') : null;
if ( ! $driver instanceof yf_search_driver) {
$this->last_error = 'search driver "' . $name . '" not found';
return null;
}
$this->_connection_driver = $name;
return $this->_connection = $driver;
}
public function is_ready()
public function is_ready()
{
$driver = $this->connect();
return $driver ? (bool) $driver->is_ready() : false;
}
public function search(array $params = [], &$error_message = '')
Explicit because __call() cannot pass $error_message by reference.
$params array public function search(array $params = [], &$error_message = '')
{
$driver = $this->connect();
if ( ! $driver) {
$error_message = $this->last_error;
return false;
}
$result = $driver->search($params, $error_message);
$this->last_error = $result === false ? (string) ($error_message ?: $driver->last_error) : '';
return $result;
}
_ hooks and helpers; not routable as page actionspublic function __call($name, $args)
Catch missing method call: contract and driver-specific methods go to the driver.
public function __call($name, $args)
{
$this->connect();
if (is_object($this->_connection) && method_exists($this->_connection, $name)) {
$result = call_user_func_array([$this->_connection, $name], $args);
$this->last_error = (string) ($this->_connection->last_error ?? '');
return $result;
}
if ( ! is_object($this->_connection)) {
return false;
}
return main()->extend_call($this, $name, $args);
}