diff --git a/.gitignore b/.gitignore
index 908ecac..e976691 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
/nbproject/
composer.lock
composer.phar
+/phpunit.xml
+.idea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c860fb7..60b9874 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
# CHANGELOG
+## 0.7.0 (2017-05-23)
+
+- [MAJOR]: [PR #46](https://github.com/fabiang/xmpp/pull/46) Added support for password-protected chatrooms
+- [MAJOR]: [PR #44](https://github.com/fabiang/xmpp/pull/44) Added anonymous authentication method
+- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added support for registereing user
+- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added vCard support
+- [MAJOR]: [PR #34](https://github.com/fabiang/xmpp/pull/34) Added support for blocking and unblocking an user
+- [MAJOR]: Drop support for PHP lower than 5.6
+- [MAJOR]: [PR #31](https://github.com/fabiang/xmpp/pull/31): Possibility to set context for SocketClient
+
## 0.6.1 (2014-11-20)
- [PATCH] [Issue #4](https://github.com/fabiang/xmpp/issues/4): Incomplete buffer response
diff --git a/LICENSE.md b/LICENSE.md
index 4de87d7..a54a1c0 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,7 +1,7 @@
Simplified BSD License
======================
-Copyright 2014 Fabian Grutschus.
+Copyright 2014-2017 Fabian Grutschus.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
diff --git a/README.md b/README.md
index ec307c3..d650033 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,28 @@
# fabiang/xmpp
-[](https://packagist.org/packages/fabiang/xmpp) [](https://packagist.org/packages/fabiang/xmpp) [](https://packagist.org/packages/fabiang/xmpp) [](https://packagist.org/packages/fabiang/xmpp)
-[](https://travis-ci.org/fabiang/xmpp) [](https://scrutinizer-ci.com/g/fabiang/xmpp/) [](https://coveralls.io/r/fabiang/xmpp?branch=master) [](https://gemnasium.com/fabiang/xmpp) [](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74)
-
Library for XMPP protocol connections (Jabber) for PHP.
+[](https://packagist.org/packages/fabiang/xmpp)
+[](https://packagist.org/packages/fabiang/xmpp)
+[](https://packagist.org/packages/fabiang/xmpp)
+[](https://gemnasium.com/fabiang/xmpp)
+[](https://travis-ci.org/fabiang/xmpp)
+[](https://coveralls.io/r/fabiang/xmpp?branch=master)
+[](https://scrutinizer-ci.com/g/fabiang/xmpp/)
+[](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74)
+
## SYSTEM REQUIREMENTS
-- PHP >= 5.3.3
+- PHP minimum 5.6 or minimum 7.0
- psr/log
-- psr/log-implementation - like monolog/monolog for logging (optional)
+- (optional) psr/log-implementation - like monolog/monolog for logging
## INSTALLATION
New to Composer? Read the [introduction](https://getcomposer.org/doc/00-intro.md#introduction). Add the following to your composer file:
-```json
-{
- "require": {
- "fabiang/xmpp": "*"
- }
-}
+```bash
+composer require fabiang/xmpp
```
## DOCUMENTATION
@@ -73,6 +75,7 @@ $client->send($message);
// join a channel
$channel = new Presence;
$channel->setTo('channelname@conference.myjabber.com')
+ ->setPassword('channelpassword')
->setNickName('mynick');
$client->send($channel);
@@ -95,14 +98,14 @@ $client->disconnect();
If you like this library and you want to contribute, make sure the unit-tests and integration tests are running.
Composer will help you to install the right version of PHPUnit and [Behat](http://behat.org/).
- composer install --dev
+ composer install
After that:
- ./vendor/bin/phpunit -c tests
- ./vendor/bin/behat --config=tests/behat.yml --strict
+ ./vendor/bin/phpunit
+ ./vendor/bin/behat
-New features should allways tested with Behat.
+New features should always tested with Behat.
## LICENSE
@@ -112,5 +115,4 @@ BSD-2-Clause. See the [LICENSE](LICENSE.md).
- Better integration of channels
- Factory method for server addresses
-- Add support von vCard
- improve documentation
diff --git a/behat.yml b/behat.yml
new file mode 100644
index 0000000..9453b74
--- /dev/null
+++ b/behat.yml
@@ -0,0 +1,6 @@
+default:
+ paths:
+ features: %behat.paths.base%/tests/features
+ bootstrap: %behat.paths.features%/bootstrap
+ context:
+ class: Fabiang\Xmpp\Integration\FeatureContext
diff --git a/composer.json b/composer.json
index 92a051d..5cb7a3e 100644
--- a/composer.json
+++ b/composer.json
@@ -26,14 +26,17 @@
}
},
"require": {
- "php": ">=5.3.3",
- "psr/log": "~1.0"
+ "php": "^5.6 || ^7.0",
+ "psr/log": "^1.0"
},
"require-dev": {
- "monolog/monolog": "~1.11",
- "phpunit/phpunit": "~4.3",
- "behat/behat": "~2.5",
- "satooshi/php-coveralls": "~0.6"
+ "behat/behat": "^2.5.5",
+ "monolog/monolog": "^1.22",
+ "phpunit/phpunit": "^5.7.20",
+ "satooshi/php-coveralls": "^1.0",
+ "symfony/console": "^2.8",
+ "symfony/dependency-injection": "^2.8",
+ "symfony/finder": "^2.8"
},
"suggest": {
"psr/log-implementation": "Allows more advanced logging of the xmpp connection"
@@ -43,6 +46,12 @@
"dev-master": "1.0.x-dev"
}
},
+ "config": {
+ "platform": {
+ "php": "5.6"
+ },
+ "sort-packages": true
+ },
"archive": {
"exclude": [
".gitignore",
diff --git a/examples/avatar.png b/examples/avatar.png
new file mode 100644
index 0000000..55e678e
Binary files /dev/null and b/examples/avatar.png differ
diff --git a/examples/config.inc.php b/examples/config.inc.php
new file mode 100644
index 0000000..146d19d
--- /dev/null
+++ b/examples/config.inc.php
@@ -0,0 +1,10 @@
+ 'xmpp.example.com',
+ 'conference' => 'conference.example.com',
+ 'port' => 5222,
+ 'connectionType' => 'tcp',
+ 'verifyPeer' => true,
+ 'login' => 'admin',
+ 'password' => '123456',
+];
\ No newline at end of file
diff --git a/examples/example.php b/examples/example.php
new file mode 100644
index 0000000..71d66bf
--- /dev/null
+++ b/examples/example.php
@@ -0,0 +1,47 @@
+pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
+
+$hostname = 'localhost';
+$port = 5222;
+$connectionType = 'tcp';
+$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];
+
+
+$options = new Options($address);
+$options->setLogger($logger)
+ ->setUsername($config['login'])
+ ->setPassword($config['password']);
+
+if ($config['verifyPeer'] === false) {
+ $options->setContextOptions([
+ 'ssl' => [
+ 'verify_peer' => false,
+ 'verify_peer_name' => false,
+ 'allow_self_signed' => true,
+ ],
+ ]);
+}
+
+$client = new Client($options);
+
+$client->connect();
+$client->send(new Roster);
+$client->send(new Presence);
+$client->send(new Message);
+
+$client->disconnect();
diff --git a/examples/register.php b/examples/register.php
new file mode 100644
index 0000000..99f319f
--- /dev/null
+++ b/examples/register.php
@@ -0,0 +1,91 @@
+pushHandler(new StreamHandler( 'php://stdout', Logger::DEBUG));
+
+$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];
+
+$newUser = 'testuser';
+$newPassword = '123456';
+
+$options = new Options($address);
+$options->setLogger($logger)
+ ->setUsername($config['login'])
+ ->setPassword($config['password']);
+
+if ($config['verifyPeer'] === false) {
+ $options->setContextOptions([
+ 'ssl' => [
+ 'verify_peer' => false,
+ 'verify_peer_name' => false,
+ 'allow_self_signed' => true,
+ ],
+ ]);
+}
+
+
+$client = new Client($options);
+
+$client->connect();
+$request = new RequestUserRegisterForm($config['login'] . '@' . $config['host'], $config['host']);
+$client->send($request);
+
+$form = $client->getOptions()->getForm();
+$user = new RegisterUser(
+ $newUser . '@' . $config['host'],
+ $newPassword,
+ $config['login'] . '@' . $config['host'],
+ $config['host'],
+ $form
+);
+
+try {
+ $client->send($user);
+ print 'User is registered' . PHP_EOL;
+} catch (StanzasErrorException $e) {
+ /**
+ * @see https://xmpp.org/extensions/xep-0086.html#sect-idm139696314152720
+ */
+ if ($e->getCode() == StanzasErrorException::ERROR_CONFLICT) { // conflict
+ fwrite(STDOUT, 'User already exists. Try to change password' . PHP_EOL);
+ $request = new RequestChangePasswordForm(
+ $config['login'] . '@' . $config['host'],
+ $config['host']
+ );
+
+ try {
+ $client->send($request);
+
+ $form = $client->getOptions()->getForm();
+ $user = new ChangeUserPassword(
+ $newUser . '@' . $config['host'],
+ $newPassword,
+ $config['login'] . '@' . $config['host'],
+ $config['host'],
+ $form
+ );
+ } catch (StanzasErrorException $e) {
+ fwrite(STDOUT, 'Failed to change password of user!' . PHP_EOL);
+ fwrite(STDOUT, $e->getMessage() . PHP_EOL);
+ }
+
+ } else {
+ fwrite(STDOUT, 'Failed to register user!' . PHP_EOL);
+ fwrite(STDOUT, $e->getMessage() . PHP_EOL);
+ }
+}
+$client->disconnect();
\ No newline at end of file
diff --git a/examples/vcard.php b/examples/vcard.php
new file mode 100644
index 0000000..1c05064
--- /dev/null
+++ b/examples/vcard.php
@@ -0,0 +1,66 @@
+pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
+
+$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];
+
+$login = 'testuser';
+$password = '123456';
+
+
+$options = new Options($address);
+$options->setLogger($logger)
+ ->setUsername($login)
+ ->setPassword($password);
+
+if ($config['verifyPeer'] === false) {
+ $options->setContextOptions([
+ 'ssl' => [
+ 'verify_peer' => false,
+ 'verify_peer_name' => false,
+ 'allow_self_signed' => true,
+ ],
+ ]);
+}
+
+$client = new Client($options);
+
+$client->connect();
+
+$vCard = new VCardUpdate($login);
+$vCard->setProperty('NICKNAME', 'iCoolVan')
+ ->setProperty('FAMILY', 'Ivanov')
+ ->setProperty('GIVEN', 'Ivan')
+ ->setProperty('MIDDLE', 'Ivanovich')
+ ->setProperty('EMAIL', 'info@personal-site.com');
+
+
+$vCard->setProperty('PHOTO', __DIR__ . '/avatar.png')
+ ->setImageUrl("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png");
+$image_hash = $vCard->getImageId();
+
+$vCard->setProperty('URL', 'https://personal-site.com');
+try {
+ $client->send($vCard);
+ // tell other users that we have update vCard
+ $presence = new VCardPresence($image_hash);
+ $client->send($presence);
+ fwrite(STDOUT, 'vCard was updated.' . PHP_EOL);
+} catch (StanzasErrorException $e) {
+ fwrite(STDOUT, 'Failed to update user vCard!' . PHP_EOL);
+ fwrite(STDOUT, $e->getMessage() . PHP_EOL);
+}
+$client->disconnect();
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..424de7b
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+ tests/src/
+
+
+
+
+
+ src/
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Connection/AbstractConnection.php b/src/Connection/AbstractConnection.php
index 30f79c4..53ad8b2 100644
--- a/src/Connection/AbstractConnection.php
+++ b/src/Connection/AbstractConnection.php
@@ -36,13 +36,13 @@
namespace Fabiang\Xmpp\Connection;
-use Fabiang\Xmpp\Stream\XMLStream;
-use Fabiang\Xmpp\EventListener\EventListenerInterface;
use Fabiang\Xmpp\Event\EventManager;
use Fabiang\Xmpp\Event\EventManagerInterface;
use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
-use Fabiang\Xmpp\Options;
+use Fabiang\Xmpp\EventListener\EventListenerInterface;
use Fabiang\Xmpp\Exception\TimeoutException;
+use Fabiang\Xmpp\Options;
+use Fabiang\Xmpp\Stream\XMLStream;
use Psr\Log\LogLevel;
/**
@@ -82,9 +82,9 @@ abstract class AbstractConnection implements ConnectionInterface
/**
* Event listeners.
*
- * @var EventListenerInterface[]
+ * @var BlockingEventListenerInterface[]
*/
- protected $listeners = array();
+ protected $listeners = [];
/**
* Connected.
@@ -226,7 +226,7 @@ public function setEventManager(EventManagerInterface $events)
/**
* Get listeners.
*
- * @return EventListenerInterface
+ * @return BlockingEventListenerInterface[]
*/
public function getListeners()
{
@@ -259,7 +259,7 @@ public function setOptions(Options $options)
*/
protected function log($message, $level = LogLevel::DEBUG)
{
- $this->getEventManager()->trigger('logger', $this, array($message, $level));
+ $this->getEventManager()->trigger('logger', $this, [$message, $level]);
}
/**
@@ -285,6 +285,14 @@ protected function checkBlockingListeners()
return $blocking;
}
+ /**
+ * @return BlockingEventListenerInterface
+ */
+ public function getLastBlockingListener()
+ {
+ return $this->lastBlockingListener;
+ }
+
/**
* Check for timeout.
*
diff --git a/src/Connection/ConnectionInterface.php b/src/Connection/ConnectionInterface.php
index b9f6fc8..9665cce 100644
--- a/src/Connection/ConnectionInterface.php
+++ b/src/Connection/ConnectionInterface.php
@@ -36,10 +36,11 @@
namespace Fabiang\Xmpp\Connection;
-use Fabiang\Xmpp\Stream\XMLStream;
use Fabiang\Xmpp\Event\EventManagerAwareInterface;
+use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
use Fabiang\Xmpp\EventListener\EventListenerInterface;
use Fabiang\Xmpp\OptionsAwareInterface;
+use Fabiang\Xmpp\Stream\XMLStream;
/**
* Connections must implement this interface.
@@ -143,4 +144,11 @@ public function resetStreams();
* @return $this
*/
public function addListener(EventListenerInterface $eventListener);
+
+ /**
+ * get last blocking listener
+ *
+ * @return BlockingEventListenerInterface
+ */
+ public function getLastBlockingListener();
}
diff --git a/src/Connection/Socket.php b/src/Connection/Socket.php
index 8ce49a7..ebbdc2a 100644
--- a/src/Connection/Socket.php
+++ b/src/Connection/Socket.php
@@ -36,11 +36,11 @@
namespace Fabiang\Xmpp\Connection;
-use Psr\Log\LogLevel;
+use Fabiang\Xmpp\Exception\TimeoutException;
+use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Stream\SocketClient;
use Fabiang\Xmpp\Util\XML;
-use Fabiang\Xmpp\Options;
-use Fabiang\Xmpp\Exception\TimeoutException;
+use Psr\Log\LogLevel;
/**
* Connection to a socket stream.
@@ -50,7 +50,7 @@
class Socket extends AbstractConnection implements SocketConnectionInterface
{
- const DEFAULT_LENGTH = 4096;
+ const DEFAULT_LENGTH = 65536;
const STREAM_START = <<<'XML'
@@ -89,7 +89,7 @@ public function __construct(SocketClient $socket)
*/
public static function factory(Options $options)
{
- $socket = new SocketClient($options->getAddress());
+ $socket = new SocketClient($options->getAddress(), $options->getContextOptions());
$object = new static($socket);
$object->setOptions($options);
return $object;
@@ -129,7 +129,7 @@ private function reconnectTls(TimeoutException $exception)
// check if we didn't receive any data
// if not we re-try to connect via TLS
if (false === $this->receivedAnyData) {
- $matches = array();
+ $matches = [];
$previousAddress = $this->getOptions()->getAddress();
// only reconnect via tls if we've used tcp before.
if (preg_match('#tcp://(?.+)#', $previousAddress, $matches)) {
diff --git a/src/Event/Event.php b/src/Event/Event.php
index abce6f4..a818f4b 100644
--- a/src/Event/Event.php
+++ b/src/Event/Event.php
@@ -36,8 +36,8 @@
namespace Fabiang\Xmpp\Event;
-use Fabiang\Xmpp\Exception\OutOfRangeException;
use Fabiang\Xmpp\Exception\InvalidArgumentException;
+use Fabiang\Xmpp\Exception\OutOfRangeException;
/**
* Generic event.
@@ -66,14 +66,14 @@ class Event implements EventInterface
*
* @var array
*/
- protected $parameters = array();
+ protected $parameters = [];
/**
* Event stack.
*
* @var array
*/
- protected $eventStack = array();
+ protected $eventStack = [];
/**
* {@inheritDoc}
diff --git a/src/Event/EventManager.php b/src/Event/EventManager.php
index f8ea266..67b2c55 100644
--- a/src/Event/EventManager.php
+++ b/src/Event/EventManager.php
@@ -55,7 +55,7 @@ class EventManager implements EventManagerInterface
*
* @var array
*/
- protected $events = array(self::WILDCARD => array());
+ protected $events = [self::WILDCARD => []];
/**
* Event object.
@@ -90,7 +90,7 @@ public function attach($event, $callback)
}
if (!isset($this->events[$event])) {
- $this->events[$event] = array();
+ $this->events[$event] = [];
}
if (!in_array($callback, $this->events[$event], true)) {
@@ -107,13 +107,13 @@ public function trigger($event, $caller, array $parameters)
return;
}
- $events = array();
+ $events = [];
if (!empty($this->events[$event])) {
$events = $this->events[$event];
}
$callbacks = array_merge($events, $this->events[self::WILDCARD]);
- $previous = array();
+ $previous = [];
$eventObject = clone $this->getEventObject();
$eventObject->setName($event);
diff --git a/src/EventListener/Logger.php b/src/EventListener/Logger.php
index f914698..d68f7b2 100644
--- a/src/EventListener/Logger.php
+++ b/src/EventListener/Logger.php
@@ -69,6 +69,6 @@ public function event(EventInterface $event)
*/
public function attachEvents()
{
- $this->getEventManager()->attach('logger', array($this, 'event'));
+ $this->getEventManager()->attach('logger', [$this, 'event']);
}
}
diff --git a/src/EventListener/Stream/Authentication.php b/src/EventListener/Stream/Authentication.php
index 2934abc..8a7dc79 100644
--- a/src/EventListener/Stream/Authentication.php
+++ b/src/EventListener/Stream/Authentication.php
@@ -37,11 +37,11 @@
namespace Fabiang\Xmpp\EventListener\Stream;
use Fabiang\Xmpp\Event\XMLEvent;
-use Fabiang\Xmpp\Exception\RuntimeException;
-use Fabiang\Xmpp\EventListener\Stream\Authentication\AuthenticationInterface;
-use Fabiang\Xmpp\Exception\Stream\AuthenticationErrorException;
use Fabiang\Xmpp\EventListener\AbstractEventListener;
use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
+use Fabiang\Xmpp\EventListener\Stream\Authentication\AuthenticationInterface;
+use Fabiang\Xmpp\Exception\RuntimeException;
+use Fabiang\Xmpp\Exception\Stream\AuthenticationErrorException;
/**
* Listener
@@ -63,7 +63,7 @@ class Authentication extends AbstractEventListener implements BlockingEventListe
*
* @var array
*/
- protected $mechanisms = array();
+ protected $mechanisms = [];
/**
* {@inheritDoc}
@@ -71,10 +71,10 @@ class Authentication extends AbstractEventListener implements BlockingEventListe
public function attachEvents()
{
$input = $this->getConnection()->getInputStream()->getEventManager();
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}mechanisms', array($this, 'authenticate'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism', array($this, 'collectMechanisms'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}failure', array($this, 'failure'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}success', array($this, 'success'));
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}mechanisms', [$this, 'authenticate']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism', [$this, 'collectMechanisms']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}failure', [$this, 'failure']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}success', [$this, 'success']);
}
/**
diff --git a/src/EventListener/Stream/Authentication/Anonymous.php b/src/EventListener/Stream/Authentication/Anonymous.php
new file mode 100644
index 0000000..3b2cc22
--- /dev/null
+++ b/src/EventListener/Stream/Authentication/Anonymous.php
@@ -0,0 +1,66 @@
+
+ * @copyright 2016 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\EventListener\Stream\Authentication;
+
+use Fabiang\Xmpp\EventListener\AbstractEventListener;
+
+/**
+ * Handler for "anonymous" authentication mechanism.
+ *
+ * @package Xmpp\EventListener\Authentication
+ */
+class Anonymous extends AbstractEventListener implements AuthenticationInterface
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public function attachEvents()
+ {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function authenticate($username, $password)
+ {
+ $this->getConnection()->send(
+ ''
+ );
+ }
+}
diff --git a/src/EventListener/Stream/Authentication/DigestMd5.php b/src/EventListener/Stream/Authentication/DigestMd5.php
index 49b43fd..35129c6 100644
--- a/src/EventListener/Stream/Authentication/DigestMd5.php
+++ b/src/EventListener/Stream/Authentication/DigestMd5.php
@@ -36,10 +36,10 @@
namespace Fabiang\Xmpp\EventListener\Stream\Authentication;
-use Fabiang\Xmpp\EventListener\AbstractEventListener;
use Fabiang\Xmpp\Event\XMLEvent;
-use Fabiang\Xmpp\Util\XML;
+use Fabiang\Xmpp\EventListener\AbstractEventListener;
use Fabiang\Xmpp\Exception\Stream\AuthenticationErrorException;
+use Fabiang\Xmpp\Util\XML;
/**
* Handler for "digest md5" authentication mechanism.
@@ -74,11 +74,11 @@ class DigestMd5 extends AbstractEventListener implements AuthenticationInterface
public function attachEvents()
{
$input = $this->getInputEventManager();
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}challenge', array($this, 'challenge'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}success', array($this, 'success'));
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}challenge', [$this, 'challenge']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-sasl}success', [$this, 'success']);
$output = $this->getOutputEventManager();
- $output->attach('{urn:ietf:params:xml:ns:xmpp-sasl}auth', array($this, 'auth'));
+ $output->attach('{urn:ietf:params:xml:ns:xmpp-sasl}auth', [$this, 'auth']);
}
/**
@@ -183,10 +183,10 @@ protected function response($values)
protected function parseCallenge($challenge)
{
if (!$challenge) {
- return array();
+ return [];
}
- $matches = array();
+ $matches = [];
preg_match_all('#(\w+)\=(?:"([^"]+)"|([^,]+))#', $challenge, $matches);
list(, $variables, $quoted, $unquoted) = $matches;
// filter empty strings; preserve keys
diff --git a/src/EventListener/Stream/Bind.php b/src/EventListener/Stream/Bind.php
index b6499fd..330ce58 100644
--- a/src/EventListener/Stream/Bind.php
+++ b/src/EventListener/Stream/Bind.php
@@ -36,8 +36,8 @@
namespace Fabiang\Xmpp\EventListener\Stream;
-use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
/**
* Listener
@@ -53,8 +53,8 @@ class Bind extends AbstractSessionEvent implements BlockingEventListenerInterfac
public function attachEvents()
{
$input = $this->getInputEventManager();
- $input->attach('{urn:ietf:params:xml:ns:xmpp-bind}bind', array($this, 'bindFeatures'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-bind}jid', array($this, 'jid'));
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-bind}bind', [$this, 'bindFeatures']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-bind}jid', [$this, 'jid']);
}
/**
diff --git a/src/EventListener/Stream/BlockedUsers.php b/src/EventListener/Stream/BlockedUsers.php
new file mode 100644
index 0000000..769c19e
--- /dev/null
+++ b/src/EventListener/Stream/BlockedUsers.php
@@ -0,0 +1,144 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\EventListener\Stream;
+
+use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\EventListener\AbstractEventListener;
+use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
+use Fabiang\Xmpp\Protocol\User\User;
+
+/**
+ * Listener
+ *
+ * @package Xmpp\EventListener
+ */
+class BlockedUsers extends AbstractEventListener implements BlockingEventListenerInterface
+{
+
+ /**
+ * Blocking.
+ *
+ * @var boolean
+ */
+ protected $blocking = false;
+
+ /**
+ * user object.
+ *
+ * @var User
+ */
+ protected $userObject;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function attachEvents()
+ {
+ $this->getOutputEventManager()
+ ->attach('{urn:xmpp:blocking}blocklist', [$this, 'query']);
+ $this->getInputEventManager()
+ ->attach('{urn:xmpp:blocking}blocklist', [$this, 'result']);
+ }
+
+ /**
+ * Sending a query request for roster sets listener to blocking mode.
+ *
+ * @return void
+ */
+ public function query()
+ {
+ $this->blocking = true;
+ }
+
+ /**
+ * Result received.
+ *
+ * @param \Fabiang\Xmpp\Event\XMLEvent $event
+ * @return void
+ */
+ public function result(XMLEvent $event)
+ {
+ if ($event->isEndTag()) {
+ $users = [];
+
+ /* @var $element \DOMElement */
+ $element = $event->getParameter(0);
+ $items = $element->getElementsByTagName('item');
+ /* @var $item \DOMElement */
+ foreach ($items as $item) {
+ $users[] = $item->getAttribute('jid');
+ }
+ dd($users);
+ //$this->getOptions()->setUsers($users);
+ $this->blocking = false;
+ }
+ }
+
+ /**
+ * Get user object.
+ *
+ * @return User
+ */
+ public function getUserObject()
+ {
+ if (null === $this->userObject) {
+ $this->setUserObject(new User);
+ }
+
+ return $this->userObject;
+ }
+
+ /**
+ * Set user object.
+ *
+ * @param User $userObject
+ * @return $this
+ */
+ public function setUserObject(User $userObject)
+ {
+ $this->userObject = $userObject;
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isBlocking()
+ {
+ return $this->blocking;
+ }
+}
diff --git a/src/EventListener/Stream/Command.php b/src/EventListener/Stream/Command.php
new file mode 100644
index 0000000..fd61b92
--- /dev/null
+++ b/src/EventListener/Stream/Command.php
@@ -0,0 +1,115 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\EventListener\Stream;
+
+use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\EventListener\AbstractEventListener;
+use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
+use Fabiang\Xmpp\EventListener\UnBlockingEventListenerInterface;
+use Fabiang\Xmpp\Form\Form;
+
+/**
+ * Listener
+ *
+ * @package Xmpp\EventListener
+ */
+class Command extends AbstractEventListener implements BlockingEventListenerInterface, UnBlockingEventListenerInterface
+{
+
+ /**
+ * Blocking.
+ *
+ * @var boolean
+ */
+ protected $blocking = false;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public function attachEvents()
+ {
+ $this->getOutputEventManager()
+ ->attach('{http://jabber.org/protocol/commands}command', array($this, 'query'));
+
+ $this->getInputEventManager()
+ ->attach('{http://jabber.org/protocol/commands}command', array($this, 'result'));
+ }
+
+ /**
+ * Sending a query request for roster sets listener to blocking mode.
+ *
+ * @return void
+ */
+ public function query()
+ {
+ $this->blocking = true;
+ }
+
+ /**
+ * Result received.
+ *
+ * @param \Fabiang\Xmpp\Event\XMLEvent $event
+ * @return void
+ */
+ public function result(XMLEvent $event)
+ {
+ if ($event->isEndTag()) {
+ if (!$this->getOptions()->getForm()) {
+ $form = new Form($event);
+ $this->getOptions()->setForm($form);
+ }
+ $this->blocking = false;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isBlocking()
+ {
+ return $this->blocking;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function unBlock()
+ {
+ $this->blocking = false;
+ }
+}
\ No newline at end of file
diff --git a/src/EventListener/Stream/Roster.php b/src/EventListener/Stream/Roster.php
index 223070f..a087c91 100644
--- a/src/EventListener/Stream/Roster.php
+++ b/src/EventListener/Stream/Roster.php
@@ -69,9 +69,9 @@ class Roster extends AbstractEventListener implements BlockingEventListenerInter
public function attachEvents()
{
$this->getOutputEventManager()
- ->attach('{jabber:iq:roster}query', array($this, 'query'));
+ ->attach('{jabber:iq:roster}query', [$this, 'query']);
$this->getInputEventManager()
- ->attach('{jabber:iq:roster}query', array($this, 'result'));
+ ->attach('{jabber:iq:roster}query', [$this, 'result']);
}
/**
@@ -93,7 +93,7 @@ public function query()
public function result(XMLEvent $event)
{
if ($event->isEndTag()) {
- $users = array();
+ $users = [];
/* @var $element \DOMElement */
$element = $event->getParameter(0);
diff --git a/src/EventListener/Stream/Session.php b/src/EventListener/Stream/Session.php
index 10b8c60..8567f0c 100644
--- a/src/EventListener/Stream/Session.php
+++ b/src/EventListener/Stream/Session.php
@@ -36,8 +36,8 @@
namespace Fabiang\Xmpp\EventListener\Stream;
-use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
/**
* Listener
@@ -53,8 +53,8 @@ class Session extends AbstractSessionEvent implements BlockingEventListenerInter
public function attachEvents()
{
$input = $this->getInputEventManager();
- $input->attach('{urn:ietf:params:xml:ns:xmpp-session}session', array($this, 'sessionStart'));
- $input->attach('{jabber:client}iq', array($this, 'iq'));
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-session}session', [$this, 'sessionStart']);
+ $input->attach('{jabber:client}iq', [$this, 'iq']);
}
/**
diff --git a/src/EventListener/Stream/Stanzas.php b/src/EventListener/Stream/Stanzas.php
new file mode 100644
index 0000000..6dc881e
--- /dev/null
+++ b/src/EventListener/Stream/Stanzas.php
@@ -0,0 +1,112 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\EventListener\Stream;
+
+use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\EventListener\AbstractEventListener;
+use Fabiang\Xmpp\EventListener\EventListenerInterface;
+use Fabiang\Xmpp\EventListener\UnBlockingEventListenerInterface;
+use Fabiang\Xmpp\Exception\Stream\StanzasErrorException;
+
+/**
+ * Listener
+ *
+ * @package Xmpp\EventListener
+ */
+class Stanzas extends AbstractEventListener implements EventListenerInterface
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public function attachEvents()
+ {
+ /**
+ * error events
+ * @see https://xmpp.org/extensions/xep-0133.html#errors
+ */
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}bad-request', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}conflict', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}feature-not-implemented', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}forbidden', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}not-allowed', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}service-unavailable', array($this, 'error'));
+ /**
+ * MUC error events
+ * @see https://xmpp.org/extensions/xep-0045.html#enter-errorcodes
+ */
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}item-not-found', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}registration-required', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}not-acceptable', array($this, 'error'));
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}jid-malformed', array($this, 'error'));
+ /**
+ * Pubsub
+ * @see https://xmpp.org/extensions/xep-0060.html#subscriber-retrieve-error
+ */
+ $this->getInputEventManager()
+ ->attach('{urn:ietf:params:xml:ns:xmpp-stanzas}payment-required', array($this, 'error'));
+
+ }
+
+ /**
+ * we have some errors.
+ *
+ * @param \Fabiang\Xmpp\Event\XMLEvent $event
+ * @return void
+ */
+ public function error(XMLEvent $event)
+ {
+ if ($event->isEndTag()) {
+ $blockedEvent = $this->getConnection()->getLastBlockingListener();
+ if ($blockedEvent instanceof UnBlockingEventListenerInterface) {
+ $blockedEvent->unBlock();
+ }
+ throw StanzasErrorException::createFromEvent($event);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/EventListener/Stream/StartTls.php b/src/EventListener/Stream/StartTls.php
index 9e001ce..a5b4dff 100644
--- a/src/EventListener/Stream/StartTls.php
+++ b/src/EventListener/Stream/StartTls.php
@@ -36,10 +36,10 @@
namespace Fabiang\Xmpp\EventListener\Stream;
+use Fabiang\Xmpp\Connection\SocketConnectionInterface;
use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\EventListener\AbstractEventListener;
use Fabiang\Xmpp\EventListener\BlockingEventListenerInterface;
-use Fabiang\Xmpp\Connection\SocketConnectionInterface;
/**
* Listener
@@ -62,8 +62,8 @@ class StartTls extends AbstractEventListener implements BlockingEventListenerInt
public function attachEvents()
{
$input = $this->getInputEventManager();
- $input->attach('{urn:ietf:params:xml:ns:xmpp-tls}starttls', array($this, 'starttlsEvent'));
- $input->attach('{urn:ietf:params:xml:ns:xmpp-tls}proceed', array($this, 'proceed'));
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-tls}starttls', [$this, 'starttlsEvent']);
+ $input->attach('{urn:ietf:params:xml:ns:xmpp-tls}proceed', [$this, 'proceed']);
}
/**
diff --git a/src/EventListener/Stream/Stream.php b/src/EventListener/Stream/Stream.php
index df2a31f..0dcf60d 100644
--- a/src/EventListener/Stream/Stream.php
+++ b/src/EventListener/Stream/Stream.php
@@ -61,11 +61,11 @@ class Stream extends AbstractEventListener implements BlockingEventListenerInter
public function attachEvents()
{
$this->getOutputEventManager()
- ->attach('{http://etherx.jabber.org/streams}stream', array($this, 'streamStart'));
+ ->attach('{http://etherx.jabber.org/streams}stream', [$this, 'streamStart']);
$input = $this->getInputEventManager();
- $input->attach('{http://etherx.jabber.org/streams}stream', array($this, 'streamServer'));
- $input->attach('{http://etherx.jabber.org/streams}features', array($this, 'features'));
+ $input->attach('{http://etherx.jabber.org/streams}stream', [$this, 'streamServer']);
+ $input->attach('{http://etherx.jabber.org/streams}features', [$this, 'features']);
}
/**
diff --git a/src/EventListener/Stream/StreamError.php b/src/EventListener/Stream/StreamError.php
index 1a75748..1562fa9 100644
--- a/src/EventListener/Stream/StreamError.php
+++ b/src/EventListener/Stream/StreamError.php
@@ -37,8 +37,8 @@
namespace Fabiang\Xmpp\EventListener\Stream;
use Fabiang\Xmpp\Event\XMLEvent;
-use Fabiang\Xmpp\Exception\Stream\StreamErrorException;
use Fabiang\Xmpp\EventListener\AbstractEventListener;
+use Fabiang\Xmpp\Exception\Stream\StreamErrorException;
/**
* Listener for stream errors.
@@ -55,7 +55,7 @@ public function attachEvents()
{
$this->getInputEventManager()->attach(
'{http://etherx.jabber.org/streams}error',
- array($this, 'error')
+ [$this, 'error']
);
}
diff --git a/src/EventListener/UnBlockingEventListenerInterface.php b/src/EventListener/UnBlockingEventListenerInterface.php
new file mode 100644
index 0000000..21f5ce2
--- /dev/null
+++ b/src/EventListener/UnBlockingEventListenerInterface.php
@@ -0,0 +1,53 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\EventListener;
+
+/**
+ * Interface for event listeners.
+ *
+ * @package Xmpp\EventListener
+ */
+interface UnBlockingEventListenerInterface
+{
+
+ /**
+ * unblock event listener
+ *
+ * @return boolean
+ */
+ public function unBlock();
+}
diff --git a/src/Exception/Stream/StanzasErrorException.php b/src/Exception/Stream/StanzasErrorException.php
new file mode 100644
index 0000000..39f8d55
--- /dev/null
+++ b/src/Exception/Stream/StanzasErrorException.php
@@ -0,0 +1,92 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\Exception\Stream;
+
+use Fabiang\Xmpp\Event\XMLEvent;
+
+/**
+ * Class StanzasErrorException
+ * @package Fabiang\Xmpp\Exception\Stream
+ */
+class StanzasErrorException extends StreamErrorException
+{
+ /**
+ * @see https://xmpp.org/extensions/xep-0086.html#sect-idm139696314152720
+ */
+ const ERROR_UNDEFINED = 0;
+ const ERROR_BAD_REQUEST = 400;
+ const ERROR_CONFLICT = 409;
+ const ERROR_FEATURE_NOT_IMPLEMENTED = 501;
+ const ERROR_FORBIDDEN = 403;
+ const ERROR_GONE = 302;
+ const ERROR_INTERNAL_SERVER_ERROR = 500;
+ const ERROR_ITEM_NOT_FOUND = 404;
+ const ERROR_NOT_ACCEPTABLE = 406;
+ const ERROR_NOT_ALLOWED = 405;
+ const ERROR_NOT_AUTHORIZED = 401;
+ const ERROR_REGISTRATION_REQUIRED = 407;
+ const ERROR_SERVER_TIMEOUT = 504;
+ const ERROR_SERVICE_UNAVAILABLE = 503;
+
+ /**
+ * Create exception from XMLEvent object.
+ *
+ * @param \Fabiang\Xmpp\Event\XMLEvent $event XMLEvent object
+ *
+ * @return static
+ */
+ public static function createFromEvent(XMLEvent $event)
+ {
+ /* @var $element \DOMElement */
+ list($element) = $event->getParameters();
+
+ /* @var $first \DOMElement */
+ $parent = $element->parentNode;
+
+ if (null !== $parent && XML_ELEMENT_NODE === $parent->nodeType) {
+ $code = (int)$parent->getAttribute('code');
+ $message = 'Stanzas error: "' . $element->localName . '"';
+ } else {
+ $code = 0;
+ $message = 'Generic stream error';
+ }
+
+ $exception = new static($message, $code);
+ $exception->setContent($element->ownerDocument->saveXML($element));
+
+ return $exception;
+ }
+}
\ No newline at end of file
diff --git a/src/Form/AbstractForm.php b/src/Form/AbstractForm.php
new file mode 100644
index 0000000..b25bd0a
--- /dev/null
+++ b/src/Form/AbstractForm.php
@@ -0,0 +1,202 @@
+title;
+ }
+
+ /**
+ * get instructions for form filling
+ *
+ * @return string
+ */
+ public function getInstructions()
+ {
+ return (string)$this->instructions;
+ }
+
+ /**
+ * get fields of form
+ *
+ * @return array
+ */
+ public function getFieldNames()
+ {
+ return array_keys($this->fields);
+ }
+
+ /**
+ * set value of a field
+ *
+ * @param $fieldName string
+ * @param $value string
+ * @return bool
+ */
+ public function setFieldValue($fieldName, $value)
+ {
+ if (isset($this->fields[$fieldName])) {
+ $valueNode = static::$form->ownerDocument->createElement('value', (string)$value);
+ // remove previous value
+ while ($this->fields[$fieldName]->hasChildNodes()) {
+ $this->fields[$fieldName]->removeChild($this->fields[$fieldName]->firstChild);
+ }
+ // set new value
+ $this->fields[$fieldName]->appendChild($valueNode);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * add multiple value for a field
+ *
+ * @param $fieldName string
+ * @param $value string
+ * @return bool
+ */
+ public function addFieldValue($fieldName, $value)
+ {
+ if (isset($this->fields[$fieldName])) {
+ $valueNode = static::$form->ownerDocument->createElement('value', (string)$value);
+ // add new value
+ $this->fields[$fieldName]->appendChild($valueNode);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * get field attributes, e.g. type, name, label or required
+ *
+ * @param $field
+ * @return array|null
+ */
+ public function getFieldAttributes($field)
+ {
+ if (isset($this->fields[$field])) {
+ $attributes = [];
+ if ($type = $this->fields[$field]->getAttribute('type')) {
+ $attributes['type'] = (string)$type;
+ }
+ if ($name = $this->fields[$field]->getAttribute('var')) {
+ $attributes['name'] = (string)$name;
+ }
+ if ($label = $this->fields[$field]->getAttribute('label')) {
+ $attributes['label'] = (string)$label;
+ }
+ if ($required = $this->fields[$field]->getElementsByTagName('required')) {
+ $attributes['required'] = $required->length > 0 ? true : false;
+ }
+ return $attributes;
+ }
+ return null;
+ }
+
+ /**
+ * return field options if has
+ *
+ * @param $field string
+ * @return array
+ */
+ public function getFieldOptions($field)
+ {
+ $options = array();
+ if (isset($this->fields[$field])) {
+ $optionNodeList = $this->fields[$field]->getElementsByTagName('option');
+ if ($optionNodeList->length > 0) {
+ for ($i = 0; $i < $optionNodeList->length; $i++) {
+ $optionNode = $optionNodeList->item($i);
+ array_push($options, $optionNode->firstChild->textContent);
+ }
+ }
+ }
+ return $options;
+ }
+
+ /**
+ * converts form to XML string
+ *
+ * @return string
+ */
+ public function toString()
+ {
+ static::$form->setAttribute('type', 'submit');
+ // append new values
+ foreach ($this->fields as $field) {
+ if ($field->getAttribute('type') && $field->getAttribute('type') != 'hidden') {
+ $field->removeAttribute('type');
+ }
+ if ($field->getAttribute('label')) {
+ $field->removeAttribute('label');
+ }
+ // remove option artifacts
+ $optionNodeList = $field->getElementsByTagName('option');
+ while ($optionNodeList->length > 0) {
+ $field->removeChild($optionNodeList->item(0));
+ }
+
+ static::$form->appendChild($field);
+ }
+
+ return static::$form->ownerDocument->saveXML(static::$form);
+ }
+
+ public function unsetAllFields()
+ {
+ $this->fields = array();
+ }
+}
\ No newline at end of file
diff --git a/src/Form/Form.php b/src/Form/Form.php
new file mode 100644
index 0000000..cf0dd43
--- /dev/null
+++ b/src/Form/Form.php
@@ -0,0 +1,59 @@
+getParameter(0);
+ $form = $command->getElementsByTagName('x')->item(0);
+ if ($form) {
+ static::$form = $form;
+ $this->sid = $command->getAttribute('sessionid');
+ $titleNode = static::$form->getElementsByTagName('title')->item(0);
+ if ($titleNode) {
+ $this->title = $titleNode->nodeValue;
+ self::$form->removeChild($titleNode);
+ }
+ unset($titleNode);
+ $instructionsNode = static::$form->getElementsByTagName('instructions')->item(0);
+ if ($instructionsNode) {
+ $this->instructions = $instructionsNode->nodeValue;
+ self::$form->removeChild($instructionsNode);
+ }
+ unset($instructionsNode);
+ $fieldNodeList = static::$form->getElementsByTagName('field');
+ if ($fieldNodeList->length > 0) {
+ for ($i = 0; $i < $fieldNodeList->length; $i++) {
+ $field = $fieldNodeList->item($i);
+ $this->fields[$field->getAttribute('var')] = $field;
+ }
+ } else {
+ $this->fields = array();
+ }
+ unset($fieldNodeList);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/Form/FormInterface.php b/src/Form/FormInterface.php
new file mode 100644
index 0000000..fbee025
--- /dev/null
+++ b/src/Form/FormInterface.php
@@ -0,0 +1,98 @@
+getParameter(0);
+ $form = $query->getElementsByTagName('x')->item(0);
+ if ($form) {
+ static::$form = $form;
+ unset($query);
+ $titleNode = static::$form->getElementsByTagName('title')->item(0);
+ if ($titleNode) {
+ $this->title = $titleNode->nodeValue;
+ self::$form->removeChild($titleNode);
+ }
+ unset($titleNode);
+ $instructionsNode = static::$form->getElementsByTagName('instructions')->item(0);
+ if ($instructionsNode) {
+ $this->instructions = $instructionsNode->nodeValue;
+ self::$form->removeChild($instructionsNode);
+ }
+ unset($instructionsNode);
+ $fieldNodeList = static::$form->getElementsByTagName('field');
+ if ($fieldNodeList->length > 0) {
+ for ($i = 0; $i < $fieldNodeList->length; $i++) {
+ $field = $fieldNodeList->item($i);
+ $this->fields[$field->getAttribute('var')] = $field;
+ }
+ } else {
+ $this->fields = array();
+ }
+ unset($fieldNodeList);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/Options.php b/src/Options.php
index 63b4bd5..ddeaf08 100644
--- a/src/Options.php
+++ b/src/Options.php
@@ -37,8 +37,13 @@
namespace Fabiang\Xmpp;
use Fabiang\Xmpp\Connection\ConnectionInterface;
-use Fabiang\Xmpp\Protocol\ImplementationInterface;
+use Fabiang\Xmpp\EventListener\Stream\Authentication\Anonymous;
+use Fabiang\Xmpp\EventListener\Stream\Authentication\DigestMd5;
+use Fabiang\Xmpp\EventListener\Stream\Authentication\Plain;
+use Fabiang\Xmpp\Form\FormInterface;
use Fabiang\Xmpp\Protocol\DefaultImplementation;
+use Fabiang\Xmpp\Protocol\ImplementationInterface;
+use Fabiang\Xmpp\Protocol\User\User;
use Psr\Log\LoggerInterface;
/**
@@ -99,6 +104,12 @@ class Options
*/
protected $jid;
+ /**
+ *
+ * @var FormInterface|null
+ */
+ protected $form;
+
/**
*
* @var boolean
@@ -109,7 +120,13 @@ class Options
*
* @var array
*/
- protected $users = array();
+ protected $users = [];
+
+ /**
+ *
+ * @var null|User
+ */
+ protected $user;
/**
* Timeout for connection.
@@ -123,10 +140,15 @@ class Options
*
* @var array
*/
- protected $authenticationClasses = array(
- 'digest-md5' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\DigestMd5',
- 'plain' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\Plain'
- );
+ protected $authenticationClasses;
+
+ /**
+ * Options used to create a stream context
+ *
+ * @var array
+ */
+ protected $contextOptions = [];
+
/**
* Constructor.
@@ -135,6 +157,12 @@ class Options
*/
public function __construct($address = null)
{
+ $this->authenticationClasses = [
+ 'digest-md5' => DigestMd5::class,
+ 'plain' => Plain::class,
+ 'anonymous' => Anonymous::class,
+ ];
+
if (null !== $address) {
$this->setAddress($address);
}
@@ -163,6 +191,7 @@ public function getImplementation()
public function setImplementation(ImplementationInterface $implementation)
{
$this->implementation = $implementation;
+
return $this;
}
@@ -186,10 +215,11 @@ public function getAddress()
*/
public function setAddress($address)
{
- $this->address = (string) $address;
+ $this->address = (string)$address;
if (false !== ($host = parse_url($address, PHP_URL_HOST))) {
$this->setTo($host);
}
+
return $this;
}
@@ -212,6 +242,7 @@ public function getConnection()
public function setConnection(ConnectionInterface $connection)
{
$this->connection = $connection;
+
return $this;
}
@@ -234,6 +265,7 @@ public function getLogger()
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
+
return $this;
}
@@ -257,7 +289,8 @@ public function getTo()
*/
public function setTo($to)
{
- $this->to = (string) $to;
+ $this->to = (string)$to;
+
return $this;
}
@@ -279,7 +312,8 @@ public function getUsername()
*/
public function setUsername($username)
{
- $this->username = (string) $username;
+ $this->username = (string)$username;
+
return $this;
}
@@ -292,6 +326,7 @@ public function getResource()
{
$username = $this->getUsername();
$username = explode('/', $username);
+
return isset($username[1]) ? $username[1] : '';
}
@@ -313,7 +348,8 @@ public function getPassword()
*/
public function setPassword($password)
{
- $this->password = (string) $password;
+ $this->password = (string)$password;
+
return $this;
}
@@ -335,7 +371,29 @@ public function getJid()
*/
public function setJid($jid)
{
- $this->jid = (string) $jid;
+ $this->jid = (string)$jid;
+
+ return $this;
+ }
+
+ /**
+ * @return FormInterface
+ */
+ public function getForm()
+ {
+ return $this->form;
+ }
+
+ /**
+ * set form
+ *
+ * @param FormInterface $form
+ * @return $this
+ */
+ public function setForm(FormInterface $form)
+ {
+ $this->form = $form;
+
return $this;
}
@@ -357,7 +415,8 @@ public function isAuthenticated()
*/
public function setAuthenticated($authenticated)
{
- $this->authenticated = (bool) $authenticated;
+ $this->authenticated = (bool)$authenticated;
+
return $this;
}
@@ -380,6 +439,28 @@ public function getUsers()
public function setUsers(array $users)
{
$this->users = $users;
+
+ return $this;
+ }
+
+ /**
+ * Get users.
+ *
+ * @return Protocol\User\User
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
+ * @param User $user
+ * @return $this
+ */
+ public function setUser(User $user)
+ {
+ $this->user = $user;
+
return $this;
}
@@ -401,6 +482,7 @@ public function getAuthenticationClasses()
public function setAuthenticationClasses(array $authenticationClasses)
{
$this->authenticationClasses = $authenticationClasses;
+
return $this;
}
@@ -422,7 +504,31 @@ public function getTimeout()
*/
public function setTimeout($timeout)
{
- $this->timeout = (int) $timeout;
+ $this->timeout = (int)$timeout;
+
+ return $this;
+ }
+
+ /**
+ * Get context options for connection
+ *
+ * @return array
+ */
+ public function getContextOptions()
+ {
+ return $this->contextOptions;
+ }
+
+ /**
+ * Set context options for connection
+ *
+ * @param array $contextOptions
+ * @return \Fabiang\Xmpp\Options
+ */
+ public function setContextOptions($contextOptions)
+ {
+ $this->contextOptions = (array)$contextOptions;
+
return $this;
}
}
diff --git a/src/Protocol/BlockUser.php b/src/Protocol/BlockUser.php
new file mode 100644
index 0000000..77d995d
--- /dev/null
+++ b/src/Protocol/BlockUser.php
@@ -0,0 +1,113 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\Protocol;
+
+use Fabiang\Xmpp\Util\XML;
+
+/**
+ * Protocol setting for Xmpp.
+ *
+ * @package Xmpp\Protocol
+ */
+class BlockUser implements ProtocolImplementationInterface
+{
+ protected $from;
+
+ // the jid of the user to block
+ protected $accountjid;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ '
+
+
+
+ ',
+ $this->getFrom(),
+ XML::generateId(),
+ $this->getJabberID()
+ );
+ }
+
+ /**
+ * Get JabberID.
+ *
+ * @return string
+ */
+ public function getJabberID()
+ {
+ return $this->accountjid;
+ }
+
+ /**
+ * Set abberID.
+ *
+ * @param string $accountjid
+ * @return $this
+ */
+ public function setJabberID($accountjid)
+ {
+ $this->accountjid = (string) $accountjid;
+ return $this;
+ }
+
+ /**
+ * Get JabberID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set abberID.
+ *
+ * @param string $nickname
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string) $from;
+ return $this;
+ }
+}
diff --git a/src/Protocol/BlockedUsers.php b/src/Protocol/BlockedUsers.php
new file mode 100644
index 0000000..be1100c
--- /dev/null
+++ b/src/Protocol/BlockedUsers.php
@@ -0,0 +1,57 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\Protocol;
+
+use Fabiang\Xmpp\Util\XML;
+
+/**
+ * Protocol setting for Xmpp.
+ *
+ * @package Xmpp\Protocol
+ */
+class BlockedUsers implements ProtocolImplementationInterface
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public function toString()
+ {
+ return ''
+ . '';
+ }
+}
diff --git a/src/Protocol/DefaultImplementation.php b/src/Protocol/DefaultImplementation.php
index 93a4b58..d4ca201 100644
--- a/src/Protocol/DefaultImplementation.php
+++ b/src/Protocol/DefaultImplementation.php
@@ -36,17 +36,20 @@
namespace Fabiang\Xmpp\Protocol;
-use Fabiang\Xmpp\Options;
-use Fabiang\Xmpp\EventListener\EventListenerInterface;
-use Fabiang\Xmpp\Event\EventManagerInterface;
use Fabiang\Xmpp\Event\EventManager;
-use Fabiang\Xmpp\EventListener\Stream\Stream;
-use Fabiang\Xmpp\EventListener\Stream\StreamError;
-use Fabiang\Xmpp\EventListener\Stream\StartTls;
+use Fabiang\Xmpp\Event\EventManagerInterface;
+use Fabiang\Xmpp\EventListener\EventListenerInterface;
use Fabiang\Xmpp\EventListener\Stream\Authentication;
use Fabiang\Xmpp\EventListener\Stream\Bind;
-use Fabiang\Xmpp\EventListener\Stream\Session;
+use Fabiang\Xmpp\EventListener\Stream\BlockedUsers as BlockedUsersListener;
+use Fabiang\Xmpp\EventListener\Stream\Command;
use Fabiang\Xmpp\EventListener\Stream\Roster as RosterListener;
+use Fabiang\Xmpp\EventListener\Stream\Session;
+use Fabiang\Xmpp\EventListener\Stream\Stanzas;
+use Fabiang\Xmpp\EventListener\Stream\StartTls;
+use Fabiang\Xmpp\EventListener\Stream\Stream;
+use Fabiang\Xmpp\EventListener\Stream\StreamError;
+use Fabiang\Xmpp\Options;
/**
* Default Protocol implementation.
@@ -82,6 +85,9 @@ public function register()
$this->registerListener(new Bind);
$this->registerListener(new Session);
$this->registerListener(new RosterListener);
+ $this->registerListener(new BlockedUsersListener);
+ $this->registerListener(new Stanzas);
+ $this->registerListener(new Command);
}
/**
diff --git a/src/Protocol/Presence.php b/src/Protocol/Presence.php
index 93cf800..6d33d93 100644
--- a/src/Protocol/Presence.php
+++ b/src/Protocol/Presence.php
@@ -132,6 +132,13 @@ class Presence implements ProtocolImplementationInterface
*/
protected $nickname;
+ /**
+ * Channel password.
+ *
+ * @var string
+ */
+ protected $password;
+
/**
* Constructor.
*
@@ -155,7 +162,14 @@ public function toString()
$presence .= ' to="' . XML::quote($this->getTo()) . '/' . XML::quote($this->getNickname()) . '"';
}
- return $presence . '>' . $this->getPriority() . '';
+ $presence .= '>' . $this->getPriority() . '';
+
+ if (null !== $this->getPassword()) {
+ $presence .= "" . $this->getPassword() . "";
+ }
+
+ $presence .= '';
+ return $presence;
}
/**
@@ -223,4 +237,26 @@ public function setPriority($priority)
$this->priority = (int) $priority;
return $this;
}
+
+ /**
+ * Get channel password.
+ *
+ * @return string¦null
+ */
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ /**
+ * Set channel password.
+ *
+ * @param string|null $to
+ * @return $this
+ */
+ public function setPassword($password = null)
+ {
+ $this->password = $password;
+ return $this;
+ }
}
diff --git a/src/Protocol/UnblockUser.php b/src/Protocol/UnblockUser.php
new file mode 100644
index 0000000..77b1ec3
--- /dev/null
+++ b/src/Protocol/UnblockUser.php
@@ -0,0 +1,88 @@
+
+ * @copyright 2014 Fabian Grutschus. All rights reserved.
+ * @license BSD
+ * @link http://github.com/fabiang/xmpp
+ */
+
+namespace Fabiang\Xmpp\Protocol;
+
+use Fabiang\Xmpp\Util\XML;
+
+/**
+ * Protocol setting for Xmpp.
+ *
+ * @package Xmpp\Protocol
+ */
+class UnblockUser implements ProtocolImplementationInterface
+{
+
+ // the jid of the user to block
+ protected $accountjid;
+ /**
+ * {@inheritDoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ '
+
+
+
+ ',
+ XML::generateId(),
+ $this->getJabberID()
+ );
+ }
+
+ /**
+ * Get JabberID.
+ *
+ * @return string
+ */
+ public function getJabberID()
+ {
+ return $this->accountjid;
+ }
+
+ /**
+ * Set abberID.
+ *
+ * @param string $nickname
+ * @return $this
+ */
+ public function setJabberID($accountjid)
+ {
+ $this->accountjid = (string) $accountjid;
+ return $this;
+ }
+}
diff --git a/src/Protocol/User/ChangeUserPassword.php b/src/Protocol/User/ChangeUserPassword.php
new file mode 100644
index 0000000..0a1b783
--- /dev/null
+++ b/src/Protocol/User/ChangeUserPassword.php
@@ -0,0 +1,187 @@
+setFrom($from)
+ ->setTo($to)
+ ->setUserJID($userJid)
+ ->setPassword($password)
+ ->setForm($form);
+
+ $this->form->setFieldValue('accountjid', $this->getUserJID());
+ $this->form->setFieldValue('password', $this->getPassword());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ "" .
+ "" .
+ $this->form->toString() .
+ "",
+ $this->getFrom(),
+ XML::generateId(),
+ $this->getTo(),
+ $this->form->getSid()
+ );
+ }
+
+ /**
+ * Get server address.
+ *
+ * @return string
+ */
+ public function getTo()
+ {
+ return $this->to;
+ }
+
+ /**
+ * Set receiver - for example: xmpp.example.org
+ *
+ * @param $to string
+ * @return $this
+ */
+ public function setTo($to)
+ {
+ $this->to = (string)$to;
+ return $this;
+ }
+
+ /**
+ * Get UserJID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set UserJID.
+ *
+ * @param $from string
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string)$from;
+ return $this;
+ }
+
+ /**
+ * @param FormInterface $form
+ * @return $this
+ */
+ private function setForm(FormInterface $form)
+ {
+ $this->form = $form;
+ return $this;
+ }
+
+ /**
+ * Get UserJID.
+ *
+ * @return string
+ */
+ public function getUserJID()
+ {
+ return $this->userJid;
+ }
+
+ /**
+ * set user account JID
+ *
+ * @param $userJid string
+ * @return $this
+ */
+ public function setUserJID($userJid)
+ {
+ $this->userJid = (string)$userJid;
+ return $this;
+ }
+
+ /**
+ * Get account password.
+ *
+ * @return string
+ */
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ /**
+ * @param $password string - set account password
+ * @return $this
+ */
+ public function setPassword($password)
+ {
+ $this->password = (string)$password;
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/src/Protocol/User/RegisterUser.php b/src/Protocol/User/RegisterUser.php
new file mode 100644
index 0000000..24bdcd6
--- /dev/null
+++ b/src/Protocol/User/RegisterUser.php
@@ -0,0 +1,193 @@
+setFrom($from)
+ ->setTo($to)
+ ->setForm($form)
+ ->setUserJID($userJid)
+ ->setPassword($password);
+
+ $this->form->setFieldValue('accountjid', $this->getUserJID());
+ $this->form->setFieldValue('password', $this->getPassword());
+ $this->form->setFieldValue('password-verify', $this->getPassword());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ "" .
+ "" .
+ $this->form->toString() .
+ "" .
+ "",
+ $this->getFrom(),
+ XML::generateId(),
+ $this->getTo(),
+ $this->form->getSid()
+ );
+ }
+
+ /**
+ * Get server address.
+ *
+ * @return string
+ */
+ public function getTo()
+ {
+ return $this->to;
+ }
+
+ /**
+ * Set receiver - for example: xmpp.example.org
+ *
+ * @param $to string
+ * @return $this
+ */
+ public function setTo($to)
+ {
+ $this->to = (string)$to;
+ return $this;
+ }
+
+ /**
+ * Get UserJID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set UserJID.
+ *
+ * @param $from string
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string)$from;
+ return $this;
+ }
+
+ /**
+ * @param FormInterface $form
+ * @return $this
+ */
+ private function setForm(FormInterface $form)
+ {
+ $this->form = $form;
+ return $this;
+ }
+
+ /**
+ * Get UserJID.
+ *
+ * @return string
+ */
+ public function getUserJID()
+ {
+ return $this->userJid;
+ }
+
+ /**
+ * set user account JID
+ *
+ * @param $userJid string
+ * @return $this
+ */
+ public function setUserJID($userJid)
+ {
+ $this->userJid = (string)$userJid;
+ return $this;
+ }
+
+ /**
+ * Get account password.
+ *
+ * @return string
+ */
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ /**
+ * @param $password string - set account password
+ * @return $this
+ */
+ public function setPassword($password)
+ {
+ $this->password = (string)$password;
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/src/Protocol/User/RequestChangePasswordForm.php b/src/Protocol/User/RequestChangePasswordForm.php
new file mode 100644
index 0000000..59c66bb
--- /dev/null
+++ b/src/Protocol/User/RequestChangePasswordForm.php
@@ -0,0 +1,110 @@
+setFrom($from)
+ ->setTo($to);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ "" .
+ "" .
+ "",
+ $this->getFrom(),
+ XML::generateId(),
+ $this->getTo()
+ );
+ }
+
+ /**
+ * Get server address.
+ *
+ * @return string
+ */
+ public function getTo()
+ {
+ return $this->to;
+ }
+
+ /**
+ * Set receiver - for example: xmpp.example.org
+ *
+ * @param $to string
+ * @return $this
+ */
+ public function setTo($to)
+ {
+ $this->to = (string)$to;
+ return $this;
+ }
+
+ /**
+ * Get JabberID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set jabberID.
+ *
+ * @param $from string
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string)$from;
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/src/Protocol/User/RequestUserRegisterForm.php b/src/Protocol/User/RequestUserRegisterForm.php
new file mode 100644
index 0000000..6d61ca4
--- /dev/null
+++ b/src/Protocol/User/RequestUserRegisterForm.php
@@ -0,0 +1,107 @@
+setFrom($from)
+ ->setTo($to);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage(
+ "" .
+ "" .
+ "",
+ $this->getFrom(),
+ XML::generateId(),
+ $this->getTo()
+ );
+ }
+
+ /**
+ * Get server address.
+ *
+ * @return string
+ */
+ public function getTo()
+ {
+ return $this->to;
+ }
+
+ /**
+ * Set receiver - for example: xmpp.example.org
+ *
+ * @param $to string
+ * @return $this
+ */
+ public function setTo($to)
+ {
+ $this->to = (string)$to;
+ return $this;
+ }
+
+ /**
+ * Get JabberID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set jabberID.
+ *
+ * @param $from string
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string)$from;
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/src/Protocol/User/User.php b/src/Protocol/User/User.php
index ba78d8c..c7109df 100644
--- a/src/Protocol/User/User.php
+++ b/src/Protocol/User/User.php
@@ -66,7 +66,7 @@ class User
*
* @var array
*/
- protected $groups = array();
+ protected $groups = [];
public function getName()
{
diff --git a/src/Protocol/User/VCardPresence.php b/src/Protocol/User/VCardPresence.php
new file mode 100644
index 0000000..e00984a
--- /dev/null
+++ b/src/Protocol/User/VCardPresence.php
@@ -0,0 +1,82 @@
+imageId = $imageId;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ if ($this->imageId) {
+ return XML::quoteMessage("" .
+ "" .
+ "%s" .
+ "" .
+ "" .
+ "%s" .
+ "" .
+ "",
+ $this->getImageId(),
+ $this->getImageId()
+ );
+ } else {
+ return XML::quoteMessage("" .
+ "" .
+ "");
+ }
+ }
+
+ /**
+ * set SHA1 image id
+ *
+ * @param $imageId
+ * @return $this
+ */
+ protected function setImageId($imageId)
+ {
+ $this->imageId = $imageId;
+ return $this;
+ }
+
+ /**
+ * get image SHA1 id
+ *
+ * @return string
+ */
+ public function getImageId()
+ {
+ return $this->imageId;
+ }
+}
\ No newline at end of file
diff --git a/src/Protocol/User/VCardUpdate.php b/src/Protocol/User/VCardUpdate.php
new file mode 100644
index 0000000..6c18f7f
--- /dev/null
+++ b/src/Protocol/User/VCardUpdate.php
@@ -0,0 +1,294 @@
+setFrom($from);
+ $this->setProperty('JABBERID', $from);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toString()
+ {
+ return XML::quoteMessage("" .
+ "" .
+ $this->composeVCard() .
+ "" .
+ "",
+ XML::generateId()
+ );
+ }
+
+ /**
+ * compose XML string of vCard
+ * @return string
+ */
+ protected function composeVCard()
+ {
+ $xmlVCard = '';
+ if (!empty($this->vCard)) {
+ foreach ($this->vCard as $attrName => $attrValue) {
+ // DOMNode maybe?
+ $xmlVCard .= '<' . $attrName . '>';
+ if (is_array($attrValue)) {
+ foreach ($attrValue as $subAttrName => $subAttrValue) {
+ $xmlVCard .= '<' . $subAttrName . '>';
+ $xmlVCard .= (string)$subAttrValue;
+ $xmlVCard .= '' . $subAttrName . '>';
+ }
+ } else {
+ $xmlVCard .= (string)$attrValue;
+ }
+ $xmlVCard .= '' . $attrName . '>';
+ }
+ }
+ return $xmlVCard;
+ }
+
+ /**
+ * Get UserJID.
+ *
+ * @return string
+ */
+ public function getFrom()
+ {
+ return $this->from;
+ }
+
+ /**
+ * Set UserJID.
+ *
+ * @param $from string
+ * @return $this
+ */
+ public function setFrom($from)
+ {
+ $this->from = (string)$from;
+ return $this;
+ }
+
+ /**
+ * set property of vCard
+ *
+ * @param $property
+ * @param $value
+ * @return $this
+ */
+ public function setProperty($property, $value)
+ {
+ if (in_array($property, $this->availableProperties)) {
+ switch ($property) {
+ case 'GIVEN':
+ case 'FAMILY':
+ case 'MIDDLE':
+ if (!isset($this->vCard['N'])) {
+ $this->vCard['N'] = array('FAMILY' => '', 'GIVEN' => '', 'MIDDLE' => '');
+ $this->vCard['FN'] = '';
+ }
+ $this->vCard['N'][$property] = (string)$value;
+ $this->vCard['FN'] .= empty($this->vCard['FN']) ? (string)$value : ' ' . (string)$value;
+ break;
+ case 'URL':
+ case 'NICKNAME':
+ case 'JABBERID':
+ case 'DESC':
+ $this->vCard[$property] = strip_tags($value);
+ break;
+ case 'EMAIL':
+ $this->vCard[$property]['USERID'] = strip_tags($value);
+ break;
+ case 'PHOTO':
+ // value must be path to image
+ $this->setImage($value);
+ $this->vCard['PHOTO'] = array('TYPE' => $this->getImageMime(), 'BINVAL' => $this->getImageBase64Data());
+ // free some memory
+ $this->imageData = null;
+ break;
+ }
+ }
+ return $this;
+ }
+
+ /**
+ * @param $url
+ * @return $this
+ */
+ public function setImageUrl($url)
+ {
+ if (filter_var($url, FILTER_VALIDATE_URL) && isset($this->vCard['PHOTO'])) {
+ $this->vCard['PHOTO']['EXTVAL'] = $url;
+ }
+ return $this;
+ }
+
+ /**
+ * Set image content
+ *
+ * @param $path
+ * @return $this
+ */
+ public function setImage($path)
+ {
+ if (!file_exists($path)) {
+ throw new InvalidArgumentException('File "' . $path . '" does not exists.');
+ }
+ $this->imagePath = $path;
+
+ $this->getImageMime();
+ $this->imageData = file_get_contents($path);
+ $this->setImageId();
+ return $this;
+ }
+
+ /**
+ * set SHA1 image id
+ */
+ protected function setImageId()
+ {
+ $this->imageId = sha1($this->imageData);
+ }
+
+ /**
+ * get image SHA1 id
+ *
+ * @return string
+ */
+ public function getImageId()
+ {
+ return $this->imageId;
+ }
+
+
+ /**
+ * get converted to Base64 image data
+ *
+ * @see https://xmpp.org/extensions/xep-0153.html#bizrules-image
+ * @return string
+ */
+ protected function getImageBase64Data()
+ {
+ return "\n" . wordwrap(XML::base64Encode($this->imageData), 75, "\n", true) . "\n";
+ }
+
+ /**
+ * get image mime type
+ * @return string
+ */
+ protected function getImageMime()
+ {
+ if (!$this->imageMime) {
+ $size = getimagesize($this->imagePath);
+ $this->imageMime = isset($size['mime']) ? $size['mime'] : '';
+
+ if ($size[0] < 32 || $size[1] < 32 || $size[0] > 96 || $size[1] > 96) {
+ throw new InvalidArgumentException('Image size must be between 32px and 96px');
+ }
+ if (!in_array($this->imageMime, $this->mimes)) {
+ throw new InvalidArgumentException('Type of Image must be of allowed mimes: ' . implode(', ', $this->mimes) . '.');
+ }
+ }
+ return $this->imageMime;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/Stream/SocketClient.php b/src/Stream/SocketClient.php
index afba977..c0b6876 100644
--- a/src/Stream/SocketClient.php
+++ b/src/Stream/SocketClient.php
@@ -63,39 +63,57 @@ class SocketClient
*/
protected $address;
+
+ /**
+ * Options used to create a stream context
+ * @see http://php.net/manual/en/function.stream-context-create.php
+ *
+ * @var array
+ */
+ protected $options;
+
/**
* Constructor takes address as argument.
*
* @param string $address
*/
- public function __construct($address)
+ public function __construct($address, $options = null)
{
$this->address = $address;
+ $this->options = $options;
}
/**
* Connect.
*
- * @param integer $timeout Timeout for connection
+ * @param integer $timeout Timeout for connection
* @param boolean $persistent Persitent connection
* @return void
*/
public function connect($timeout = 30, $persistent = false)
{
+ $flags = STREAM_CLIENT_CONNECT;
+
if (true === $persistent) {
- $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
- } else {
- $flags = STREAM_CLIENT_CONNECT;
+ $flags |= STREAM_CLIENT_PERSISTENT;
}
// call stream_socket_client with custom error handler enabled
$handler = new ErrorHandler(
- function ($address, $timeout, $flags) {
+ function ($address, $timeout, $flags, array $options = null) {
+ $errno = null;
+ $errstr = null;
+
+ if (!empty($options)) {
+ $context = stream_context_create($options);
+ return stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context);
+ }
return stream_socket_client($address, $errno, $errstr, $timeout, $flags);
},
$this->address,
$timeout,
- $flags
+ $flags,
+ $this->options
);
$resource = $handler->execute(__FILE__, __LINE__);
@@ -106,9 +124,9 @@ function ($address, $timeout, $flags) {
/**
* Reconnect and optionally use different address.
*
- * @param string $address
+ * @param string $address
* @param integer $timeout
- * @param bool $persistent
+ * @param bool $persistent
*/
public function reconnect($address = null, $timeout = 30, $persistent = false)
{
@@ -139,7 +157,7 @@ public function close()
*/
public function setBlocking($flag = true)
{
- stream_set_blocking($this->resource, (int) $flag);
+ stream_set_blocking($this->resource, (int)$flag);
return $this;
}
@@ -157,7 +175,7 @@ public function read($length = self::BUFFER_LENGTH)
/**
* Write to stream.
*
- * @param string $string String
+ * @param string $string String
* @param integer $length Limit
* @return void
*/
@@ -173,7 +191,7 @@ public function write($string, $length = null)
/**
* Enable/disable cryptography on stream.
*
- * @param boolean $enable Flag
+ * @param boolean $enable Flag
* @param integer $cryptoType One of the STREAM_CRYPTO_METHOD_* constants.
* @return void
* @throws InvalidArgumentException
diff --git a/src/Stream/XMLStream.php b/src/Stream/XMLStream.php
index 72e26e4..4899722 100644
--- a/src/Stream/XMLStream.php
+++ b/src/Stream/XMLStream.php
@@ -36,9 +36,9 @@
namespace Fabiang\Xmpp\Stream;
+use Fabiang\Xmpp\Event\EventManager;
use Fabiang\Xmpp\Event\EventManagerAwareInterface;
use Fabiang\Xmpp\Event\EventManagerInterface;
-use Fabiang\Xmpp\Event\EventManager;
use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Event\XMLEventInterface;
use Fabiang\Xmpp\Exception\XMLParserException;
@@ -85,21 +85,21 @@ class XMLStream implements EventManagerAwareInterface
*
* @var array
*/
- protected $namespaces = array();
+ protected $namespaces = [];
/**
* Cache of namespace prefixes.
*
* @var array
*/
- protected $namespacePrefixes = array();
+ protected $namespacePrefixes = [];
/**
* Element cache.
*
* @var array
*/
- protected $elements = array();
+ protected $elements = [];
/**
* XML parser.
@@ -120,7 +120,7 @@ class XMLStream implements EventManagerAwareInterface
*
* @var array
*/
- protected $eventCache = array();
+ protected $eventCache = [];
/**
* Constructor.
@@ -155,13 +155,13 @@ public function parse($source)
{
$this->clearDocument($source);
- $this->eventCache = array();
+ $this->eventCache = [];
if (0 === xml_parse($this->parser, $source, false)) {
throw XMLParserException::create($this->parser);
}
// trigger collected events.
$this->trigger();
- $this->eventCache = array();
+ $this->eventCache = [];
// was not there, so lets close the document
if ($this->depth > 0) {
@@ -186,7 +186,7 @@ protected function clearDocument($source)
if ('reset();
- $matches = array();
+ $matches = [];
if (preg_match('/^<\?xml.*encoding=(\'|")([\w-]+)\1.*?>/i', $source, $matches)) {
$this->encoding = $matches[2];
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding);
@@ -260,7 +260,7 @@ protected function startXml()
$this->depth++;
$event = '{' . $namespaceElement . '}' . $elementName;
- $this->cacheEvent($event, true, array($element));
+ $this->cacheEvent($event, true, [$element]);
}
/**
@@ -271,7 +271,7 @@ protected function startXml()
*/
protected function createAttributeNodes(array $attribs)
{
- $attributesNodes = array();
+ $attributesNodes = [];
foreach ($attribs as $name => $value) {
// collect namespace prefixes
if ('xmlns:' === substr($name, 0, 6)) {
@@ -316,7 +316,7 @@ protected function endXml()
}
$event = '{' . $namespaceURI . '}' . $localName;
- $this->cacheEvent($event, false, array($element));
+ $this->cacheEvent($event, false, [$element]);
}
/**
@@ -345,7 +345,7 @@ protected function dataXml()
*/
protected function cacheEvent($event, $startTag, $params)
{
- $this->eventCache[] = array($event, $startTag, $params);
+ $this->eventCache[] = [$event, $startTag, $params];
}
/**
@@ -382,9 +382,9 @@ public function reset()
$this->parser = $parser;
$this->depth = 0;
$this->document = new \DOMDocument('1.0', $this->encoding);
- $this->namespaces = array();
- $this->namespacePrefixes = array();
- $this->elements = array();
+ $this->namespaces = [];
+ $this->namespacePrefixes = [];
+ $this->elements = [];
}
/**
diff --git a/src/Util/ErrorHandler.php b/src/Util/ErrorHandler.php
index cf63cad..9752fa2 100644
--- a/src/Util/ErrorHandler.php
+++ b/src/Util/ErrorHandler.php
@@ -36,8 +36,8 @@
namespace Fabiang\Xmpp\Util;
-use Fabiang\Xmpp\Exception\InvalidArgumentException;
use Fabiang\Xmpp\Exception\ErrorException;
+use Fabiang\Xmpp\Exception\InvalidArgumentException;
/**
* XML utility methods.
@@ -59,7 +59,7 @@ class ErrorHandler
*
* @var array
*/
- protected $arguments = array();
+ protected $arguments = [];
public function __construct($method)
{
diff --git a/tests/features/bootstrap/BindContext.php b/tests/features/bootstrap/BindContext.php
index ff963e7..f3f19dd 100644
--- a/tests/features/bootstrap/BindContext.php
+++ b/tests/features/bootstrap/BindContext.php
@@ -37,7 +37,6 @@
namespace Fabiang\Xmpp\Integration;
use Behat\Behat\Context\BehatContext;
-use Behat\Behat\Exception\PendingException;
class BindContext extends BehatContext
{
@@ -63,7 +62,9 @@ public function requestForBindingSend()
{
$buffer = $this->getConnection()->getBuffer();
assertRegExp(
- '#^$#',
+ '#^'
+ . ''
+ . '$#',
$buffer[1]
);
}
diff --git a/tests/src/ClientTest.php b/tests/src/ClientTest.php
index 12cd182..f17bc66 100644
--- a/tests/src/ClientTest.php
+++ b/tests/src/ClientTest.php
@@ -36,12 +36,18 @@
namespace Fabiang\Xmpp;
+use Fabiang\Xmpp\Connection\ConnectionInterface;
+use Fabiang\Xmpp\Event\EventManagerInterface;
+use Fabiang\Xmpp\EventListener\Logger;
+use Fabiang\Xmpp\Protocol\ImplementationInterface;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 10:05:30.
*
* @coversDefaultClass Fabiang\Xmpp\Client
*/
-class ClientTest extends \PHPUnit_Framework_TestCase
+class ClientTest extends TestCase
{
/**
* @var Client
@@ -76,18 +82,16 @@ class ClientTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
- $this->options = $this->getMockBuilder('Fabiang\Xmpp\Options')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->options = $this->createMock(Options::class);
- $this->connection = $this->getMock('Fabiang\Xmpp\Connection\ConnectionInterface');
+ $this->connection = $this->createMock(ConnectionInterface::class);
$this->options->expects($this->any())
->method('getConnection')
->willReturn($this->connection);
- $this->eventManager = $this->getMock('Fabiang\Xmpp\Event\EventManagerInterface');
- $this->implementation = $this->getMock('Fabiang\Xmpp\Protocol\ImplementationInterface');
+ $this->eventManager = $this->createMock(EventManagerInterface::class);
+ $this->implementation = $this->createMock(ImplementationInterface::class);
$this->options->expects($this->any())
->method('getImplementation')
@@ -117,7 +121,7 @@ public function testConstructor()
$this->implementation->expects($this->once())
->method('registerListener')
- ->with($this->isInstanceOf('\Fabiang\Xmpp\EventListener\Logger'));
+ ->with($this->isInstanceOf(Logger::class));
$this->implementation->expects($this->once())
->method('setEventManager')
@@ -150,17 +154,15 @@ public function testConstructor()
*/
public function testConstructorCreatingDefaults()
{
- $options = $this->getMockBuilder('Fabiang\Xmpp\Options')
- ->disableOriginalConstructor()
- ->getMock();
+ $options = $this->createMock(Options::class);
$options->expects($this->any())
->method('getImplementation')
->willReturn($this->implementation);
$object = new Client($options);
- $this->assertInstanceOf('Fabiang\Xmpp\Event\EventManagerInterface', $object->getEventManager());
- $this->assertInstanceOf('Fabiang\Xmpp\Connection\ConnectionInterface', $object->getConnection());
+ $this->assertInstanceOf(EventManagerInterface::class, $object->getEventManager());
+ $this->assertInstanceOf(ConnectionInterface::class, $object->getConnection());
}
/**
@@ -206,7 +208,7 @@ public function testSend()
->method('send')
->with($this->equalTo('test'));
- $message = $this->getMock('Fabiang\Xmpp\Protocol\ProtocolImplementationInterface');
+ $message = $this->createMock(Protocol\ProtocolImplementationInterface::class);
$message->expects($this->once())
->method('toString')
->willReturn('test');
@@ -224,7 +226,7 @@ public function testSend()
*/
public function testSetAndGetEventManager()
{
- $eventManager = $this->getMock('Fabiang\Xmpp\Event\EventManagerInterface');
+ $eventManager = $this->createMock(EventManagerInterface::class);
$this->assertSame($eventManager, $this->object->setEventManager($eventManager)->getEventManager());
}
@@ -252,9 +254,12 @@ public function testGetOptions()
public function testOptionsConnection()
{
$options = new Options();
- $client = $this->getMock('\Fabiang\Xmpp\Client', array('setupImplement'), array($options));
+ $client = $this->getMockBuilder(Client::class)
+ ->setMethods(array('setupImplement'))
+ ->setConstructorArgs([$options])
+ ->getMock();
$optionsAssert = $client->getOptions();
- $this->assertInstanceOf('Fabiang\Xmpp\Connection\ConnectionInterface', $optionsAssert->getConnection());
+ $this->assertInstanceOf(ConnectionInterface::class, $optionsAssert->getConnection());
}
}
diff --git a/tests/src/Connection/SocketTest.php b/tests/src/Connection/SocketTest.php
index 523a64c..46e8685 100644
--- a/tests/src/Connection/SocketTest.php
+++ b/tests/src/Connection/SocketTest.php
@@ -36,12 +36,13 @@
namespace Fabiang\Xmpp\Connection;
-use Fabiang\Xmpp\Stream\XMLStream;
-use Fabiang\Xmpp\Stream\SocketClient;
-use Fabiang\Xmpp\EventListener\Stream\Stream;
-use Fabiang\Xmpp\Event\EventManager;
use Fabiang\Xmpp\Event\Event;
+use Fabiang\Xmpp\Event\EventManager;
+use Fabiang\Xmpp\EventListener\Stream\Stream;
use Fabiang\Xmpp\Options;
+use Fabiang\Xmpp\Stream\SocketClient;
+use Fabiang\Xmpp\Stream\XMLStream;
+use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;
/**
@@ -49,7 +50,7 @@
*
* @coversDefaultClass Fabiang\Xmpp\Connection\Socket
*/
-class SocketTest extends \PHPUnit_Framework_TestCase
+class SocketTest extends TestCase
{
/**
@@ -87,7 +88,7 @@ protected function setUp()
*/
public function testConstructor()
{
- $mock = $this->getMock('\Fabiang\Xmpp\Stream\SocketClient', array(), array(), '', false);
+ $mock = $this->createMock(SocketClient::class);
$object = new Socket($mock, '');
$this->assertSame($mock, $object->getSocket());
}
@@ -117,7 +118,7 @@ public function testReceive()
$mock = $this->object->getSocket();
$mock->expects($this->once())
->method('read')
- ->with($this->equalTo(4096))
+ ->with($this->equalTo(65536))
->will($this->returnValue($return));
$this->assertSame($return, $this->object->receive());
}
diff --git a/tests/src/Connection/TestTest.php b/tests/src/Connection/TestTest.php
index c9f504d..46eba9d 100644
--- a/tests/src/Connection/TestTest.php
+++ b/tests/src/Connection/TestTest.php
@@ -2,17 +2,17 @@
namespace Fabiang\Xmpp\Connection;
-use Fabiang\Xmpp\Options;
-use Fabiang\Xmpp\Connection\Socket;
-use Fabiang\Xmpp\EventListener\Stream\Stream;
use Fabiang\Xmpp\Event\Event;
+use Fabiang\Xmpp\EventListener\Stream\Stream;
+use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 15:29:46.
*
* @coversDefaultClass Fabiang\Xmpp\Connection\Test
*/
-class TestTest extends \PHPUnit_Framework_TestCase
+class TestTest extends TestCase
{
/**
diff --git a/tests/src/Event/EventManagerTest.php b/tests/src/Event/EventManagerTest.php
index 219c649..132c038 100644
--- a/tests/src/Event/EventManagerTest.php
+++ b/tests/src/Event/EventManagerTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Event;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-12-31 at 19:16:20.
*
* @coversDefaultClass Fabiang\Xmpp\Event\EventManager
*/
-class EventManagerTest extends \PHPUnit_Framework_TestCase
+class EventManagerTest extends TestCase
{
/**
diff --git a/tests/src/Event/EventTest.php b/tests/src/Event/EventTest.php
index 2c61d57..87f5023 100644
--- a/tests/src/Event/EventTest.php
+++ b/tests/src/Event/EventTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Event;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-12-31 at 20:01:01.
*
* @coversDefaultClass Fabiang\Xmpp\Event\Event
*/
-class EventTest extends \PHPUnit_Framework_TestCase
+class EventTest extends TestCase
{
/**
diff --git a/tests/src/Event/XMLEventTest.php b/tests/src/Event/XMLEventTest.php
index 0b811c0..3fe3a13 100644
--- a/tests/src/Event/XMLEventTest.php
+++ b/tests/src/Event/XMLEventTest.php
@@ -36,10 +36,12 @@
namespace Fabiang\Xmpp\Event;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-11 at 18:21:21.
*/
-class XMLEventTest extends \PHPUnit_Framework_TestCase
+class XMLEventTest extends TestCase
{
/**
* @var XMLEvent
diff --git a/tests/src/EventListener/LoggerTest.php b/tests/src/EventListener/LoggerTest.php
index e47d792..bf93c42 100644
--- a/tests/src/EventListener/LoggerTest.php
+++ b/tests/src/EventListener/LoggerTest.php
@@ -36,17 +36,19 @@
namespace Fabiang\Xmpp\EventListener;
-use Monolog\Logger as MonologLogger;
-use Monolog\Handler\TestHandler;
use Fabiang\Xmpp\Event\Event;
+use Fabiang\Xmpp\Event\EventManagerInterface;
use Fabiang\Xmpp\Options;
+use Monolog\Handler\TestHandler;
+use Monolog\Logger as MonologLogger;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-21 at 14:18:43.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Logger
*/
-class LoggerTest extends \PHPUnit_Framework_TestCase
+class LoggerTest extends TestCase
{
/**
@@ -123,8 +125,8 @@ public function testAttachEvents()
*/
public function testSetAndGetEventManager()
{
- $this->assertInstanceOf('\Fabiang\Xmpp\Event\EventManagerInterface', $this->object->getEventManager());
- $eventManager = $this->getMock('\Fabiang\Xmpp\Event\EventManagerInterface');
+ $this->assertInstanceOf(EventManagerInterface::class, $this->object->getEventManager());
+ $eventManager = $this->createMock(EventManagerInterface::class);
$this->assertSame($eventManager, $this->object->setEventManager($eventManager)->getEventManager());
}
}
diff --git a/tests/src/EventListener/Stream/Authentication/DigestMd5Test.php b/tests/src/EventListener/Stream/Authentication/DigestMd5Test.php
index 8c4a2fd..c3a1740 100644
--- a/tests/src/EventListener/Stream/Authentication/DigestMd5Test.php
+++ b/tests/src/EventListener/Stream/Authentication/DigestMd5Test.php
@@ -36,17 +36,18 @@
namespace Fabiang\Xmpp\EventListener\Stream\Authentication;
-use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Connection\Test;
+use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Util\XML;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-27 at 12:11:12.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Authentication\DigestMd5
*/
-class DigestMd5Test extends \PHPUnit_Framework_TestCase
+class DigestMd5Test extends TestCase
{
/**
diff --git a/tests/src/EventListener/Stream/AuthenticationTest.php b/tests/src/EventListener/Stream/AuthenticationTest.php
index 5d2a55c..4819eda 100644
--- a/tests/src/EventListener/Stream/AuthenticationTest.php
+++ b/tests/src/EventListener/Stream/AuthenticationTest.php
@@ -36,17 +36,18 @@
namespace Fabiang\Xmpp\EventListener\Stream;
-use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Connection\Test;
use Fabiang\Xmpp\Event\EventManager;
+use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-11 at 18:29:57.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Authentication
*/
-class AuthenticationTest extends \PHPUnit_Framework_TestCase
+class AuthenticationTest extends TestCase
{
/**
@@ -276,7 +277,7 @@ public function testSuccess()
$event = new XMLEvent;
$event->setParameters(array($element));
- $connection = $this->getMock('\Fabiang\Xmpp\Connection\Test', array());
+ $connection = $this->createMock(Test::class);
$this->object->getOptions()->setConnection($connection);
$connection->expects($this->once())
diff --git a/tests/src/EventListener/Stream/BindTest.php b/tests/src/EventListener/Stream/BindTest.php
index de90ef4..8c3b242 100644
--- a/tests/src/EventListener/Stream/BindTest.php
+++ b/tests/src/EventListener/Stream/BindTest.php
@@ -37,15 +37,16 @@
namespace Fabiang\Xmpp\EventListener\Stream;
use Fabiang\Xmpp\Connection\Test;
-use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 15:11:34.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Bind
*/
-class BindTest extends \PHPUnit_Framework_TestCase
+class BindTest extends TestCase
{
/**
@@ -72,6 +73,7 @@ protected function setUp()
$options = new Options;
$options->setConnection($this->connection);
+ $options->setUsername('foo/baz@test.com');
$this->object->setOptions($options);
$this->connection->setReady(true)->setOptions($options);
$this->connection->connect();
@@ -131,7 +133,9 @@ public function testBind()
$this->assertTrue($this->object->isBlocking());
$buffer = $this->connection->getBuffer();
$this->assertRegExp(
- '##',
+ '#'
+ . ''
+ . 'baz@test.com#',
$buffer[1]
);
}
diff --git a/tests/src/EventListener/Stream/RosterTest.php b/tests/src/EventListener/Stream/RosterTest.php
index 9491144..23ac797 100644
--- a/tests/src/EventListener/Stream/RosterTest.php
+++ b/tests/src/EventListener/Stream/RosterTest.php
@@ -36,17 +36,18 @@
namespace Fabiang\Xmpp\EventListener\Stream;
-use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Connection\Test;
+use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\User\User;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 10:15:26.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Roster
*/
-class RosterTest extends \PHPUnit_Framework_TestCase
+class RosterTest extends TestCase
{
/**
diff --git a/tests/src/EventListener/Stream/SessionTest.php b/tests/src/EventListener/Stream/SessionTest.php
index 30260f5..c139b76 100644
--- a/tests/src/EventListener/Stream/SessionTest.php
+++ b/tests/src/EventListener/Stream/SessionTest.php
@@ -37,15 +37,16 @@
namespace Fabiang\Xmpp\EventListener\Stream;
use Fabiang\Xmpp\Connection\Test;
-use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 16:01:32.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Session
*/
-class SessionTest extends \PHPUnit_Framework_TestCase
+class SessionTest extends TestCase
{
/**
diff --git a/tests/src/EventListener/Stream/StartTlsTest.php b/tests/src/EventListener/Stream/StartTlsTest.php
index 6a8409e..cf6e356 100644
--- a/tests/src/EventListener/Stream/StartTlsTest.php
+++ b/tests/src/EventListener/Stream/StartTlsTest.php
@@ -37,15 +37,16 @@
namespace Fabiang\Xmpp\EventListener\Stream;
use Fabiang\Xmpp\Connection\Test;
-use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Event\XMLEvent;
+use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 14:16:00.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\StartTls
*/
-class StartTlsTest extends \PHPUnit_Framework_TestCase
+class StartTlsTest extends TestCase
{
/**
diff --git a/tests/src/EventListener/Stream/StreamTest.php b/tests/src/EventListener/Stream/StreamTest.php
index 5fd95bb..511fff0 100644
--- a/tests/src/EventListener/Stream/StreamTest.php
+++ b/tests/src/EventListener/Stream/StreamTest.php
@@ -36,16 +36,17 @@
namespace Fabiang\Xmpp\EventListener\Stream;
-use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Connection\Test;
+use Fabiang\Xmpp\Event\XMLEvent;
use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-11 at 18:20:16.
*
* @coversDefaultClass Fabiang\Xmpp\EventListener\Stream\Stream
*/
-class StreamTest extends \PHPUnit_Framework_TestCase
+class StreamTest extends TestCase
{
/**
diff --git a/tests/src/Exception/Stream/StreamErrorExceptionTest.php b/tests/src/Exception/Stream/StreamErrorExceptionTest.php
index 5984b1c..a140b45 100644
--- a/tests/src/Exception/Stream/StreamErrorExceptionTest.php
+++ b/tests/src/Exception/Stream/StreamErrorExceptionTest.php
@@ -37,13 +37,14 @@
namespace Fabiang\Xmpp\Exception\Stream;
use Fabiang\Xmpp\Event\XMLEvent;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 11:18:45.
*
* @coversDefaultClass Fabiang\Xmpp\Exception\Stream\StreamErrorException
*/
-class StreamErrorExceptionTest extends \PHPUnit_Framework_TestCase
+class StreamErrorExceptionTest extends TestCase
{
/**
diff --git a/tests/src/Exception/XMLParserExceptionTest.php b/tests/src/Exception/XMLParserExceptionTest.php
index f58fc34..e7c4cad 100644
--- a/tests/src/Exception/XMLParserExceptionTest.php
+++ b/tests/src/Exception/XMLParserExceptionTest.php
@@ -36,10 +36,12 @@
namespace Fabiang\Xmpp\Exception;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 11:09:05.
*/
-class XMLParserExceptionTest extends \PHPUnit_Framework_TestCase
+class XMLParserExceptionTest extends TestCase
{
/**
diff --git a/tests/src/OptionsTest.php b/tests/src/OptionsTest.php
index 9f7a0ba..5d5ffc8 100644
--- a/tests/src/OptionsTest.php
+++ b/tests/src/OptionsTest.php
@@ -37,13 +37,14 @@
namespace Fabiang\Xmpp;
use Fabiang\Xmpp\Connection\Test;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 09:32:06.
*
* @coversDefaultClass Fabiang\Xmpp\Options
*/
-class OptionsTest extends \PHPUnit_Framework_TestCase
+class OptionsTest extends TestCase
{
/**
diff --git a/tests/src/Protocol/DefaultImplementationTest.php b/tests/src/Protocol/DefaultImplementationTest.php
index 386c236..7438751 100644
--- a/tests/src/Protocol/DefaultImplementationTest.php
+++ b/tests/src/Protocol/DefaultImplementationTest.php
@@ -36,15 +36,16 @@
namespace Fabiang\Xmpp\Protocol;
-use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Connection\Test;
+use Fabiang\Xmpp\Options;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 09:54:58.
*
* @coversDefaultClass Fabiang\Xmpp\Protocol\DefaultImplementation
*/
-class DefaultImplementationTest extends \PHPUnit_Framework_TestCase
+class DefaultImplementationTest extends TestCase
{
/**
diff --git a/tests/src/Protocol/MessageTest.php b/tests/src/Protocol/MessageTest.php
index af3bfcc..6c20cfd 100644
--- a/tests/src/Protocol/MessageTest.php
+++ b/tests/src/Protocol/MessageTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Protocol;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 13:25:49.
*
* @coversDefaultClass Fabiang\Xmpp\Protocol\Message
*/
-class MessageTest extends \PHPUnit_Framework_TestCase
+class MessageTest extends TestCase
{
/**
diff --git a/tests/src/Protocol/PresenceTest.php b/tests/src/Protocol/PresenceTest.php
index bbf5187..8b9809d 100644
--- a/tests/src/Protocol/PresenceTest.php
+++ b/tests/src/Protocol/PresenceTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Protocol;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 11:12:27.
*
* @coversDefaultClass Fabiang\Xmpp\Protocol\Presence
*/
-class PresenceTest extends \PHPUnit_Framework_TestCase
+class PresenceTest extends TestCase
{
/**
diff --git a/tests/src/Protocol/RosterTest.php b/tests/src/Protocol/RosterTest.php
index cb8d36d..7bcf4a1 100644
--- a/tests/src/Protocol/RosterTest.php
+++ b/tests/src/Protocol/RosterTest.php
@@ -36,10 +36,12 @@
namespace Fabiang\Xmpp\Protocol;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 10:08:00.
*/
-class RosterTest extends \PHPUnit_Framework_TestCase
+class RosterTest extends TestCase
{
/**
diff --git a/tests/src/Protocol/User/UserTest.php b/tests/src/Protocol/User/UserTest.php
index 325e54b..12492e9 100644
--- a/tests/src/Protocol/User/UserTest.php
+++ b/tests/src/Protocol/User/UserTest.php
@@ -2,10 +2,12 @@
namespace Fabiang\Xmpp\Protocol\User;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-20 at 10:36:12.
*/
-class UserTest extends \PHPUnit_Framework_TestCase
+class UserTest extends TestCase
{
/**
diff --git a/tests/src/Stream/SocketClientTest.php b/tests/src/Stream/SocketClientTest.php
index e1a3d2a..2e5a650 100644
--- a/tests/src/Stream/SocketClientTest.php
+++ b/tests/src/Stream/SocketClientTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Stream;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator on 2014-11-17 at 19:10:27.
*
* @coversDefaultClass Fabiang\Xmpp\Stream\SocketClient
*/
-class SocketClientTest extends \PHPUnit_Framework_TestCase
+class SocketClientTest extends TestCase
{
/**
diff --git a/tests/src/Stream/XMLStreamTest.php b/tests/src/Stream/XMLStreamTest.php
index 12d9e4a..297956c 100644
--- a/tests/src/Stream/XMLStreamTest.php
+++ b/tests/src/Stream/XMLStreamTest.php
@@ -36,7 +36,7 @@
namespace Fabiang\Xmpp\Stream;
-use PHPUnit_Framework_TestCase as TestCase;
+use PHPUnit\Framework\TestCase as TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-12-31 at 21:28:14.
diff --git a/tests/src/Util/ErrorHandlerTest.php b/tests/src/Util/ErrorHandlerTest.php
index 9eb407b..0faf68a 100644
--- a/tests/src/Util/ErrorHandlerTest.php
+++ b/tests/src/Util/ErrorHandlerTest.php
@@ -37,13 +37,14 @@
namespace Fabiang\Xmpp\Util;
use Fabiang\Xmpp\Exception\ErrorException;
+use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator on 2014-11-13 at 13:42:23.
*
* @coversDefaultClass Fabiang\Xmpp\Util\ErrorHandler
*/
-class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
+class ErrorHandlerTest extends TestCase
{
/**
diff --git a/tests/src/Util/XMLTest.php b/tests/src/Util/XMLTest.php
index 9ccee93..59c2e11 100644
--- a/tests/src/Util/XMLTest.php
+++ b/tests/src/Util/XMLTest.php
@@ -36,12 +36,14 @@
namespace Fabiang\Xmpp\Util;
+use PHPUnit\Framework\TestCase;
+
/**
* Generated by PHPUnit_SkeletonGenerator on 2014-10-29 at 11:04:03.
*
* @coversDefaultClass Fabiang\Xmpp\Util\XML
*/
-class XMLTest extends \PHPUnit_Framework_TestCase
+class XMLTest extends TestCase
{
/**