<commit_before># CrossbarHTTPPublisherBundle

[![Stable release][Last stable image]][Packagist link]
[![Unstable release][Last unstable image]][Packagist link]
[![Build status][Master build image]][Master build link]

[![Coverage Status][Master coverage image]][Master coverage link]
[![Scrutinizer][Master scrutinizer image]][Master scrutinizer link]
[![SL Insight][SL Insight image]][SL Insight link]

This bundle allows to submit PubSub events via HTTP/POST requests to a [Crossbar HTTP Publisher](http://crossbar.io/docs/HTTP-Bridge-Services-Publisher/).

####Supports:

* Multiple publisher, automatically registered into Service Container
* [Signed requests](http://crossbar.io/docs/HTTP-Bridge-Services-Publisher/#signed-requests)
* SSL certificate verification skip (useful in dev enviroment)

####Requires:

* php: >=5.4
* symfony/http-kernel: >=2.3
* symfony/framework-bundle: >=2.3
* symfony/dependency-injection: >=2.3
* symfony/config: >=2.3
* symfony/yaml: >=2.3
* guzzlehttp/guzzle": >=5.0,<6.0

####Installation

As simple as download it 

```console
$ composer require facile-it/crossbar-http-publisher-bundle dev-master
```

and register the bundle in your app (usually in app/AppKernel.php)
````php
public function registerBundles()
{
    return array(
        // ...
        new Facile\CrossbarHTTPPublisherBundle\FacileCrossbarHTTPPublisherBundle(),
    );
}
````
####Configuration

Quite easy, just add something like this in your config.yml:

````yaml
facile_crossbar_http_publisher:
    connections:
        dummy_publisher_1:
            protocol: https                     #default: http
            host: crossbar.io                   #default: 127.0.0.1 
            port: 443                           #default: 8080
            path: publish                       #default: publish, often just empty
            auth_key: this_is_very_key          #default: null
            auth_secret: this_is_very_secret    #default: null
            ssl_ignore: true                    #default: false
        dummy_publisher_2:
            host: crossbar.tu
````

and you'll can get the publisher services from the container:

````php
$firstPublisher = $container->get('facile.crossbar.publisher.dummy_publisher_1');
$secondPublisher = $container->get('facile.crossbar.publisher.dummy_publisher_2');

$topic = 'com.myapp.topic1';

// using args
$firstPublisher->publish($topic, ['foo',1]);

// using kwargs
$secondPublisher->publish($topic, null, ['key'=>'value']);

// using both and printing Crossbar's response already decoded:
print_r($firstPublisher->publish($topic, ['foo',1], ['key'=>'value']));

// ouptuts:
//
// array(1) {
//   ["id"]=>
//   int(1395572605)
// }

````<commit_msg>Updating readme<commit_after># CrossbarHTTPPublisherBundle

[![Stable release][Last stable image]][Packagist link]
[![Unstable release][Last unstable image]][Packagist link]
[![Build status][Master build image]][Master build link]

[![Coverage Status][Master coverage image]][Master coverage link]
[![Scrutinizer][Master scrutinizer image]][Master scrutinizer link]
[![SL Insight][SL Insight image]][SL Insight link]

This bundle allows to submit PubSub events via HTTP/POST requests to a [Crossbar HTTP Publisher](http://crossbar.io/docs/HTTP-Bridge-Services-Publisher/), which is a simple, lightweight websocket server implemented in Python.

## Features

* Define multiple publishers
* Publishers are automatically registered into Syomfony's service container
* Send [signed requests](http://crossbar.io/docs/HTTP-Bridge-Services-Publisher/#signed-requests) easily
* Skip SSL certificate verification (useful in dev environment)

## Requirements
* PHP >=5.6
* Guzzle 5 or 6
* The following Symfony components (or the full-stack framework), version 2.7, 2.8 or 3.x:
    * symfony/framework-bundle
    * symfony/dependency-injection
    * symfony/config

## Installation

Require this package with Composer: 

```console
$ composer require facile-it/crossbar-http-publisher-bundle
```

... and register the bundle in your app (usually in `app/AppKernel.php`)

```php
public function registerBundles()
{
    return array(
        // ...
        new Facile\CrossbarHTTPPublisherBundle\FacileCrossbarHTTPPublisherBundle(),
    );
}
````

#### Configuration
You just need to configure the publishers that you need to use; here is an example of the config, with the default values:

```yaml
facile_crossbar_http_publisher:
  connections:
    dummy_publisher_1:
      protocol: https                     #default: http
      host: crossbar.io                   #default: 127.0.0.1 
      port: 443                           #default: 8080
      path: publish                       #default: publish, often just empty
      auth_key: this_is_very_key          #default: null
      auth_secret: this_is_very_secret    #default: null
      ssl_ignore: true                    #default: false
  dummy_publisher_2:
      host: crossbar.tu
```

#### Usage

Once you've done that, the publishers will be available as Symfony services in your container:

```php
$firstPublisher = $container->get('facile.crossbar.publisher.dummy_publisher_1');
$secondPublisher = $container->get('facile.crossbar.publisher.dummy_publisher_2');

$topic = 'com.myapp.topic1';

// using args
$firstPublisher->publish($topic, ['foo',1]);

// using kwargs
$secondPublisher->publish($topic, null, ['key'=>'value']);

// using both and printing Crossbar's response already decoded:
print_r($firstPublisher->publish($topic, ['foo',1], ['key'=>'value']));

// ouptuts:
//
// array(1) {
//   ["id"]=>
//   int(1395572605)
// }
```
{'fraction_non_alphanumeric': 0.13020182175388462, 'fraction_numerical': 0.015538489015895695, 'mean_word_length': 3.612850082372323, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3966209', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1632, 'n_words': 447}