此包最新版本(dev-master)的许可证信息不可用。

dev-master 2014-04-10 01:26 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:26:34 UTC


README

此包旨在解决大多数Web应用的一个共同部分:用户消息。此包附带一个可扩展的数据库结构,允许您使用该包解决诸如用户之间的私密消息或所有用户可以书写想法的地方等问题。

关于

此包旨在作为应用中即时消息聊天(通过WebSockets传输)的消息存储解决方案使用。在某些时刻,WebSocket服务器将使用此包保存会话。

安装

目前在此文档中仅提供Laravel 4框架的安装指南。

  • 运行数据库迁移

php artisan migrate --bench=softservlet/forum

  • 在您的app/config/app.php中添加包服务提供者

Softservlet\Forum\Providers\ForumServiceProvider

  • 在您的应用程序中实现ActorInterface。

此包背后的基本思想是在实体之间发送消息。我们称此实体为Actor。为了使用此包,您必须在您的应用程序中定义谁是actor。

actor通常发送消息。

在您的模型中某个地方,您应该实现来自Softservlet\Forum\Actor\ActorInterface的ActorInterface。一个示例代码可能是

<?php

use Softservlet\Forum\Actor\ActorInterface;

class User implements ActorInterface
{

	private $userId;

	public function __construct($userId)
	{
		$this->userId = $userId;
	}

	public function getId()
	{
		return $this->userId;
	}

	//more about your user 
}

一旦您实现了ActorInterface,将其绑定到您的应用程序服务提供者。在您的应用程序服务提供者中写入:App::bind('Softservlet\Forum\Actor\ActorInterface', 'Your\Namespace\To\User');

  • 实现ActorRepositoryInterface 包需要获取实现ActorInterface的您的对象实例,以便能够发送消息。

您需要实现:Softservlet\Forum\Repositories\ActorRepositoryInterface

此接口包含一个find($id)方法,它应该返回一个ActorInterface实例。在这里,您应该从数据库中检索您的用户或从您存储它的地方检索。

此实现的示例代码可能是

<?php

use Softservlet\Forum\Repositories\ActorRepositoryInterface;

class UserRepository implements ActorRepositoryInterface
{
	public find($id)
	{
		//get details about your user and create
		//a instance of it
		return new User($id, $params);
	}
}

然后注册从此类到Softservlet\Forum\Repositories\ActorRepositoryInterface的绑定;

有关Laravel绑定的更多信息,请参阅Laravel文档。

工作原理

工作流程相当简单

  • 一个actor向一个Thread发送消息
  • 所有撰写或订阅该thread的actor都可以获取消息。

使用方法

创建消息和threads

  • 当您想使用此包发送消息时,首先要定义谁会发送它。如上所述,您需要实现ActorRepositoryInterface。创建一个ActorInterface的实例
   //this object will implements ActorRepositoryInterface
   $actorRepository = new ActorRepository(); 	

   //let's say that we want to send a message from a user with id equals with 1
   $actor = $actorRepository->find(1); 
  • 创建一个消息将要发送的thread(如果不存在)。
   $threadRepository = new Softservlet\Forum\Repositories\ThreadRepository();
   //create a instance of a thread with id equals with 10
   $thread = $threadRepository->find(10);
  • 创建一个新的消息。消息创建是通过在Repositories\MessageRepository类中定义的MessageRepository对象完成的。创建此对象的实例并调用带有以下参数的create()方法
  • ThreadInterface $thread
  • ActorInterface $actor
  • string $text
  • int $timestamp
   $messageRepository = new Softservlet\Forum\Repositories\MessageRepository();
   $message = $messageRepository->create($thread, $actor, "my message", time());

获取消息和threads

待办事项

使用除字符串之外的其他数据发送消息

待办事项