初始化代码

This commit is contained in:
2025-12-22 14:34:25 +08:00
parent c2c5ae2fdd
commit a77dbc743f
1510 changed files with 213008 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace think\swoole\contract;
use think\Container;
use think\swoole\Sandbox;
interface ResetterInterface
{
/**
* "handle" function for resetting app.
*
* @param Container $app
* @param Sandbox $sandbox
*/
public function handle(Container $app, Sandbox $sandbox);
}

View File

@@ -0,0 +1,39 @@
<?php
namespace think\swoole\contract\rpc;
use think\swoole\rpc\Protocol;
interface ParserInterface
{
const EOF = "\r\n\r\n";
/**
* @param Protocol $protocol
*
* @return string
*/
public function encode(Protocol $protocol): string;
/**
* @param string $string
*
* @return Protocol
*/
public function decode(string $string): Protocol;
/**
* @param string $string
*
* @return mixed
*/
public function decodeResponse(string $string);
/**
* @param mixed $result
*
* @return string
*/
public function encodeResponse($result): string;
}

View File

@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\swoole\contract\websocket;
use Swoole\Websocket\Frame;
use think\Request;
interface HandlerInterface
{
/**
* "onOpen" listener.
*
* @param int $fd
* @param Request $request
*/
public function onOpen($fd, Request $request);
/**
* "onMessage" listener.
* only triggered when event handler not found
*
* @param Frame $frame
*/
public function onMessage(Frame $frame);
/**
* "onClose" listener.
*
* @param int $fd
* @param int $reactorId
*/
public function onClose($fd, $reactorId);
}

View File

@@ -0,0 +1,29 @@
<?php
namespace think\swoole\contract\websocket;
use Swoole\WebSocket\Frame;
interface ParserInterface
{
/**
* Encode output payload for websocket push.
*
* @param string $event
* @param mixed $data
*
* @return mixed
*/
public function encode(string $event, $data);
/**
* Input message on websocket connected.
* Define and return event name and payload data here.
*
* @param Frame $frame
*
* @return array
*/
public function decode($frame);
}

View File

@@ -0,0 +1,61 @@
<?php
namespace think\swoole\contract\websocket;
interface RoomInterface
{
/**
* Rooms key
*
* @const string
*/
public const ROOMS_KEY = 'rooms';
/**
* Descriptors key
*
* @const string
*/
public const DESCRIPTORS_KEY = 'fds';
/**
* Do some init stuffs before workers started.
*
* @return RoomInterface
*/
public function prepare(): RoomInterface;
/**
* Add multiple socket fds to a room.
*
* @param int fd
* @param array|string rooms
*/
public function add(int $fd, $rooms);
/**
* Delete multiple socket fds from a room.
*
* @param int fd
* @param array|string rooms
*/
public function delete(int $fd, $rooms);
/**
* Get all sockets by a room key.
*
* @param string room
*
* @return array
*/
public function getClients(string $room);
/**
* Get all rooms by a fd.
*
* @param int fd
*
* @return array
*/
public function getRooms(int $fd);
}