bigoen/mercure-twig-bundle
Composer 安装命令:
composer require bigoen/mercure-twig-bundle
包简介
Mercure twig bundle.
README 文档
README
Developed based on https://github.com/sroze/live-twig package.
Install:
composer require bigoen/mercure-twig-bundle
If you don't use Symfony Flex:
.env.local
###> bigoen/mercure-twig-bundle ### MERCURE_TWIG_PUBLISH_URL=http://mercure/.well-known/mercure ###< bigoen/mercure-twig-bundle ###
config/bundles.php
return [ // ... Bigoen\MercureTwigBundle\BigoenMercureTwigBundle::class => ['all' => true], ];
config/packages/bigoen_mercure_twig.yaml
bigoen_mercure_twig: public_url: "%env(MERCURE_TWIG_PUBLISH_URL)%" # subscriber_js: '@BigoenMercureTwig\subscriber_js.html.twig'
How to use?
Configurations:
- Set MERCURE_TWIG_PUBLISH_URL,
- Set subscriber_js in yaml configuration. Default: '@BigoenMercureTwig\subscriber_js.html.twig'
Publisher Example:
use Symfony\Component\Mercure\PublisherInterface; use Symfony\Component\Mercure\Update; /** @var PublisherInterface $publisher */ $publisher(new Update('live', 'test'));
Controller Example:
<?php declare(strict_types=1); namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; /** * @Route("/mercure", name="mercure.") */ class MercureController extends AbstractController { /** * @Route("/order", name="order") */ public function orderAction(): Response { return $this->render('mercure/order.html.twig'); } }
Twig Example:
- Set render controller,
- Set mercure topics,
- Set token is private.
- Set isAdd. Default: 0. 1 = afterbegin, 2 = beforebegin.
{{ render_bigoen_mercure_twig(
controller('App\\Controller\\MercureController::orderAction'),
{'topics': ['live'], 'isAdd': 1, 'token': 'bearer token'}
) }}
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2020-12-10