Introduce PHP7 strict typing

This commit is contained in:
Diogo Cordeiro
2019-11-02 23:36:21 +00:00
parent 79239e8e2d
commit 57f33b4328
14 changed files with 586 additions and 547 deletions

View File

@@ -1,5 +1,4 @@
<?php
/**
* @file: XMPPHP Cli example
*
@@ -19,18 +18,16 @@
* LEVEL_VERBOSE = 4;
*/
require '../vendor/autoload.php';
$conf = array(
'server' => 'talk.google.com',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'gmail.com',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
);
$conf = [
'server' => 'im.server.tld',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'domain.net',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
];
// Easy and simple for access to variables with their names
extract($conf);
@@ -38,13 +35,13 @@ extract($conf);
$conn = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
$conn->autoSubscribe();
$vcard_request = array();
$vcard_request = [];
try {
$conn->connect();
while (!$conn->isDisconnected()) {
$events = array('message', 'presence', 'end_stream', 'session_start', 'vcard');
$events = ['message', 'presence', 'end_stream', 'session_start', 'vcard'];
$payloads = $conn->processUntil($events);
foreach ($payloads as $result) {
@@ -56,84 +53,84 @@ try {
switch ($event) {
case 'message':
case 'message':
if (!$body) {
break;
}
if (!$body) {
break;
}
echo str_repeat('-', 80);
echo "Message from: $from";
echo str_repeat('-', 80);
echo "Message from: $from";
if (isset($subject)) {
echo "Subject: $subject";
}
if (isset($subject)) {
echo "Subject: $subject";
}
echo $body;
echo str_repeat('-', 80);
echo $body;
echo str_repeat('-', 80);
$cmd = explode(' ', $body);
$body = "Mi no entender! '$body'";
$conn->message($from, $body, $type);
$cmd = explode(' ', $body);
$body = "Mi no entender! '$body'";
$conn->message($from, $body, $type);
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
if ($cmd[0] == 'vcard') {
if (!isset($cmd[1])) {
$cmd[1] = $conn->user;
}
if ($cmd[0] == 'vcard') {
if (!isset($cmd[1])) {
$cmd[1] = $conn->user;
}
// Take a note which user requested which vcard
$vcard_request[$from] = $cmd[1];
// Request the vcard
$conn->getVCard($cmd[1]);
}
}
break;
// Take a note which user requested which vcard
$vcard_request[$from] = $cmd[1];
// Request the vcard
$conn->getVCard($cmd[1]);
}
}
break;
case 'presence':
case 'presence':
echo "Presence: $from [$show] $status\n";
break;
echo "Presence: $from [$show] $status\n";
break;
case 'session_start':
case 'session_start':
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
case 'vcard':
case 'vcard':
$deliver = array_keys($vcard_request, $from);
$msg = '';
$deliver = array_keys($vcard_request, $from);
$msg = '';
foreach ($data as $key => $item) {
$msg .= $key . ': ';
foreach ($data as $key => $item) {
$msg .= $key . ': ';
if (is_array($item)) {
$msg .= "\n";
foreach ($item as $subkey => $subitem) {
$msg .= ' ' . $subkey . ':' . $subitem . "\n";
}
} else {
$msg .= $item . "\n";
}
}
if (is_array($item)) {
$msg .= "\n";
foreach ($item as $subkey => $subitem) {
$msg .= ' ' . $subkey . ':' . $subitem . "\n";
}
} else {
$msg .= $item . "\n";
}
}
foreach ($deliver as $sendjid) {
unset($vcard_request[$sendjid]);
$conn->message($sendjid, $msg, 'chat');
}
break;
}
foreach ($deliver as $sendjid) {
unset($vcard_request[$sendjid]);
$conn->message($sendjid, $msg, 'chat');
}
break;
}
}
}
} catch (XMPPHP\Exception $e) {

View File

@@ -1,5 +1,4 @@
<?php
/**
* @file: XMPPHP Cli example BOSH
*
@@ -19,30 +18,28 @@
* LEVEL_VERBOSE = 4;
*/
require '../vendor/autoload.php';
$conf = array(
'server' => 'server.tld',
'port' => 5280,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'server.tld',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
);
$conf = [
'host' => 'server.tld',
'port' => 5280,
'username' => 'username',
'password' => 'password',
'resource' => 'xmpphp',
'server' => 'http://server.tld:5280/xmpp-httpbind',
'print_log' => true,
'log_level' => XMPPHP\Log::LEVEL_VERBOSE,
];
// Easy and simple for access to variables with their names
extract($conf);
$conn = new XMPPHP\BOSH($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel);
$conn = new XMPPHP\BOSH($host, $port, $username, $password, $proto, $server, $print_log, $log_level);
$conn->autoSubscribe();
try {
$conn->connect('http://server.tld:5280/xmpp-httpbind');
$conn->connect();
while (!$conn->isDisconnected()) {
$events = array('message', 'presence', 'end_stream', 'session_start');
$events = ['message', 'presence', 'end_stream', 'session_start'];
$payloads = $conn->processUntil($events);
foreach ($payloads as $result) {
@@ -54,49 +51,49 @@ try {
switch ($event) {
case 'message':
case 'message':
if (!$body) {
break;
}
if (!$body) {
break;
}
echo str_repeat('-', 80);
echo "Message from: $from";
echo str_repeat('-', 80);
echo "Message from: $from";
if (isset($subject)) {
echo "Subject: $subject";
}
if (isset($subject)) {
echo "Subject: $subject";
}
echo $body;
echo str_repeat('-', 80);
echo $body;
echo str_repeat('-', 80);
$cmd = explode(' ', $body);
$body = "Mi no entender! '$body'";
$conn->message($from, $body, $type);
$cmd = explode(' ', $body);
$body = "Mi no entender! '$body'";
$conn->message($from, $body, $type);
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
}
break;
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
}
break;
case 'presence':
case 'presence':
echo "Presence: $from [$show] $status\n";
break;
echo "Presence: $from [$show] $status\n";
break;
case 'session_start':
case 'session_start':
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
}
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
}
}
}
} catch (XMPPHP\Exception $e) {

View File

@@ -1,5 +1,4 @@
<?php
/**
* @file: XMPPHP Send message example
*
@@ -18,18 +17,16 @@
* LEVEL_VERBOSE = 4;
*/
require_once __DIR__.'/../vendor/autoload.php';
$conf = array(
'server' => 'talk.google.com',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'gmail.com',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
);
$conf = [
'server' => 'jabber.domain.com',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'domain.net',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
];
// Easy and simple for access to variables with their names
extract($conf);

View File

@@ -1,5 +1,4 @@
<?php
/**
* @file: XMPPHP Cli example
*
@@ -22,18 +21,16 @@
session_start();
header('content-type', 'plain/text');
require '../vendor/autoload.php';
$conf = array(
'server' => 'talk.google.com',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'gmail.com',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
);
$conf = [
'server' => 'talk.google.com',
'port' => 5222,
'username' => 'username',
'password' => 'password',
'proto' => 'xmpphp',
'domain' => 'gmail.com',
'printlog' => true,
'loglevel' => XMPPHP\Log::LEVEL_VERBOSE,
];
// Easy and simple for access to variables with their names
extract($conf);
@@ -48,11 +45,11 @@ try {
flush();
}
} else {
$_SESSION['messages'] = array();
$_SESSION['messages'] = [];
}
$conn->connect('http://server.tld:5280/xmpp-httpbind', 1, true);
$events = array('message', 'presence', 'end_stream', 'session_start', 'vcard');
$conn->connect();
$events = ['message', 'presence', 'end_stream', 'session_start', 'vcard'];
$payloads = $conn->processUntil($events);
foreach ($payloads as $result) {
@@ -64,49 +61,49 @@ try {
switch ($event) {
case 'message':
case 'message':
if (!$body) {
break;
if (!$body) {
break;
}
$cmd = explode(' ', $body);
$msg = str_repeat('-', 80);
$msg .= "\nMessage from: $from\n";
if (isset($subject)) {
$msg .= "Subject: $subject\n";
}
$msg .= $body . "\n";
$msg .= str_repeat('-', 80);
echo "<pre>$msg</pre>";
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
}
$_SESSION['messages'][] = $msg;
flush();
break;
case 'presence':
echo "Presence: $from [$show] $status\n";
break;
case 'session_start':
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
}
$cmd = explode(' ', $body);
$msg = str_repeat('-', 80);
$msg .= "\nMessage from: $from\n";
if (isset($subject)) {
$msg .= "Subject: $subject\n";
}
$msg .= $body . "\n";
$msg .= str_repeat('-', 80);
echo "<pre>$msg</pre>";
if (isset($cmd[0])) {
if ($cmd[0] == 'quit') {
$conn->disconnect();
}
if ($cmd[0] == 'break') {
$conn->send('</end>');
}
}
$_SESSION['messages'][] = $msg;
flush();
break;
case 'presence':
echo "Presence: $from [$show] $status\n";
break;
case 'session_start':
echo "Session start\n";
$conn->getRoster();
$conn->presence('Quasar!');
break;
}
}
} catch (XMPPHP\Exception $e) {
die($e->getMessage());