renttek / bitbucket-webhook-types

库,用于将bitbucket webhook有效负载转换为类型化对象

0.0.1 2023-06-01 18:33 UTC

This package is auto-updated.

Last update: 2024-08-30 01:38:34 UTC


README

此库提供了一种转换器以及用于bitbucket webhook有效负载的值对象。

安装

可以使用composer轻松安装此模块

composer require renttek/bitbucket-webhook-types

用法

$pullRequestCreatedPayload = '<webhook json here>';

$converter = new \Renttek\BitbucketWebhookTypes\Converter();

$pullRequestCreated = $converter->fromJson(
    \Renttek\BitbucketWebhookTypes\EventPayload\PullrequestCreated::class,
    $pullRequestCreatedPayload
)

使用自定义映射器/配置

转换器使用 cuyz/valinor 构建,如果您想使用自定义映射器而不是默认映射器,可以将映射器传递给 \Renttek\BitbucketWebhookTypes\Converter 构造函数

$pullRequestCreatedPayload = '<webhook json here>';

$myAwesomeMapper = (new MapperBuilder())
    ->supportDateFormats('Y-m-d\TH:i:s.uP')
    ->infer(
        ...
    )
    ->registerConstructor(
        ...
    )
    ->allowSuperfluousKeys()
    ->mapper();

$converter = new \Renttek\BitbucketWebhookTypes\Converter($myAwesomeMapper);

$pullRequestCreated = $converter->fromJson(
    \Renttek\BitbucketWebhookTypes\EventPayload\PullrequestCreated::class,
    $pullRequestCreatedPayload
)

致谢

我想感谢CuyZ团队和所有为valinor做出贡献的贡献者!