承接 gfs/notifications 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

gfs/notifications

Composer 安装命令:

composer require gfs/notifications

包简介

Symfony GFSNotificationsBundle

README 文档

README

Install via composer

composer require gfs/notifications ~v1.0

Add to AppKernel.php

new GFS\NotificationBundle\NotificationBundle(),

2. Create Notification

use GFS\NotificationBundle\Entity\Notification as Base;
class Notifications extends Base
{
    /**
    * @var int
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $id;

  /**
   * @var User
   *
   * @ORM\ManyToOne(targetEntity="User",inversedBy="notifications")
   * @ORM\JoinColumn(name="user_id", onDelete="cascade")
   */
  private $user;

  /**
   * @param UserInterface $user
   *
   * @return $this
   */
  public function setUser(UserInterface $user)
  {
      $this->user = $user;

      return $this;
  }

  /**
   * @return User
   */
  public function getUser()
  {
      return $this->user;
  }

  /**
   * Get id
   *
   * @return int
   */
  public function getId()
  {
      return $this->id;
  }

  /**
   * This is important because the server will send your JSON notifications ( json_encode(your notification) ).
   * You can customize what field you want the server to send to your client.
   */
  public function jsonSerialize()
  {
      return [
          'type' => $this->getType(),
          'description' => $this->getDescription(),
          'checked' => $this->getChecked(),
          'checkedAt' => $this->getCheckedAt(),
          'createdAt' => $this->getCreateAt(),
          'url' => $this->url,
          'id' => $this->id,
          'userId' => $this->user->getUsername() //This helps the server identify if a specific user is connected and only send notifications to that user. You can use another field for common notifications, for example group notifications.
      ];
  }
}

Function jsonSerialize should return an array that must contain the field 'userId', the server checks all connections if they contain this value.

3. Start server

Symfony 2 php app/console server:notification

Symfony 3 php bin/console server:notification

4. Client job

Use any WebSocket you want or any technologies. The most important thing is the URL, it must have GET parameter userId. That parameter will be bind to current connection. This userId is used when you create a notification, the parameter userId comes from function jsonSerialize. The GET parameter userId should be identical with the one returned by the function jsonSerialize, so the user receives the notification.

var conn = new WebSocket('ws://yourip:8080?userId='+$scope.username);
conn.onopen = function(e) {
    console.log("Connection established!");
};

conn.onmessage = function(e) {
    var noitification = JSON.parse(e.data);
    // handle your notification object here
};

5. Create a notification

Create an entity: Notification. After successfully inserting it in the database, a notification will be sent to the server and the server will find the connection that matches userId field from jsonSerialize.

 $notification = new Notifications();
 $notification->setType('type')
     ->setDescription('Your Notification here')
     ->setUser($user)
 ;
 $this->get('doctrine.orm.default_entity_manager')->persist($notification);
 $this->get('doctrine.orm.default_entity_manager')->flush();

Configuration

#config.yml
gfs_notifications:
    host: localhost # ip or DNS where server run default is localhost
    port: 8080 # port when server want run default is 8080
    notification: GFS\NotificationBundle\Notification\Notification # you can implement your own Ratchet\MessageComponentInterface

Default Entity field:

  • id
  • type ( string, 255 )
  • description ( text )
  • created_at ( DateTime )
  • checked_at ( DateTime, default null )
  • checked ( boolean )
  • user ( instance of Symfony\Component\Security\Core\User\UserInterface )

Remeber if you want rewrite __contruct don't forget to write:

$this->created_at = new \DateTime('now').

gfs/notifications 适用场景与选型建议

gfs/notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 598 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 gfs/notifications 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 598
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-21