yf_wrapper_search class

Search 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.

Fileplugins/search/classes/yf_wrapper_search.class.php
Use_class('wrapper_search')

Public properties

A site sets them in its config with $PROJECT_CONF['wrapper_search']['NAME'] = ...;

PropertyDefaultDescription
$REMOVED_DRIVERS
array<string,string>
['solr' => 'removed in yf 3.9 (it was an empty stub), see https://git'...]
array (
  'solr' => 'removed in yf 3.9 (it was an empty stub), see https://github.com/yfix/yf/blob/master/docs/UPGRADING.md',
)
driver name => why it is gone; such a driver answers false after one warning
$_connection null
$_connection_driver
string
'' Driver name of the current connection: a different driver value reconnects
$_removed_warned
array<string,bool>
[]
$driver 'db_like'
$last_error
string
'' Error of the last call that failed

Public methods 4

connect

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;
    }

is_ready

public function is_ready()
    public function is_ready()
    {
        $driver = $this->connect();
        return $driver ? (bool) $driver->is_ready() : false;
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public 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);
    }