xlabs / bookmarkbundle
书签管理组件
1.0.14
2021-07-08 10:00 UTC
Requires
- php: >=5.6
- predis/predis: ^1.1
- symfony/symfony: >=3.4
- xlabs/rabbitmqbundle: ^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 安装
php -d memory_limit=-1 composer.phar require xlabs/bookmarkbundle
此组件依赖于 "xlabs/rabbitmqbundle"。请确保也已设置。
在您的 AppKernel 中
public function registerbundles()
{
return [
...
...
new XLabs\BookmarkBundle\XLabsBookmarkBundle(),
];
}
php bin/console doctrine:schema:update --force
路由
追加到主路由文件
# app/config/routing.yml
x_labs_bookmark:
resource: "@XLabsBookmarkBundle/Resources/config/routing.yml"
#prefix: /
配置示例
以下显示默认值
# app/config/config.yml
x_labs_bookmark:
redis_settings:
host: 192.168.5.23
port: 6379
database_id: 7
_key_namespace: 'xlabs:bookmark'
backup: # for mysql backup/restore
<alias>: <entity_FQCN>
用法
将此代码追加到您的模板中任何位置
{% include 'XLabsBookmarkBundle:Bookmark:loader.html.twig' %}
要查看示例模板,请检查
XLabsBookmarkBundle:Bookmark:example.html.twig
MySQL 备份
请确保运行以下命令。这是将所有操作保存到项目数据库中的消费者。
php bin/console xlabs:bookmark:mysql_backup --no-debug
如果 Redis 失去了所有数据,您可以通过执行以下命令来恢复它
php bin/console xlabs:bookmark:restore --no-debug
如果您已经在 Redis 中有数据,并希望创建其 MySQL 备份,以下是一个一次性命令示例,您应将其复制到项目中并适当修改
php bin/console xlabs:bookmark:initial_backup --no-debug
事件监听器
如果您希望在前后端发生 BOOKMARK 操作时执行某些操作,您可以创建一个事件监听器,如下所示
# YourBundle/Resources/config/services.yml
...
xlabs_bookmark.event_listener:
class: YourBundle\EventListeners\YourListener.php
tags:
- { name: kernel.event_listener, event: xlabs_bookmark.event, method: yourListenerMethod }
use Symfony\Component\EventDispatcher\Event;
class YourListener extends Event
{
public function yourListenerMethod(Event $event)
{
dump($event->getBookmark()); die;
}
}
$event 变量包含有关已发生的 BOOKMARK 操作的所有信息。
调整
默认情况下,服务使用会话中的用户。如果您希望使用特定用户执行 BOOKMARK 操作来使用此服务
$user = $em->getRepository('YourBundle:YourUserEntity')->find(<ID>);
$bookmark_engine = $container->get('xlabs_bookmark_engine');
$bookmark_engine->setUser($user);
$bookmark_engine->...