Skip to content

Commit

Permalink
Prepare version 1.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaillard committed Aug 18, 2016
1 parent 1ed91e1 commit 73d293e
Show file tree
Hide file tree
Showing 14 changed files with 417 additions and 69 deletions.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Code Climate](https://img.shields.io/codeclimate/github/gomoob/php-websocket-server.svg?style=flat)](https://codeclimate.com/github/gomoob/php-websocket-server)
[![License](https://img.shields.io/packagist/l/gomoob/php-websocket-server.svg?style=flat)](https://packagist.org/packages/gomoob/php-websocket-server)

# Introduction
## Introduction

The Gomoob WebSocket server is a simple [Ratchet](http://socketo.me "Ratchet") server which works with custom tags
to easily forward messages to clients depending on custom tags.
Expand Down Expand Up @@ -41,9 +41,9 @@ $phpClient = new WebSocketClient('ws://localhost:8080');
$phpClient->send(WebSocketRequest::create($message, ['language' => 'FR']);
```

# Installation
## Installation

## Server side (run the server)
### Server side (run the server)

Running a server requires only one line of code.

Expand All @@ -54,7 +54,7 @@ echo "WebSocket server started, enter Ctrl+C to stop server." . PHP_EOL;
\Gomoob\WebSocket\Server\WebSocketServer::factory()->run();
```

## Client side (PHP)
### Client side (PHP)

First pull the project with composer using the following dependency.

Expand Down Expand Up @@ -84,7 +84,7 @@ $response = $phpClient->send(
);
```

# Advanced configuration
## Advanced configuration

The default behavior of the Gomoob WebSocket server is the following !

Expand All @@ -95,7 +95,7 @@ The default behavior of the Gomoob WebSocket server is the following !

If one of those behaviors does not fit your need please read the following sub sections. You can also read the `src/test/server.php` file which shows how to start a server with custom message parsing and authorizations.

## Message parser
### Message parser

By default the WebSocket server will accept plain string messages, if you try to send a JSON object then you'll
encounter the following exception.
Expand Down Expand Up @@ -203,7 +203,7 @@ WebSocketServer::factory(
)->run();
```

## Authorization Manager
### Authorization Manager

By default the WebSocket server will accept all connections and message sendings, in most cases this behavior is not
expected because anybody could open a WebSocket on your server and try to forward messages to all connected clients
Expand Down Expand Up @@ -243,7 +243,7 @@ interface IAuthManager
So its very easy to manage authorizations, just return `true` or `false` with the `authorizeOpen(...)` or
`authorizeSend(...)` functions.

### The `ApplicationsAuthManager`
#### The `ApplicationsAuthManager`

To easier authorization we provide an authorization manager which allows to declare several applications with `key`
and `secret` properties.
Expand Down Expand Up @@ -330,22 +330,49 @@ WebSocketClient::factory('ws://localhost:8080')->send(
);
```

# Release history
## Docker container

## 1.0.3 (2016-08-17)
To help you start quickly we also provide a Docker container here https://hub.docker.com/r/gomoob/php-websocket-server.

## Release history

### 1.1.0 (2016-08-18)
* Add more PHP Documentor documentation about the goals of `metadata` in
the `\Gomoob\WebSocket\IWebSocketRequest` interface and the
`\Gomoob\WebSocket\Request\WebSocketRequest` class ;
* Add management of `defaultMetadata` in the `\Gomoob\WebSoscket\IWebSocketClient` interface and the
`\Gomoob\WebSocket\Client\WebSocketClient` class ;
* Add management of `defaultTags` in the `\Gomoob\WebSocket\IWebSocketClient` interface and the
`\Gomoob\WebSocket\Client\WebSocketClient` class ;
* Improve `\Gomoob\WebSocket\Message\Message` serialization ;
* Improve `\Gomoob\WebSocket\Request\WebSocketRequest` serialization ;
* Now all the factory methods can be calls with a `factory(...)` method or an alias `create(...)` method.

### 1.0.3 (2016-08-17)
* Fix `port` and `address` options problems while creating a `WebSocketServer`, the parameter were not
transmitted to the Ratchet server ;
* Now the default port number is `80` which is the default Ratchet server port.

## 1.0.2 (2016-08-17)
### 1.0.2 (2016-08-17)
* Add missing `symfony/yaml` composer dependency, otherwise problems was encountered while running
`composer update --no-dev` ;
* Add missing `monolog/monolog` composer dependency, , otherwise problems was encountered while running
`composer update --no-dev`.

## 1.0.1 (2016-08-17)
### 1.0.1 (2016-08-17)
* Configure specific Eclipse validator rules ;
* Add MIT license.

## 1.0.0 (2016-08-17)
### 1.0.0 (2016-08-17)
* First release.

## About Gomoob

At [Gomoob](https://www.gomoob.com) we build high quality software with awesome Open Source frameworks everyday. Would
you like to start your next project with us? That's great! Give us a call or send us an email and we will get back to
you as soon as possible !

You can contact us by email at [contact@gomoob.com](mailto:contact@gomoob.com) or by phone number
[(+33) 6 85 12 81 26](tel:+33685128126) or [(+33) 6 28 35 04 49](tel:+33685128126).

Visit also http://gomoob.github.io to discover more Open Source softwares we develop.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "gomoob/php-websocket-server",
"version" : "1.0.3",
"version" : "1.1.0",
"license" : "MIT",
"minimum-stability" : "stable",
"prefer-stable" : true,
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fatcap-web-sockets",
"version": "1.0.3",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "git://bitbucket.org/gomoob/fatcap-web-sockets.git"
Expand Down
17 changes: 17 additions & 0 deletions src/main/php/Gomoob/WebSocket/Auth/ApplicationsAuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class ApplicationsAuthManager implements IAuthManager
*/
protected $keyMap = [];

/**
* Creates a new instance of the applications authorization manager.
*
* **NOTE** This function is an alias of the `factory(array $options)` function.
*
* @param array $options Options used to configure the component, the following options are available :
* * `configurationFile` an absolute path to a YAML configuration file which declares the applications ;
* * `authorizeOpen` a boolean used to indicate if connection opening is authorized by default (default is `true`)
* ;
*
* @throws \InvalidArgumentException if the provided configuration file cannot be read or has an invalid format.
*/
public static function create(array $options = [])
{
return static::factory($options);
}

/**
* Creates a new instance of the applications authorization manager.
*
Expand Down
80 changes: 79 additions & 1 deletion src/main/php/Gomoob/WebSocket/Client/WebSocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ class WebSocketClient implements IWebSocketClient
*/
protected $client;

/**
* Default metadata to set on all requests sent with the client, those metadata will be merged with the
* metadata specified on the requests.
*
* **WARNING** If a metadata property specifically defined on a request has the same name as a default metadata
* property defined on the WebSocket client then the metadata property defined with the request
* overwrites the default metadata property.
*
* @var array
*/
protected $defaultMetadata = [];

/**
* Default tags to set on all requests sent with the client, those tags will be merged with the tags specified on
* the requests.
*
* **WARNING** If a tag property specifically defined on a request has the same name as a default tag
* property defined on the WebSocket client then the tag property defined with the request
* overwrites the default tag property.
* @var array
*/
protected $defaultTags = [];

/**
* Creates a new instance of the Gomoob Web Socket client.
*
Expand All @@ -36,7 +59,23 @@ public function __construct($uri)
{
$this->client = new Client($uri);
}

/**
* {@inheritDoc}
*/
public function getDefaultMetadata()
{
return $this->defaultMetadata;
}

/**
* {@inheritDoc}
*/
public function getDefaultTags()
{
return $this->defaultTags;
}

/**
* {@inheritdoc}
*/
Expand All @@ -46,8 +85,47 @@ public function send(IWebSocketRequest $webSocketRequest)
if (!$webSocketRequest->getMessage()) {
throw new \InvalidArgumentException('The provided Web Socket request must have a message !');
}

// Create a cloned WebSocket request to update it before sending it
$clonedWebSocketRequest = clone $webSocketRequest;

// Merge default metadata
$clonedWebSocketRequest->setMetadata(
array_merge(
$this->defaultMetadata,
$webSocketRequest->getMetadata()
)
);

// Merge default tags
$clonedWebSocketRequest->setTags(
array_merge(
$this->defaultTags,
$webSocketRequest->getTags()
)
);

// Sends the request
$this->client->send(json_encode($webSocketRequest));
$this->client->send(json_encode($clonedWebSocketRequest));
}

/**
* {@inheritDoc}
*/
public function setDefaultMetadata(array $defaultMetadata = [])
{
$this->defaultMetadata = $defaultMetadata;

return $this;
}

/**
* {@inheritDoc}
*/
public function setDefaultTags(array $defaultTags = [])
{
$this->defaultTags = $defaultTags;

return $this;
}
}
52 changes: 52 additions & 0 deletions src/main/php/Gomoob/WebSocket/IWebSocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
*/
interface IWebSocketClient
{
/**
* Gets the default metadata to set on all requests sent with the client, those metadata will be merged with the
* metadata specified on the requests.
*
* **WARNING** If a metadata property specifically defined on a request has the same name as a default metadata
* property defined on the WebSocket client then the metadata property defined with the request
* overwrites the default metadata property.
*
* @return array the default metadata to sent on all requests sent with the client.
*/
public function getDefaultMetadata();

/**
* Gets the default tags to set on all requests sent with the client, those tags will be merged with the
* tags specified on the requests.
*
* **WARNING** If a tag property specifically defined on a request has the same name as a default tag
* property defined on the WebSocket client then the tag property defined with the request
* overwrites the default tag property.
*
* @return array the default tags to sent on all requests sent with the client.
*/
public function getDefaultTags();

/**
* Sends a Web Socket request to the Gomoob Web Socket server.
*
Expand All @@ -23,4 +47,32 @@ interface IWebSocketClient
* @return \Gomoob\WebSocket\IWebSocketResponse the resulting Web Socket response.
*/
public function send(IWebSocketRequest $webSocketRequest);

/**
* Sets default metadata to set on all requests sent with the client, those metadata will be merged with the
* metadata specified on the requests.
*
* **WARNING** If a metadata property specifically defined on a request has the same name as a default metadata
* property defined on the WebSocket client then the metadata property defined with the request
* overwrites the default metadata property.
*
* @param array $defaultMetadata default metadata to sent on all requests sent with the client.
*
* @return \Gomoob\WebSocket\IWebSocketClient this instance.
*/
public function setDefaultMetadata(array $defaultMetadata = []);

/**
* Sets the default tags to set on all requests sent with the client, those tags will be merged with the
* tags specified on the requests.
*
* **WARNING** If a tag property specifically defined on a request has the same name as a default tag
* property defined on the WebSocket client then the tag property defined with the request
* overwrites the default tag property.
*
* @param array $defaultTags the default tags to sent on all requests sent with the client.
*
* @return \Gomoob\WebSocket\IWebSocketClient this instance.
*/
public function setDefaultTags(array $defaultTags = []);
}
Loading

0 comments on commit 73d293e

Please sign in to comment.