yf_wrapper_pubsub class

Core PUB/SUB events wrapper.

Fileplugins/pubsub/classes/yf_wrapper_pubsub.class.php
Use_class('wrapper_pubsub')

Public properties

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

PropertyDefaultDescription
$_connection null
$driver 'redis'

Public methods 6

conf

public function conf($params = [])

Configure driver.

    public function conf($params = [])
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->conf($params);
    }

connect

public function connect()

Do connect to the low level driver.

    public function connect()
    {
        if ( ! $this->_connection) {
            $this->_connection = _class('pubsub_driver_' . $this->driver, 'classes/pubsub/');
            $this->_connection->connect();
        }
        return $this->_connection;
    }

is_ready

public function is_ready()

Check if system is ready.

    public function is_ready()
    {
        ! $this->_connection && $this->connect();
        return (bool) $this->_connection;
    }

pub

public function pub($channel, $what)

Publish new event.

    public function pub($channel, $what)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->pub($channel, $what);
    }

sub

public function sub($channels, $callback)

Subscribe for one or more events.

    public function sub($channels, $callback)
    {
        ! $this->_connection && $this->connect();
        return $this->_connection->sub($channels, $callback);
    }

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

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        ! $this->_connection && $this->connect();
        // Support for driver-specific methods
        if (is_object($this->_connection) && method_exists($this->_connection, $name)) {
            return call_user_func_array([$this->_connection, $name], $args);
        }
        return main()->extend_call($this, $name, $args);
    }