PK IeśNë«”I I
LICENSE.mdnu W+A¶ Simplified BSD License
======================
Copyright 2014-2017 Fabian Grutschus.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PK IeśN?äŰ_* * README.mdnu W+A¶ # fabiang/xmpp
Library for XMPP protocol connections (Jabber) for PHP.
[![License](https://poser.pugx.org/fabiang/xmpp/license.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Latest Stable Version](https://poser.pugx.org/fabiang/xmpp/v/stable.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Total Downloads](https://poser.pugx.org/fabiang/xmpp/downloads.svg)](https://packagist.org/packages/fabiang/xmpp)
[![Dependency Status](https://gemnasium.com/fabiang/xmpp.svg)](https://gemnasium.com/fabiang/xmpp)
[![Build Status](https://travis-ci.org/fabiang/xmpp.png?branch=master)](https://travis-ci.org/fabiang/xmpp)
[![Coverage Status](https://img.shields.io/coveralls/fabiang/xmpp.svg)](https://coveralls.io/r/fabiang/xmpp?branch=master)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/fabiang/xmpp/badges/quality-score.png?s=2605ad2bc987ff8501b8f749addff43ec1ac7098)](https://scrutinizer-ci.com/g/fabiang/xmpp/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74/mini.png)](https://insight.sensiolabs.com/projects/a535cd82-788d-4506-803e-02ede44a9e74)
## SYSTEM REQUIREMENTS
- PHP minimum 5.6 or minimum 7.0
- psr/log
- (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:
```bash
composer require fabiang/xmpp
```
## DOCUMENTATION
This library uses an object to hold options:
```php
use Fabiang\Xmpp\Options;
$options = new Options($address);
$options->setUsername($username)
->setPassword($password);
```
The server address must be in the format `tcp://myjabber.com:5222`.
If the server supports TLS the connection will automatically be encrypted.
You can also pass a PSR-2-compatible object to the options object:
```php
$options->setLogger($logger)
```
The client manages the connection to the Jabber server and requires the options object:
```php
use Fabiang\Xmpp\Client;
$client = new Client($options);
// optional connect manually
$client->connect();
```
For sending data you just need to pass a object that implements `Fabiang\Xmpp\Protocol\ProtocolImplementationInterface`:
```php
use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;
// fetch roster list; users and their groups
$client->send(new Roster);
// set status to online
$client->send(new Presence);
// send a message to another user
$message = new Message;
$message->setMessage('test')
->setTo('nickname@myjabber.com')
$client->send($message);
// join a channel
$channel = new Presence;
$channel->setTo('channelname@conference.myjabber.com')
->setPassword('channelpassword')
->setNickName('mynick');
$client->send($channel);
// send a message to the above channel
$message = new Message;
$message->setMessage('test')
->setTo('channelname@conference.myjabber.com')
->setType(Message::TYPE_GROUPCHAT);
$client->send($message);
```
After all you should disconnect:
```php
$client->disconnect();
```
## DEVELOPING
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
After that:
./vendor/bin/phpunit
./vendor/bin/behat
New features should always tested with Behat.
## LICENSE
BSD-2-Clause. See the [LICENSE](LICENSE.md).
## TODO
- Better integration of channels
- Factory method for server addresses
- improve documentation
PK IeśNhfK·B B src/Connection/Socket.phpnu W+A¶
* @copyright 2014 Fabian Grutschus. All rights reserved.
* @license BSD
* @link http://github.com/fabiang/xmpp
*/
namespace Fabiang\Xmpp\Connection;
use Psr\Log\LogLevel;
use Fabiang\Xmpp\Stream\SocketClient;
use Fabiang\Xmpp\Util\XML;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Exception\TimeoutException;
/**
* Connection to a socket stream.
*
* @package Xmpp\Connection
*/
class Socket extends AbstractConnection implements SocketConnectionInterface
{
const DEFAULT_LENGTH = 4096;
const STREAM_START = <<<'XML'