cravler / faye-app-bundle
dev-master / 3.x-dev
2024-09-02 13:10 UTC
Requires
- php: >=7.4
- symfony/framework-bundle: ^5.4|^6.0
- twig/twig: ^2.13|^3.0
This package is auto-updated.
Last update: 2024-09-02 13:10:56 UTC
README
此包依赖于 faye-app。
安装步骤
步骤 1:下载包
composer require cravler/faye-app-bundle:2.x-dev
此命令要求您全局安装Composer,具体请参考Composer文档中的安装章节。
步骤 2:启用包
此包应该由Flex自动启用。如果您不使用Flex,您需要手动在项目的config/bundles.php
文件中添加以下行来启用包
<?php // config/bundles.php return [ // ... Cravler\FayeAppBundle\CravlerFayeAppBundle::class => ['all' => true], ];
步骤 3:添加路由
# config/routes.yaml cravler_faye_app: resource: "@CravlerFayeAppBundle/Resources/config/routing.yaml"
步骤 4:包含JavaScript
为了包含FayeApp所需的JavaScript库,请将这些库添加到您的根布局文件中。
<!-- .../Acme/DemoBundle/Resources/views/layout.html.twig --> <script type="text/javascript" src="..."></script> {{ faye_app_javascript() }}
使用方法
创建入口点
<?php // .../Acme/DemoBundle/EntryPoint/Example.php namespace Acme\DemoBundle\EntryPoint; use Cravler\FayeAppBundle\EntryPoint\AbstractEntryPoint; class Example extends AbstractEntryPoint { public function getId() { return 'acme-demo.example'; } }
注册入口点
<!-- .../Acme/DemoBundle/Resources/config/services.xml --> <services> ... <service id="acme.demo.entry_point.example" class="Acme\DemoBundle\EntryPoint\Example"> <call method="setEntryPointManager"> <argument type="service" id="cravler_faye_app.service.entry_point_manager" /> </call> <tag name="cravler_faye_app.entry_point" /> </service> ... </services>
订阅频道
<script type="text/javascript"> var exampleEntryPoint = FayeApp.createEntryPoint('acme-demo.example'); var subscription = exampleEntryPoint.subscribe('/foo', function(message) { console.log('[foo] Handle message: ', message); }); subscription.then(function() { console.log('[foo] Subscription is now active!'); }, function(error) { console.log('[foo] Subscription problem: ' + error.message); }); </script>
发送消息
<script type="text/javascript"> var exampleEntryPoint = FayeApp.createEntryPoint('acme-demo.example'); var publication = exampleEntryPoint.publish('/foo', { text: 'Hi there' }); publication.then(function() { console.log('[foo] Message received by server!'); }, function(error) { console.log('[foo] There was a problem: ' + error.message); }); </script>
配置
该包的默认配置如下所示
cravler_faye_app: example: false user_provider: false #security.user.provider.concrete.[provider_name] route_url_prefix: /faye-app use_request_uri: false secret: ThisTokenIsNotSoSecretChangeIt app: scheme: ~ host: 127.0.0.1 port: ~ mount: /pub-sub options: {}
许可证
此包采用MIT许可证。请参阅包中的完整许可证。
LICENSE