1. Go to this page and download the library: Download olexin-pro/cenrtifuge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
olexin-pro / cenrtifuge example snippets
use Illuminate\Contracts\Auth\Authenticatable;
use OlexinPro\Centrifuge\Routing\ChannelRouter;
/** @var ChannelRouter $centrifuge */
// Private channel with a parameter
$centrifuge->channel('private-user.{userId}', function (?Authenticatable $user, string $userId) {
return $user && (int) $user->getAuthIdentifier() === (int) $userId;
});
// Public channel
$centrifuge->channel('public.chat', function () {
return true;
});
use OlexinPro\Centrifuge\Routing\RpcRouter;
/** @var RpcRouter $rpc */
// Global middleware
$rpc->middleware([\App\Centrifuge\Middleware\LogRpcRequest::class]);
// Single method
$rpc->register('ping', \App\Centrifuge\Handlers\PingHandler::class);
// Grouped methods with middleware
$rpc->group('', [\App\Centrifuge\Middleware\RequireAuth::class], function (RpcRouter $rpc) {
$rpc->group('posts', [], function (RpcRouter $rpc) {
$rpc->register('create', \App\Centrifuge\Handlers\CreatePostHandler::class);
});
});
use Illuminate\Contracts\Auth\Authenticatable;
use OlexinPro\Centrifuge\Contracts\RpcHandlerContract;
use RoadRunner\Centrifugo\Request\RPC;
class PingHandler implements RpcHandlerContract
{
public function handle(array $data, ?Authenticatable $user, RPC $request): mixed
{
return ['pong' => true];
}
}