40 lines
1.1 KiB
PHP
Executable File
40 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Mercure\HubInterface;
|
|
use Symfony\Component\Mercure\Update;
|
|
|
|
class PublishController extends AbstractController
|
|
{
|
|
public function sample($id)
|
|
{
|
|
return $this->render('Home/publishsample.html.twig', [
|
|
'id' => $id,
|
|
]);
|
|
}
|
|
|
|
public function publish($channel, $id, Request $request, HubInterface $hub): Response
|
|
{
|
|
$ret = $request->get('msg');
|
|
$ret['from'] = [];
|
|
$ret['from']['id'] = $this->getUser()->getId();
|
|
$ret['from']['username'] = $this->getUser()->getUsername();
|
|
$ret['from']['displayname'] = $this->getUser()->getDisplayname();
|
|
$ret['from']['avatar'] = $this->generateUrl('app_minio_image', ['file' => 'avatar/'.$this->getUser()->getAvatar()]);
|
|
|
|
$update = new Update(
|
|
$channel.'-'.$id,
|
|
json_encode(
|
|
['ret' => $ret])
|
|
);
|
|
|
|
$hub->publish($update);
|
|
|
|
return new Response('published!');
|
|
}
|
|
}
|