eonx-com / webhooks
此包已被废弃,不再维护。未建议替换包。
允许根据事件触发发送有效载荷的包
v0.20.9
2020-03-27 00:36 UTC
Requires
- php: >=7.3
- ext-json: *
- ext-mbstring: *
- doctrine/orm: ^2.6.3
- eonx-com/externals: ^1.0|^2.0
- eonx-com/utils: ^1.0|^2.0
- guzzlehttp/guzzle: ^6.0.0
Requires (Dev)
- eonx-com/standards: ^0.2
- laravel/lumen-framework: ^5.5
- mockery/mockery: ^1.0
- phpmd/phpmd: ^2.6
- phpstan/phpstan: ^0.11
- phpstan/phpstan-phpunit: ^0.11.0
- phpstan/phpstan-strict-rules: ^0.11.0
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: 3.*
- symfony/security: ^4.3
Provides
Replaces
This package is auto-updated.
Last update: 2021-12-27 04:52:51 UTC
README
此库添加了对创建活动的支持,然后作为webhooks触发这些活动的订阅者。
安装
使用 Composer 在您的项目中安装此包
composer require eoneopay/webhooks
使用
在需要创建活动的应用程序中注入 \EoneoPay\Webhooks\Activities\Interface\ActivityFactoryInterface
服务。此接口上的发送方法接受一个 ActivityDataInterface
实现的实例,代表要创建的特定活动。
对于您将在应用程序中触发的每个不同活动,您需要创建一个实现 ActivityDataInterface
的类。
工作原理
ActivityFactoryInterface
接收一个ActivityDataInterface
的实例- 工厂将调用
PayloadManager
来为ActivityDataInterface
构建有效载荷 - 工厂将有效载荷和
ActivityDataInterface
保存为新的ActivityInterface
实体。 - 最后,工厂将触发 ActivityCreatedEvent
- 工厂将调用
- 监听器将在异步队列工作程序内接收事件并调用
WebhookManager#processActivity
- WebhookManager 将解析活动的任何订阅
- 然后为每个订阅创建一个新的 WebhookRequest
- 并触发新的 WebhookRequestCreatedEvent。
- 另一个监听器将接收此事件并调用
RequestProcessor#process
- 这将构建一个 PSR7 请求
- 发送请求
- 将结果记录为 WebhookResponse
集成
Laravel
要将此包集成到您的 Laravel 或 Lumen,您需要注册以下服务提供商
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookServiceProvider
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookEventServiceProvider
此库的任何实现都需要
- 实现并绑定一个服务以实现接口
EoneoPay\Webhooks\Subscription\Interfaces\SubscriptionResolverInterface
- 实现一个服务以实现接口
EoneoPay\Webhooks\Payload\Interfaces\PayloadBuilderInterface
- 示例
interface WebHookPayloadBuilderInterface extends PayloadBuilderInterface { ... } final class PayloadBuilder implements WebHookPayloadBuilderInterface { ... }
- 绑定并标记服务以实现接口
YourNamespace\WebHookPayloadBuilderInterface
$this->app->bind(WebHookPayloadBuilderInterface::class, PayloadBuilder::class); $this->app->tag([WebHookPayloadBuilderInterface::class], ['webhooks_payload_builders']);
- 将
EoneoPay\Externals\Bridge\Laravel\ORM\ResolveTargetEntityExtension
添加到config/doctrine.php
中的extensions
键下 - 修改
config/doctrine.php
以添加以下配置更改
<?php declare(strict_types=1); use EoneoPay\Externals\Bridge\LaravelDoctrine\Extensions\ResolveTargetEntityExtension; use EoneoPay\Webhooks\Models\ActivityInterface; use EoneoPay\Webhooks\Models\WebhookRequestInterface; use EoneoPay\Webhooks\Models\WebhookResponseInterface; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Activity; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Request; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Response; return [ 'managers' => [ 'default' => [ // ... 'namespaces' => [ // ... // Add the Webhooks Entities to the namespace mappings 'Eoneopay\\Webhooks\\Bridge\\Doctrine\\Entities' ], 'paths' => [ // ... // Add the Webhooks filepath to the Entity Manager \base_path('vendor/eoneopay/webhooks/src/Bridge/Doctrine/Entities') ] // ... ] ], // ... 'extensions' => [ // ... // Add the ResolveTargetEntityExtension to Doctrine ResolveTargetEntityExtension::class ], // ... 'replacements' => [ // Add replacements so Doctrine can look up entities by interface ActivityInterface::class => Activity::class, WebhookRequestInterface::class => Request::class, WebhookResponseInterface::class => Response::class ] ];