nextstage-brasil / ns-helpers
各种实用工具的方法和类
1.0.0
2024-09-29 18:08 UTC
Requires
- php: >=7.4
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-29 21:09:31 UTC
README
NsHelpers 是一个用于处理文件、目录、日期、JSON、HTTP 等的 PHP 工具集合。该存储库包含各种类和函数,可简化 PHP 应用程序的开发。
项目结构
src/Helpers/Validate.php:验证函数。JsonParser.php:JSON 操作。File.php:文件处理工具。DirectoryManipulation.php:目录处理工具。Date.php:日期处理工具。Compatibility.php:PHP 代码兼容性检查。Format.php:格式化工具。Packer.php:JavaScript 脚本压缩。
src/Http/Ssl.php:SSL 证书处理。Response.php:HTTP 响应处理。Http.php:HTTP 请求处理。
src/Integrations/Cep.php:与 CEP API 的集成。
src/Functions/functions.php:辅助函数。
tests/FileTest.php:对File类的单元测试。
安装
要安装 NsHelpers,请使用 Composer:composer require nextstage-brasil/ns-helpers
使用方法
HTTP 请求
Http 类提供用于发起 HTTP 请求的方法。以下是一些使用示例。
发起 GET 请求
<?php
use NsHelpers\Http\Http;
$response = Http::call('https://api.example.com/data', [], 'GET');
echo $response->getBody(); // Outputs the response body as a string
发起 POST 请求
<?php
use NsHelpers\Http\Http;
$params = ['key1' => 'value1', 'key2' => 'value2'];
$headers = ['Content-Type: application/json'];
$response = Http::call('https://api.example.com/data', $params, 'POST', $headers);
echo $response->getBody('array'); // Outputs the response body as an array
使用 SSL 发起 GET 请求
<?php
use NsHelpers\Http\Http;
$response = Http::call('https://secure.example.com/data', [], 'GET', [], true);
echo $response->getHttpCode(); // Outputs the HTTP status code