定制 kanxpack/curlget 二次开发

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

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

kanxpack/curlget

最新稳定版本:v1.0.2

Composer 安装命令:

composer require kanxpack/curlget

包简介

Simple PHP cUrl Get API

README 文档

README

Simple PHP cUrl Get API

Usage

<?php
use Kanxpack\CurlGet\CurlGet;

require_once './vendor/autoload.php';

echo CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResult();

print_r(CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResultArray());

$curlArray = CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResultArray();

print_r($curlArray[0]['name']['common']);

Installation

With Composer

composer require kanxpack/curlget
{
    "require": {
        "kanxpack/curlget": "^1.0"
    }
}
<?php
require 'vendor/autoload.php';

use Kanxpack\CurlGet\CurlGet;

echo CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResult();

print_r(CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResultArray());

Without Composer

Why are you not using composer? Download the CurlGet latest release and put the contents of the ZIP archive into a directory in your project. Then require the file autoload.php to get all classes and dependencies loaded on need.

<?php
require 'path-to-CurlGet-directory/autoload.php';

use Kanxpack\CurlGet\CurlGet;

echo CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResult();

print_r(CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResultArray());

Documentation

The CurlGet class handles the cURL Get request in PHP.

<?php
namespace Kanxpack\CurlGet;

class CurlGet {

    // code here

}

You can see from the code snippet above that the CurlGet class is declared in the Kanxpack\CurlGet namespace. You need to import the namespace to use CurlGet without having to provide its fully qualified name each time.

use CurlGet\CurlGet;

Examples in this documentation will assume you imported classes of the Kanxpack\CurlGet namespace this way.

Instantiation

echo CurlGet::get('https://restcountries.com/v3.1/name/portugal')->getResult();
// This is a a Curl Get request that fetches the API JSON string from https://restcountries.com/v3.1/name/portugal

$postcodeArray = CurlGet::get('https://api.postcodes.io/postcodes/SW1A2AA')->getResultArray();
print_r($postcodeArray);
// This is Curl Get request that fetches the API JSON string and then converts it to an array from https://api.postcodes.io/postcodes/SW1A2AA

Reference

public static function get(string $url, array $get = array(), array $options = array()) : self
{
    self::setDefaults($url, $get);
    self::initialiseHandle();
    self::setOptionsArray($options);
    self::executeSession();
    return self::getInstance();
}

This is the main static method that handles the CUrl Get request and it returns an instance of itself.

public static function getResult() : string|false
{
    return self::$result;
}

This static method should be called to return the default result from the get() method. Usually the result is a string response.

public static function getResultArray() : array
{
    return json_decode(self::getResult(), true);
}

This static method should be called to return the default result from the get() method as an arrat instead.

Credits

This project exists thanks to all the people who contribute.

Kanxpack

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

Become a sponsor via GitHub*

  • This is a donation. No goods or services are expected in return. Any requests for refunds for those purposes will be rejected.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-16