lsv/pusher-bundle

Symfony bundle for pusher.com

Installs: 133

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 1

Open Issues: 0

Type:bundle

v0.1.0 2016-10-28 20:49 UTC

This package is auto-updated.

Last update: 2024-11-27 22:11:41 UTC


README

Pusher.com bundle for symfony

Install

composer require lsv/pusher-bundle

Add the bundle to your AppKernel

# app/AppKernel.php
public function registerBundles()
{
    $bundles = [
        new Lsv\PusherBundle\LsvPusherBundle(),
    ];
}

Add the needed configuration

lsv_pusher:
    app_id: <Your app key>
    key: <Your app id>
    secret: <Your app secret>

There is more configuration availible

Usage

Controller example

In your controller you can use

$this->get('lsv_pusher.pusher')->trigger('channel', 'event-name', $data);

This will be a Lsv\PusherBundle\Service\PusherService object, which extends \Pusher from pusher/pusher-php-server

Why I extend the original, is because it is not possible to add middlewares to the original, so I added them in my own

As my service extends the original, you can use all the same methods as in https://github.com/pusher/pusher-http-php

Your service

In your service you can add this to your arguments

services:
    your-service:
         class: YourClass
         arguments: ["@lsv_pusher.pusher"]

And in your YourClass

use Lsv\PusherBundle\Service\PusherService

class YourClass
{
    public function __construct(PusherService $pusher)
    {
    }
}

Configuration

Even if debug is false, all events will be send, and info will be send to symfony profiler

Full configuration example

lsv_pusher:
    app_id: 123
    key: 123
    secret: 123
    timeout: 20
    encrypted: true
    cluster: eu
    curl_options:
        - CURLOPT_IPRESOLVE: CURL_IPRESOLVE_V4
    debug: true

curl_options Info

If you a add the constant to curl_options like this

lsv_pusher:
    curl_options:
        - CURLOPT_IPRESOLVE: CURL_IPRESOLVE_V4
        - CURLOPT_SSL_VERIFYSTATUS: false

The constant will be translated to the corresponded integer

Symfony 3.2+

In symfony 3.2+, you can do this

lsv_pusher:
    curl_options:
        - !php/const:CURLOPT_IPRESOLVE: !php/const:CURL_IPRESOLVE_V4
        - !php/const:CURLOPT_SSL_VERIFYSTATUS: false

Events

All event classes are in the namespace of Lsv\PusherBundle\Event

In all event classes you can use the NAME constant to get the dispatched event name, fx Lsv\PusherBundle\Event\TriggerBatchEvent::NAME

Symfony profiler

All response requests will be shown in the profiler, just like this

Symfony profiler example

Command

One command is provided to test a pusher.cosend the test to trigger

lsv:pusher:test

Optional options can also be added

License

The MIT License (MIT)

Copyright (c) 2016 Martin Aarhof

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.