定制 merlindiavova/postcodesio 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

merlindiavova/postcodesio

Composer 安装命令:

composer require merlindiavova/postcodesio

包简介

Postcodes.IO API

README 文档

README

Build Status Build Status Latest Stable Version License

PHP client to consume the Postcodes.io API.

Installation

It's recommended that you use Composer to install this library. Current supported PHP versions are 7.1-7.3.

To install this libary please run the following command:

$ composer require merlindiavova/postcodesio

Example

The example below uses sunrise/http-client-curl as the PSR-18 implementation and Nyholm/psr7 as the PSR-7 implementation.

<?php

declare(strict_types=1);

use PostcodesIO\API\Client;
use PostcodesIO\API\Client\ResponseCheck;
use PostcodesIO\API\Factory\Psr17Factory;
use Sunrise\Http\Client\Curl\Client as SunClient;
use Nyholm\Psr7\Factory\Psr17Factory as NyholmPsr17Factory;

require __DIR__ . '/vendor/autoload.php';

$psr7Implementation = new NyholmPsr17Factory();

$postcodesIoClient = new Client(
    new SunClient($psr7Implementation),
    new Psr17Factory(
        $psr7Implementation,
        $psr7Implementation,
        $psr7Implementation,
        $psr7Implementation
    )
);

$response = $postcodesIoClient->getPostcodeClient()->fetch('NW10 4DG');

$postcode = $response->getFirstResult(); // PostcodesIO\API\Postcode\Data

echo $postcode->getAdminWard() . ', ' . $postcode->getAdminDistrict(); // Harlesden, Brent

Choose a PSR-7 implementation

This library does not come with any PSR-7 implementations. You are free to use any implementation that best suits your circumstance. Below are a few notable ones:

  • Slim-Psr7 - Install using composer require slim/psr7. This is the Slim Framework projects PSR-7 implementation.
  • Nyholm/psr7 - Install using composer require nyholm/psr7. This is the fastest, strictest and most lightweight implementation at the moment.
  • Guzzle/psr7 - Install using composer require guzzlehttp/psr7. This is the implementation used by the Guzzle Client. It is not as strict but adds some nice functionality for Streams and file handling. It is the second fastest implementation but is a bit bulkier.
  • zend-diactoros - Install using composer require zendframework/zend-diactoros. This is the Zend implementation. It is the slowest implementation of the four.

Notable psr7-implementations taken https://github.com/slimphp/Slim/tree/4.x

Choose a PSR-18 implementation

This package does not come with a PSR-18 HTTP Client implementation. You are free to use any implementation that best suits your circumstance. Below are a few options:

Api Clients

Endpoint Code to get endpoint
https://api.postcodes.io/postcodes $postcodesIoClient->getPostcodeClient()
https://api.postcodes.io/outcodes $postcodesIoClient->getOutcodeClient()
https://api.postcodes.io/places $postcodesIoClient->getPlaceClient()
https://api.postcodes.io/terminated_postcodes $postcodesIoClient->getPostcodeClient()

Postcodes

<?php
// ... 
// Returns the postcode api client
$postcodesClient = $postcodesIoClient->getPostcodeClient();

// Fetch a postcode
$response = $postcodesClient->fetch('HA0 2TF'); // Returns a Postcode\Response object
$postcode = $response->getFirstResult(); // Returns Postcode\Data object

// Fetch many postcodes
$response = $postcodesClient->fetchByBulk(['HA0 2TF', 'SE1 2UP']); // Returns a Postcode\Response object
$postcodes = $response->getResult(); // Returns Client\Collection of Postcode\Data objects

// Fetch Reverse Geocode
$response = $postcodesClient->fetchByReverseGeocode(-0.076579, 51.503378); // Returns a Postcode\Response object
$postcodes = $response->getResult(); // Returns Client\Collection of Postcode\Data objects

// you add an array of optional query parameters as the third argument
$queryParams = ['limit' => 10, 'radius' => '1000', 'wideSearch' => true];
$response = $postcodesClient->fetchByReverseGeocode(-0.076579, 51.503378, $queryParams);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固