atournayre / confirmation-bundle
此软件包最新版本(2.0.1)没有可用的许可证信息。
确认捆绑包
2.0.1
2023-12-13 13:45 UTC
Requires
- php: >=8.1
- doctrine/doctrine-bundle: ^2.7
- doctrine/orm: ^2.11
- symfony/config: 6.2.*
- symfony/dependency-injection: 6.2.*
- symfony/form: 6.2.*
- symfony/http-foundation: 6.2.*
- symfony/routing: 6.2.*
- symfony/uid: 6.2.*
- symfony/yaml: 6.2.*
- twig/twig: ^3.4
Requires (Dev)
- symfony/phpunit-bridge: 6.2.*
This package is auto-updated.
Last update: 2024-09-13 15:48:42 UTC
README
此捆绑包为实体提供确认。
安装
Composer
composer require atournayre/confirmation-bundle
捆绑包
// config/bundles.php return [ // ... Atournayre\Bundle\ConfirmationBundle\AtournayreConfirmationBundle::class => ['all' => true], // ... ];
配置
创建文件并复制以下内容。
# config/packages/atournayre_confirmation.yaml atournayre_confirmation: providers: # Example for an email provider # email: App\Provider\YourEmailProvider # Others providers can be anything : sms, pigeon...
路由
创建文件并复制以下内容。
# config/routes/atournayre_confirmation.yaml atournayre_confirmation: resource: "@AtournayreConfirmationBundle/Resources/config/routing.yaml"
服务
# config/services.yaml services: _instanceof: Atournayre\Bundle\ConfirmationBundle\Provider\AbstractProvider: tags: ['atournayre.confirmation_bundle.tag.provider'] Atournayre\Bundle\ConfirmationBundle\Controller\: resource: ../vendor/atournayre/confirmation-bundle/src/Controller public: true tags: ['controller.service_arguments'] Symfony\Component\DependencyInjection\ContainerInterface: '@service_container' Atournayre\Bundle\ConfirmationBundle\Service\ConfirmationCodeService: class: Atournayre\Bundle\ConfirmationBundle\Service\ConfirmationCodeService arguments: $container: '@service_container' Atournayre\Bundle\ConfirmationBundle\Repository\ConfirmationCodeRepository: class: Atournayre\Bundle\ConfirmationBundle\Repository\ConfirmationCodeRepository Atournayre\Bundle\ConfirmationBundle\Config\LoaderConfig: class: Atournayre\Bundle\ConfirmationBundle\Config\LoaderConfig Atournayre\Bundle\ConfirmationBundle\Service\GenerateConfirmationService: class: Atournayre\Bundle\ConfirmationBundle\Service\GenerateConfirmationService # Providers needs to be public App\Provider\YourCustomProvider: class: App\Provider\YourCustomProvider public: true
使用方法
配置实体
- 实体需要实现
Atournayre\Bundle\ConfirmationBundle\Contracts\ConfirmableInterface
。 - 将
Atournayre\Bundle\ConfirmationBundle\Traits\ConfirmableTrait
添加到您的实体中。
创建一个提供者
对于每个实体/映射,您必须
- 创建一个提供者
- 它必须扩展自
Atournayre\Bundle\ConfirmationBundle\Provider\AbstractProvider
- 您需要实现抽象方法
- 您可以重写公共方法
注意
不建议重写
updateEntity()
。最好在实体内部使用
updateAfterConfirmation()
来更新它(例如:将状态从 'pending' 更改为 'valid')。
生成确认码
当您想要生成确认码时,只需使用 Atournayre\Bundle\ConfirmationBundle\Service\GenerateConfirmationService
,调用 __invoke()
方法。
以下操作将被执行
- 将生成确认码
- 实体将被标记为 "未确认"
- 收件人将被通知。
提示:如果您在实体中同时使用 id 和 uuid,您可以指定要使用的 id 作为第三个参数。
由于代码用于验证目的,服务仅发送它而不返回它。
验证确认码
验证可以通过两种方式进行
- 直接链接
- 表单
直接链接
使用 app_confirmation_code_with_code
路由,用户只需点击链接,实体就会被验证。
表单
使用 app_confirmation_code
路由,用户需要填写一个包含给他(通过通知)提供的代码的表单,以便验证实体。
模板化
由于 Symfony,您可以覆盖任何模板。
贡献
当然,开源是由每个人为公共利益贡献一点时间的力量。如果您想看到一个功能或添加一些 自己的 快乐话语,那真是太棒了!您可以请求它 - 但创建一个 pull request 是完成这项工作更好的方式。
无论如何,请随时提交问题或 pull request:所有贡献和问题都受到热烈的欢迎 :)