lupuscoding/webhook-sender
Composer 安装命令:
composer require lupuscoding/webhook-sender
包简介
Simple Sender for webhook requests.
关键字:
README 文档
README
Simple Sender for webhook requests.
Contents
Requirements #
- PHP >= 7.4
Install #
composer require lupuscoding/webhook-sender
Usage #
Send a message to a webhook
The sender accepts objects, that implement the JsonSerializable interface. Just initialize an object, that implements the interface and hand it over, to the Sender::send method.
use LupusCoding\Webhooks\Sender\Sender; // Init your serializable object /** @var JsonSerializable $mySerializableObject */ $mySerializableObject = new MySerializableObject(); // Setup the hook url $webhookUrl = 'https://httpbin.org/post'; // Init sender $sender = new Sender($webhookUrl, false); // Send object ot webhook $sender->send($mySerializableObject); // Get response $response = $sender->getLastResponse();
Create a valid serializable object
By implementing the JsonSerializable interface and creating the jsonSerialize method, you are able to decide, which data will be sent.
use JsonSerializable; class MySerializableObject implements JsonSerializable { private string $stringToPush; private string $stringToProcess; private bool $boolToPush; private bool $onlyToProcess; /* Getters and Setters may be here */ public function jsonSerialize(): array { return [ 'stringToPush' => $this->stringToPush, 'boolToPush' => $this->boolToPush, ]; } }
This example has two properties that should be pushed / send and two properties that should not be sent.
Development #
- Every contribution should respect PSR-2 and PSR-12.
- Methods must provide argument types and return types.
- Class properties must be typed.
- doc blocks must only contain descriptive information.
- doc blocks may additionally contain a type declaration for arguments or return values, if the type declaration is not precise.
For example: func(): array may not be precise if the method returns
an array of arrays or objects. Consider a doc block entry like
@return array[] or @return MyObject[] for clarification.
Testing #
Webhook test site: https://httpbin.org
First install phpunit by executing
composer install
Then start phpunit by executing
vendor/bin/phpunit
Optional: Look at the webhook test site, to get more information.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-16