-
Notifications
You must be signed in to change notification settings - Fork 22
/
Example.php
80 lines (61 loc) · 2.08 KB
/
Example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Norgul\Xmpp;
class Example
{
protected static $host = 'host.example.com';
protected static $port = 5222;
protected static $username = 'foo';
protected static $password = 'bar';
public static function test()
{
$options = new Options();
$options
->setHost(self::$host)
->setPort(self::$port)
->setUsername(self::$username)
->setPassword(self::$password);
$client = new XmppClient($options);
$client->connect();
$client->iq->getRoster();
$client->message->send('Hello world', '[email protected]');
// Uncomment if you want to manually enter raw XML (or call a function) and see a server response
// (new self)->sendRawXML($client);
do {
$response = $client->getResponse();
$client->prettyPrint($response);
} while (true);
$client->disconnect();
}
public function sendRawXML(XmppClient $client)
{
do {
$response = $client->getResponse();
$client->prettyPrint($response);
// if you provide a function name here, (i.e. getRoster ...arg)
// the function will be called instead of sending raw XML
$line = readline("\nEnter XML: ");
if ($line == 'exit') {
break;
}
$parsedLine = explode(' ', $line);
if (method_exists($client, $parsedLine[0])) {
if (count($parsedLine) < 2) {
$client->{$parsedLine[0]}();
continue;
}
$client->{$parsedLine[0]}($parsedLine[1]);
continue;
}
if (@simplexml_load_string($line)) {
$client->send($line);
continue;
}
echo "This is not a method nor a valid XML";
} while ($line != 'exit');
}
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
Example::test();