Пример #1
0
        $topic = $this->pendingSubs[$mid];
        $this->grantedSubs[$topic] = $grantedQos;
        echo "Subscribed to topic {$topic} with message ID {$mid}\n";
        if (is_callable($this->subscribeCallback)) {
            $this->subscribeCallback($mid, $qosCount, $grantedQos);
        }
    }
    public function subscribe($topic, $qos)
    {
        $mid = parent::subscribe($topic, $qos);
        $this->pendingSubs[$mid] = $topic;
    }
    public function onSubscribe(callable $callable)
    {
        $this->subscribeHandler = $callable;
    }
    public function getSubscriptions()
    {
        return $this->grantedSubs;
    }
}
$c = new MyClient('subscriptionTest');
$c->onSubscribe(function () {
    echo "Hello, I got subscribed\n";
});
$c->connect('localhost', 1883, 50);
$c->subscribe('#', 1);
for ($i = 0; $i < 5; $i++) {
    $c->loop(10);
}
var_dump($c->getSubscriptions());
Пример #2
0
<?php

/**
 * This client can connect to this server:
 * https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/wamp/authentication/wampcra
 */
require "../bootstrap.php";
require 'MyClient.php';
$client = new MyClient('realm1');
$client->setAttemptRetry(false);
$user = "******";
$secret = "secret1";
$user = "******";
$password = "******";
$client->setAuthId($user);
$client->addClientAuthenticator(new \Thruway\ClientWampCraAuthenticator($user, $password));
$client->addTransportProvider(new \Thruway\Transport\PawlTransportProvider("ws://127.0.0.1:8080/ws"));
$client->start();
Пример #3
0
// This is a custom query class that could have some customized logic
class MyQuery extends Select
{
}
// And this is the extended client, that modifies the default query mapping
// for select queries to our custom query class.
// BTW, the same could also be done using a plugin, see example 5.3.2
class MyClient extends Client
{
    /**
     * Querytype mappings
     */
    protected $queryTypes = array(self::QUERY_SELECT => array('query' => 'MyQuery', 'requestbuilder' => 'Solarium\\QueryType\\Select\\RequestBuilder\\RequestBuilder', 'responseparser' => 'Solarium\\QueryType\\Select\\ResponseParser\\ResponseParser'));
}
// create a client instance
$client = new MyClient($config);
// create a select query instance
$query = $client->createSelect();
// check the query class, it should be our custom query class
echo 'Query class: ' . get_class($query) . '<br/>';
// execute query
$result = $client->execute($query);
// display the total number of documents found by solr
echo 'NumFound: ' . $result->getNumFound();
// show documents using the resultset iterator
foreach ($result as $document) {
    echo '<hr/><table>';
    // the documents are also iterable, to get all fields
    foreach ($document as $field => $value) {
        // this converts multivalue fields to a comma-separated string
        if (is_array($value)) {