ph-ash/client-php

该包已被弃用且不再维护。未建议替代包。

用于向Phash实例推送数据的客户端库

v1.1.1 2020-03-13 14:42 UTC

This package is auto-updated.

Last update: 2023-04-13 22:23:23 UTC


README

用于向Phash实例推送数据的客户端库

它设计为可以使用PSR-7/PSR-17/PSR-18兼容的库或Guzzle。

配置

Symfony

将配置添加到应用程序中的服务定义。

  • PSR版本
    _defaults:
        autowire: true

    Phash\Client:
        class: Phash\ClientPSR
        arguments:
            $baseUri: "https://"
            $apiToken: "someToken"
  • Guzzle版本
    _defaults:
        autowire: true

    GuzzleHttp\Client:
        class: GuzzleHttp\Client
        arguments:
            $config:
                base_uri: "https://"

    Phash\Client:
        class: Phash\ClientGuzzle
        arguments:
            $apiToken: "someToken"

纯PHP

实例化客户端类并将配置作为参数传递

  • PSR版本
    $requestFactory = ...; // instanceof Psr\Http\Message\RequestFactoryInterface
    $uriFactory = ...; // instanceof Psr\Http\Message\UriFactoryInterface
    $streamFactory = ...; // instanceof Psr\Http\Message\StreamFactoryInterface
    $client = ...; // instanceof Psr\Http\Client\ClientInterface
    $client = new Phash\ClientPSR('https://', 'someToken', $requestFactory, $uriFactory, $streamFactory, $client);
  • Guzzle版本
    $guzzleClient = new GuzzleHttp\Client(['base_uri' => 'https://']);
    $client = new Phash\ClientGuzzle('someToken', $guzzleClient);

用法

    $data = new Phash\MonitoringData(
        'monitoring id',
        Phash\MonitoringData::STATUS_OK,
        'this detail message will be displayed if a tile is clicked by a user',
        60,
        1,
        new \DateTimeImmutable(),
        'path.for.tree' // can be `null` for a flat display
    );

    // optional data
    $data->setTileExpansionIntervalCount(2);
    $data->setTileExpansionGrowthExpression('+ 4');
  • 将数据推送到服务器
    $client->push($data);