hostnet / entity-tracker-bundle
封装 hostnet/entity-tracker-component 并允许配置多个监听器组件
Requires
- php: ^8.1
- hostnet/entity-tracker-component: ^2.0.0
- psr/log: ^1.1.0
- symfony/config: ^5.4||^6.0
- symfony/dependency-injection: ^5.4||^6.0
- symfony/http-kernel: ^5.4||^6.0
- symfony/yaml: ^5.4||^6.0
Requires (Dev)
- hostnet/entity-blamable-component: ^1.0.4
- hostnet/phpcs-tool: ^9.1.0
- phpspec/prophecy: ^1.19
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^9.5.6
- symfony/framework-bundle: ^5.4||^6.0
- symfony/security-bundle: ^5.4||^6.0
Suggests
- hostnet/entity-blamable-component: Provides the @Blamable annotation and listeners
- hostnet/entity-mutation-component: Provides the @Mutation annotation and listeners
- hostnet/entity-revision-component: Provides the @Revision annotation and listeners
README
文档
什么是实体追踪器包?
实体追踪器包是一个用于配置以下组件的包:
- hostnet/entity-tracker-component
- hostnet/entity-blamable-component
- hostnet/entity-mutation-component
- hostnet/entity-revision-component
您可以使用 config.yaml 配置这些组件。
注意:只有实体追踪器组件是必需的,因为这个包配置了服务。其他组件仅在存在时需要配置。
要求
追踪器包需要至少 php 7.3,并在 Doctrine2 和 Symfony2 上运行。有关具体要求,请查看 composer.json
安装
安装很简单,此包可在 packagist 上找到。您可以将包锁定到主版本,因为我们遵循 Semantic Versioning 2.0.0。
示例
"require" : { "hostnet/entity-tracker-bundle" : "^2.0.0" }
注意:如果您想要最新的更改,可以使用 dev-master,但不建议在生产代码中使用它!
文档
它是如何工作的?
它具有一个配置构建器,允许您仅配置所需的设置。如果您有可用的 "Blamable" 注释,如果未配置,则在容器编译期间将抛出异常。对其他所有支持组件也是如此。如果您在未使用的情况下配置它,它也会通知您。
设置
在 AppKernel 中注册此包
此包不依赖于其他基于编译器传递或配置的包。
class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new Hostnet\Bundle\EntityTrackerBundle\HostnetEntityTrackerBundle() // ... ]; return $bundles; } }
配置概述
默认情况下,不需要任何东西。只有当您启用某个配置选项时,它才会告诉您缺少什么。
如果您在包中使用实体,您的包应依赖于使用特定注释的组件。如果您的包在您的应用程序中,则您的应用程序应依赖于该组件。如果您使用 hostnet/entity-plugin-lib,您将为实体拥有单独的包。您应该在包上设置依赖项。
注意:根据可用的内容,确定配置要求。如果某个包或实体包依赖于某个组件,此包也将为您配置它。
模板如下
# Default configuration for extension with alias: "hostnet_entity_tracker" hostnet_entity_tracker: # Configures and enables the blamable listener blamable: # Provider implementation of Hostnet\Component\EntityBlamable\Provider\BlamableProviderInterface provider: ~ # Required # Configures and enables the revision listener revision: # Factory implementation of Hostnet\Component\EntityRevision\Factory\RevisionFactoryInterface factory: ~ # Required # Configures and enables the mutation listener mutation: ~
配置可归责组件
可归责组件有 1 个必需选项,即提供者。提供者是 根据文档中解释的 BlamableProviderInterface 实现的类。传递给该选项的参数是您正在使用的服务的名称。有两种方法可以使用这些提供者。第一种方法是使用此包附带的标准可归责提供者。这可以通过以下方法完成
config.yaml
hostnet_entity_tracker: blamable: provider: entity_tracker.provider.blamable default_username: "username for example purposes"
也可以通过实现BlamableProviderInterface来创建自己的BlamableProvider。如果您选择这样做,可以使用以下方法来利用您自定义的BlamableProvider。
注意:以下示例基于上面的链接中的AcmeBlamableProvider
services.yaml
services: acme.provider.blamable: class: Acme\Bundle\AcmeBundle\Service\AcmeBlamableProvider arguments: - 'username for example purposes'
config.yaml
hostnet_entity_tracker: blamable: provider: acme.provider.blamable
配置Mutation组件
Mutation组件没有必需的选项。要启用它,只需在配置中添加"mutation: ~"即可。
config.yaml
hostnet_entity_tracker: mutation: ~
配置Revision组件
Revision组件有1个必需的选项,即工厂。工厂是如文档所述实现RevisionFactoryInterface的类。传递给该选项的参数是您为其使用的服务的名称。
注意:以下示例基于上面的链接中的AcmeRevisionFactory
services.yaml
services: acme.factory.revision: class: Acme\Bundle\AcmeBundle\Service\AcmeBlamableProvider arguments: - 'author->name for example purposes'
config.yaml
hostnet_entity_tracker: revision: factory: acme.factory.revision