ready-dev-team/nbp-web-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ready-dev-team/nbp-web-api

最新稳定版本:2.0.0

Composer 安装命令:

composer require ready-dev-team/nbp-web-api

包简介

NBP Web API client for PHP.

README 文档

README

Latest Stable Version Build Status

Simple and fluent interface to retrieve data from NBP Web API.
This library structure is strongly inspired by knplabs/github-api package.

Installation

This package is decoupled from any HTTP client thanks to the HTTPlug.
Requires packages that provide http-client-implementation and psr/http-factory-implementation.
For more information visit HTTPlug for library users.

$ composer require kreyu/nbp-web-api

Usage

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Api\ExchangeRates;

$client = new Client();

// Example call
$client->exchangeRates(ExchangeRates::TABLE_TYPE_A)->forCurrency('EUR')->latest(5);

Changing content type

If you wish to retrieve responses in XML format rather than JSON, you can change it in the client:

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\ClientInterface;

$client = new Client();
$client->setContentType(ClientInterface::CONTENT_TYPE_XML);

Providing HTTP client and factories

By default, the HTTP client builder uses HTTP client and factories provided by the discovery.
If you have to provide specific PSR-18 compliant client or any PSR-17 factory, you can pass them to the HTTP client builder:

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/**
 * @var $client         Psr\Http\Client\ClientInterface
 * @var $requestFactory Psr\Http\Message\RequestFactoryInterface
 * @var $streamFactory  Psr\Http\Message\StreamFactoryInterface
 * @var $uriFactory     Psr\Http\Message\UriFactoryInterface
 */

$builder = new HttpClientBuilder(
    $client,
    $requestFactory,
    $streamFactory,
    $uriFactory
);

$client = new Client($builder);

Caching

To use caching mechanism, provide any PSR-6 compliant item pool to the HTTP client builder:

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/** @var $pool Psr\Cache\CacheItemPoolInterface */

$builder = new HttpClientBuilder();
$builder->setCache($pool);

$client = new Client($builder);

Using HTTPlug plugins

You can provide any HTTPlug plugin to the HTTP client builder:

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/** @var $plugin Http\Client\Common\Plugin */

$builder = new HttpClientBuilder();
$builder->addPlugin($plugin);

$client = new Client($builder);

统计信息

  • 总下载量: 1.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固