laupifrpar/pusher-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laupifrpar/pusher-bundle

Composer 安装命令:

composer require laupifrpar/pusher-bundle

包简介

A Pusher bundle for Symfony2

README 文档

README

Bundle CI

This bundle let you use Pusher simply.

Pusher (Documentation) is a simple hosted API for adding realtime bi-directional functionality via WebSockets to web and mobile apps, or any other Internet connected device. It's super powerful, and a ton of fun!

This bundle is under the MIT license.

Installation

Use composer to install this bundle.

composer require laupifrpar/pusher-bundle

If you're not using Symfony Flex, then you will also need to enable Lopi\Bundle\PusherBundle\LopiPusherBundle in your config/bundles.php file.

<?php

return [
    // ...
    Lopi\Bundle\PusherBundle\LopiPusherBundle::class => ['all' => true],
    // ...
];

Configuration

If you do not have a Pusher account, sign up and make a note of your API key before continuing.

General

To start, you'll need to setup a bit of configuration.

This is the default configuration in yml:

# app/config/config.yml
lopi_pusher:
    # Default configuration
    scheme: http
    host: api.pusherapp.com
    port: 80
    cluster: us-east-1 # Change the cluster name
    timeout: 30
    debug: false # true if you want use the debug of all requests

You must set the url parameter :

# app/config/config.yml
lopi_pusher:
    url: <scheme>://<key>:<secret>@<host>[:<port>]/apps/<app-id>

It will parse the URL and set, or replace the default value if exists, the various parameters scheme, key, secret, host, port and app_id

Or you can set the various parameters separately:

# app/config/config.yml
lopi_pusher:
    app_id: <app-id>
    key: <key>
    secret: <secret>

By default, calls will be made over a non-encrypted connection. To change this to make calls over HTTPS, simply:

# app/config/config.yml
lopi_pusher:
    # ...
    scheme: https
    port: 443

If you want to use private or presence channels, set the parameter auth_service_id

# app/config/config.yml
lopi_pusher:
    # ...
    auth_service_id: <the_auth_service_id>

See the section about "Private and Presense channel auth" below

Usage!

Once you've configured the bundle, you will have access to a pusher service, which can be autowired by Pusher\Pusher typehint. From inside a controller, you can use it like this:

use Pusher\Pusher;

class SampleController
{
    public function triggerPusherAction(Pusher $pusher)
    {
        // ...

        $data['message'] = 'hello world';
        $pusher->trigger('test_channel', 'my_event', $data);

        // ...
    }
}

This code will autowire \Pusher\Pusher class from the official Pusher SDK. You can find out all about it on pusher's documentation.

Private and Presence channel authentication (optional)

If you'd like to use private or presence, you need to add an authorization service.

First, create an authorization service that implements Lopi\Bundle\PusherBundle\Authenticator\ChannelAuthenticatorInterface:

<?php
// src/Pusher/ChannelAuthenticator.php

namespace App\Pusher;

use Lopi\Bundle\PusherBundle\Authenticator\ChannelAuthenticatorInterface;

class ChannelAuthenticator implements ChannelAuthenticatorInterface
{
    public function authenticate($socketId, $channelName)
    {
        // logic here

        return true;
    }
}

Next, register it as service like normal:

# config/services.yml
services:
    my_channel_authenticator: AppBundle\Pusher\ChannelAuthenticator

Then include its service id in the lopi_pusher auth_service_id configuration parameter:

# config/packagers/lopi_pusher.yml
lopi_pusher:
    # ...

    auth_service_id: 'my_channel_authenticator'

Additionally, enable the route by adding the following to your config\routing.yml configuration:

# config\routing.yml
lopi_pusher:
    resource: "@LopiPusherBundle/Resources/config/routing.xml"
    prefix:   /pusher

In some Symfony configurations, you may need to manually specify the channel_auth_endpoint: (not required in most setups):

{# app/Resources/views/base.html.twig #}

<script type="text/javascript">
    Pusher.channel_auth_endpoint = "{{ path('lopi_pusher_bundle_auth') }}";
</script>

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

When reporting a bug, it may be a good idea to reproduce it in a basic project built using the Symfony Standard Edition to allow developers of the bundle to reproduce the issue by simply cloning it and following some steps.

laupifrpar/pusher-bundle 适用场景与选型建议

laupifrpar/pusher-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.48M 次下载、GitHub Stars 达 65, 最近一次更新时间为 2012 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nosql」 「symfony」 「pusher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 laupifrpar/pusher-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laupifrpar/pusher-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 laupifrpar/pusher-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.48M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 65
  • 点击次数: 21
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 65
  • Watchers: 2
  • Forks: 35
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-09-18