xlabs / notifybundle
实时通知组件
1.0.14
2018-12-14 12:08 UTC
Requires
- php: >=5.3.9
- knplabs/knp-paginator-bundle: ^2.6
- predis/predis: ^1.1
- symfony/symfony: ^2.8|^3.4
- wisembly/elephant.io: ~3.0
- xlabs/mmadminbundle: ^1.0
Requires (Dev)
- symfony/asset: ~2.7|~3.0.0
- symfony/console: ~2.8|~3.0.0
- symfony/expression-language: ~2.4|~3.0.0
- symfony/finder: ~2.3|~3.0.0
- symfony/form: ^2.8.23
- symfony/http-kernel: ~2.8|~3.0.0
- symfony/polyfill-intl-icu: ~1.0
- symfony/routing: ~2.2|~3.0.0
- symfony/security: ~2.6|~3.0.0
- symfony/security-acl: ~2.6|~3.0.0
- symfony/stopwatch: ~2.2|~3.0.0
- symfony/templating: ~2.1|~3.0.0
- symfony/translation: ~2.7|~3.0.0
- symfony/var-dumper: ~2.7.16|~2.8.9|~3.0.9
- symfony/yaml: ^2.0.5|~3.0.0
Suggests
- symfony/asset: For using the AssetExtension
- symfony/expression-language: For using the ExpressionExtension
- symfony/finder
- symfony/form: For using the FormExtension
- symfony/http-kernel: For using the HttpKernelExtension
- symfony/routing: For using the RoutingExtension
- symfony/security: For using the SecurityExtension
- symfony/stopwatch: For using the StopwatchExtension
- symfony/templating: For using the TwigEngine
- symfony/translation: For using the TranslationExtension
- symfony/var-dumper: For using the DumpExtension
- symfony/yaml: For using the YamlExtension
README
一个类似redis的引擎。
安装
通过composer安装: <!--
# Symfony 2.8
php -d memory_limit=-1 composer.phar require xlabs/notifybundle "~1.0"
# Symfony 3.4
php -d memory_limit=-1 composer.phar require xlabs/notifybundle "~2.0"
-->
php -d memory_limit=-1 composer.phar require xlabs/notifybundle
在你的AppKernel
public function registerbundles()
{
return [
...
...
new XLabs\NotifyBundle\XLabsNotifyBundle(),
];
}
路由
追加到主路由文件
# app/config/routing.yml
x_labs_notify:
resource: "@XLabsNotifyBundle/Resources/config/routing.yml"
prefix: /
配置示例
以下显示默认值
# app/config/config.yml
x_labs_notify:
clients:
# many clients allowed; default is named "default"
notifier:
schema: https
ssl_key: /vagrant/sites/stiffia/ssl/wildcard.stiffia.com.key
ssl_cert: /vagrant/sites/stiffia/ssl/wildcard.stiffia.com.crt
host: notifications.stiffia.com
port: 3004
enabled: true
#track_online_users: true
# specify version 0.x for 0.* version and 1.x for 1.0 version
# to know socket.io version -> npm list socket.io
version: 1.x
# Storage
redis_settings:
host: 192.168.5.23
port: 6379
database_id: 8
_key_namespace: 'xlabs:notifications'
确保你更新所有资源
php app/console assets:install --symlink
使用
在模板的末尾之前追加此内容
{{ render(controller('XLabsNotifyBundle:Notifier:loader')) }}
完整的示例模板,请查看
XLabsFollowBundle:Follow:example.html.twig
渲染用户通知
在任何位置追加此内容到你的模板
{% include 'XLabsNotifyBundle:Notifier:notifications.html.twig' with {
'max_results': <num_results>
} %}
自动添加Ajax驱动的分页。
如果你想要自定义渲染通知的方式,通过创建覆盖模板
app/Resources/XLabsNotifyBundle/views/Notifier/notification.html.twig
要覆盖“无结果”模板
app/Resources/XLabsNotifyBundle/views/Notifier/no_results.html.twig
要删除(Ajax)一个通知,将以下属性添加到你的DOM元素
'data-xlabs-notify-remove="<notification_id>"'
要删除(Ajax)所有通知,将以下属性添加到你的DOM元素
'data-xlabs-notify-remove="all"'
要标记为已读(Ajax)一个通知,将以下属性添加到你的DOM元素
'data-xlabs-notify-markAsRead="<notification_id>"'
你也可以通过添加以下属性定义一个自定义的JS回调函数来执行上述所有操作,这样它就会在操作后执行
'data-xlabs-callback="YOUR_JS_FUNCTION"'
通知清理
强烈建议你创建一个每日的cronjob来从用户通知中删除所有自动过期的项。为此
$xlabs_storage = $container->get('xlabs_notifier_storage');
foreach($users as $user)
{
$xlabs_storage->clearExpiredUserNotifications($user->getId())
}
需求
Node js连接通过nginx反向代理进行。请确保设置nginx vhost
server {
listen 443 ssl;
server_name <x_labs_chat.nodejs_settings.host>;
## SSL settings
ssl on;
ssl_certificate <x_labs_chat.nodejs_settings.ssl_cert>;
ssl_certificate_key <x_labs_chat.nodejs_settings.ssl_key>;
## SSL caching/optimization
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers RC4:HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
keepalive_timeout 60;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
location / {
#proxy_set_header 'Access-Control-Allow-Origin' '*';
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $http_host;
#proxy_set_header X-NginX-Proxy true;
#proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass https://<your_internal_nodejs_server_ip>:<x_labs_chat.nodejs_settings.port>;
}
}