Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_PubSub Class Reference

P4Cms_PubSub is a subclass of Phly_PubSub which makes use of our own pubsub provider, to make subscription results consistent. More...

List of all members.

Public Member Functions

 filter ($topic, $args)
 Filter a value.
 publishUntil ($callback, $topic, $args=null)
 Notify subscribers until return value of one causes a callback to evaluate to true.

Static Public Member Functions

static clearHandles ($topic)
 Clear all handlers for a given topic.
static getInstance ()
 Retrieve PubSub provider instance.
static getSubscribedHandles ($topic)
 Retrieve all handlers for a given topic.
static getTopics ()
 Retrieve all registered topics.
static publish ($topic, $args=null)
 Publish to all handlers for a given topic.
static setInstance (P4Cms_PubSub_Provider $provider)
 Set PubSub provider instance.
static subscribe ($topic, $context, $handler=null)
 Subscribe to a topic.
static unsubscribe (Phly_PubSub_Handle $handle)
 Unsubscribe a handler from a topic.

Public Attributes

const TOPIC_DELIMITER = '.'

Static Protected Attributes

static $_instance

Detailed Description

P4Cms_PubSub is a subclass of Phly_PubSub which makes use of our own pubsub provider, to make subscription results consistent.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static P4Cms_PubSub::clearHandles ( topic) [static]

Clear all handlers for a given topic.

Parameters:
string$topicTopic to clear handlers for
Returns:
void
    {
        $provider = self::getInstance();
        return $provider->clearHandles($topic);
    }
P4Cms_PubSub::filter ( topic,
args 
)

Filter a value.

Notifies subscribers to the topic and passes the single value provided as an argument. Each subsequent subscriber is passed the return value of the previous subscriber, and the value of the last subscriber is returned.

Parameters:
string$topicTopic to apply filter to
mixed$argsAll arguments besides the topic are passed as arguments to the handler
Returns:
mixed
    {
        return call_user_func_array(
            array(self::getInstance(), 'filter'),
            func_get_args()
        );
    }
static P4Cms_PubSub::getInstance ( ) [static]

Retrieve PubSub provider instance.

Returns:
P4Cms_PubSub_Provider
    {
        if (null === self::$_instance) {
            self::setInstance(new P4Cms_PubSub_Provider());
        }
        return self::$_instance;
    }
static P4Cms_PubSub::getSubscribedHandles ( topic) [static]

Retrieve all handlers for a given topic.

Parameters:
string$topicTopic to get handlers for
Returns:
array Array of Phly_PubSub_Handle objects
    {
        $provider = self::getInstance();
        return $provider->getSubscribedHandles($topic);
    }
static P4Cms_PubSub::getTopics ( ) [static]

Retrieve all registered topics.

Returns:
array
    {
        $provider = self::getInstance();
        return $provider->getTopics();
    }
static P4Cms_PubSub::publish ( topic,
args = null 
) [static]

Publish to all handlers for a given topic.

Parameters:
string$topicTopic to publish
mixed$argsAll arguments besides the topic are passed as arguments to the handler
Returns:
void
    {
        return call_user_func_array(
            array(self::getInstance(), 'publish'),
            func_get_args()
        );
    }
P4Cms_PubSub::publishUntil ( callback,
topic,
args = null 
)

Notify subscribers until return value of one causes a callback to evaluate to true.

Publishes subscribers until the provided callback evaluates the return value of one as true, or until all subscribers have been executed.

Parameters:
Callable$callbackCallback function to test when notifications should cease
string$topicTopic to publish
mixed$argsAll arguments besides the topic are passed as arguments to the handler
Returns:
mixed
Exceptions:
Phly_PubSub_InvalidCallbackExceptionif invalid callback provided
    {
        return call_user_func_array(
            array(self::getInstance(), 'publishUntil'),
            func_get_args()
        );
    }
static P4Cms_PubSub::setInstance ( P4Cms_PubSub_Provider provider) [static]

Set PubSub provider instance.

Parameters:
P4Cms_PubSub_Provider$providerinstance of pub/sub provider
Returns:
void
    {
        self::$_instance = $provider;
    }
static P4Cms_PubSub::subscribe ( topic,
context,
handler = null 
) [static]

Subscribe to a topic.

Parameters:
string$topicTopic to subscribe to
string | object$contextFunction name, class name, or object instance
null | string$handlerIf $context is a class or object, the name of the method to call
Returns:
Phly_PubSub_Handle Pub-Sub handle (to allow later unsubscribe)
    {
        $provider = self::getInstance();
        return $provider->subscribe($topic, $context, $handler);
    }
static P4Cms_PubSub::unsubscribe ( Phly_PubSub_Handle $  handle) [static]

Unsubscribe a handler from a topic.

Parameters:
Phly_PubSub_Handle$handleHandler to unsubcribe from a topic
Returns:
bool Returns true if topic and handle found, and unsubscribed; returns false if either topic or handle not found.
    {
        $provider = self::getInstance();
        return $provider->unsubscribe($handle);
    }

Member Data Documentation

P4Cms_PubSub::$_instance [static, protected]

The documentation for this class was generated from the following file: