PHP code example of tuuz / net

1. Go to this page and download the library: Download tuuz/net library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tuuz / net example snippets



TuuzNet\TuuzNet;

// GET 请求
$response = TuuzNet::Get('https://api.example.com/users', [
    'page' => 1,
    'limit' => 20,
]);

// POST JSON
$response = TuuzNet::PostJson('https://api.example.com/users', [], [
    'name' => 'Alice',
    'email' => '[email protected]',
]);

// POST 表单
$response = TuuzNet::PostForm('https://api.example.com/login', [], [
    'username' => 'admin',
    'password' => '123456',
]);

// 文件上传
$response = TuuzNet::PostFile('https://api.example.com/upload', '/path/to/file.pdf');

// PUT
$response = TuuzNet::Put('https://api.example.com/users/1', [], [
    'name' => 'Bob',
]);

// DELETE
$response = TuuzNet::Delete('https://api.example.com/users/1');

TuuzNet::Get(
    string $base_url,
    array  $query = [],
    array  $headers = [],
    int    $timeout = 30
): string

TuuzNet::PostJson(
    string $base_url,
    array  $query = [],
    array  $postData = [],
    int    $timeout = 30
): string

TuuzNet::PostForm(
    string $base_url,
    array  $query = [],
    array  $postData = [],
    int    $timeout = 30
): string

TuuzNet::PostFile(
    string $send_url,
    string $real_path,
    string $fieldName = 'file',
    array  $extraData = [],
    int    $timeout = 60
): string|bool

TuuzNet::PostFile(
    'https://example.com/upload',
    '/data/avatar.png',
    'avatar',
    ['user_id' => 1001, 'type' => 'png']
);

TuuzNet::PostBinary(
    string $url,
    mixed  $data,
    array  $headers = [],
    int    $timeout = 40
): array

[
    'result'    => string|false,  // 响应内容
    'error'     => string|null,   // curl 错误信息
    'http_info' => array          // curl_getinfo() 完整信息
]

TuuzNet::Put(
    string $base_url,
    array  $query = [],
    mixed  $postData = [],
    array  $headers = [],
    int    $timeout = 30
): string

TuuzNet::Delete(
    string $base_url,
    array  $query = [],
    array  $headers = [],
    int    $timeout = 30
): string

use TuuzNet\TuuzNet;

try {
    $resp = TuuzNet::PostJson('https://example.com/api', [], ['foo' => 'bar']);
    $data = json_decode($resp, true);
} catch (\Exception $e) {
    // 可能的错误:超时、DNS 解析失败、连接拒绝、SSL 错误等
    echo '请求失败: ' . $e->getMessage();
}

use TuuzNet\CommitAnalyzer;

$analyzer = new CommitAnalyzer();

// 1. 解析单条提交
$parsed = $analyzer->parseCommit('feat(net)!: add PUT and DELETE methods');
// => ['type' => 'feat', 'scope' => 'net', 'breaking' => true, 'subject' => '...', ...]

// 2. 验证提交合规性
$result = $analyzer->validateCommit('bad commit message');
// => ['valid' => false, 'errors' => [...], 'warnings' => [...]]

// 3. 批量分析
$batch = $analyzer->analyzeBatch($commitMessages);
// => ['total', 'valid', 'by_type', 'breaking', 'version_bump', 'stats', ...]

// 4. SemVer 版本建议
$ver = $analyzer->suggestNextVersion('1.2.3', $commitMessages);
// => ['current' => '1.2.3', 'next' => '2.0.0', 'bump' => 'major', 'reason' => '...']

// 5. 生成 CHANGELOG
$changelog = $analyzer->generateChangelog('1.3.0', $commitMessages);

// 6. 生成 Composer 包提交描述(Packagist/Release Notes 用)
$desc = $analyzer->generatePackageDescription('tuuz/net', '1.3.0', $commitMessages);
echo $desc['description'];     // 完整包描述段落
echo $desc['release_notes'];   // 完整 CHANGELOG
print_r($desc['keywords']);    // 包关键词
print_r($desc['highlights']);  // 亮点摘要(Features/Breaking Changes 等)

// 7. 读取 Git 日志 + 一键分析
$commits = CommitAnalyzer::fetchGitCommits('HEAD~20..HEAD');
CommitAnalyzer::analyze();   // CLI 美化输出

php_tuuz_net/
├── src/
│   ├── Net.php              # 核心 cURL HTTP 客户端
│   ├── TuuzNet.php          # 静态 Facade(TuuzNet::xxx)
│   ├── CommitAnalyzer.php   # Conventional Commits 分析 + 包描述生成
│   └── helpers.php          # 注册全局类名别名 TuuzNet
├── composer.json
├── vendor/ (composer 生成)
├── phpunit.xml (如有)
└── README.md