PHPackages                             xiucaiwu/tp5tool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xiucaiwu/tp5tool

Abandoned → [https://github.com/xiucaiwu/phptool](/?search=https%3A%2F%2Fgithub.com%2Fxiucaiwu%2Fphptool)Library[Utility &amp; Helpers](/categories/utility)

xiucaiwu/tp5tool
================

The PHP Common Tool Classes

1.2.1(6y ago)32162MITPHPPHP &gt;=5.6.0

Since Dec 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xiucaiwu/phptool)[ Packagist](https://packagist.org/packages/xiucaiwu/tp5tool)[ Docs](https://github.com/xiucaiwu/phptool)[ RSS](/packages/xiucaiwu-tp5tool/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (6)Used By (0)

phptool
=======

[](#phptool)

收集PHP常用的工具类,一个代码搬运工.

安装
--

[](#安装)

> composer require "xiucaiwu/phptool"

删除
--

[](#删除)

> composer remove xiucaiwu/phptool

更新
--

[](#更新)

> composer update xiucaiwu/phptool

使用
--

[](#使用)

SelectTree使用场景=&gt;后台管理系统的菜单列表 [![菜单列表](https://github.com/xiucaiwu/phptool/raw/master/screenshots/20180516133315.png)](https://github.com/xiucaiwu/phptool/blob/master/screenshots/20180516133315.png)

```
//引入类库
use PHPTool\SelectTree;

// SelectTree 使用案例
public function stdemo()
{
    $arr = array(
             1  => array('id' =>'1','parentid' =>0,'name' =>'一级栏目一'),
             2  => array('id' =>'2','parentid' =>0,'name' =>'一级栏目二'),
             3  => array('id' =>'3','parentid' =>1,'name' =>'二级栏目一'),
             4  => array('id' =>'4','parentid' =>1,'name' =>'二级栏目二'),
             5  => array('id' =>'5','parentid' =>2,'name' =>'二级栏目三'),
             6  => array('id' =>'6','parentid' =>3,'name' =>'三级栏目一'),
             7  => array('id' =>'7','parentid' =>3,'name' =>'三级栏目二')
        );
        $st = new SelectTree($arr);
        dump($st->getArray());
        // 下拉菜单选项使用 get_tree方法
        $html='';
        $str = "\$spacer\$name";     // $name是数组中存在的key
        $html .= $st->get_tree(0, $str, -1).'';
        echo $html;
}

```

// 输出

```
array(7) {
  [1] => array(3) {
    ["id"] => string(1) "1"
    ["parentid"] => int(0)
    ["name"] => string(16) " 一级栏目一"
  }
  [3] => array(3) {
    ["id"] => string(1) "3"
    ["parentid"] => int(1)
    ["name"] => string(46) "&nbsp;&nbsp;&nbsp;&nbsp;├─ 二级栏目一"
  }
  [6] => array(3) {
    ["id"] => string(1) "6"
    ["parentid"] => int(3)
    ["name"] => string(73) "&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;├─ 三级栏目一"
  }
  [7] => array(3) {
    ["id"] => string(1) "7"
    ["parentid"] => int(3)
    ["name"] => string(74) "&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp; └─ 三级栏目二"
  }
  [4] => array(3) {
    ["id"] => string(1) "4"
    ["parentid"] => int(1)
    ["name"] => string(47) "&nbsp;&nbsp;&nbsp;&nbsp; └─ 二级栏目二"
  }
  [2] => array(3) {
    ["id"] => string(1) "2"
    ["parentid"] => int(0)
    ["name"] => string(16) " 一级栏目二"
  }
  [5] => array(3) {
    ["id"] => string(1) "5"
    ["parentid"] => int(2)
    ["name"] => string(47) "&nbsp;&nbsp;&nbsp;&nbsp; └─ 二级栏目三"
  }
}

一级栏目一
&nbsp;├─二级栏目一
&nbsp;│&nbsp;├─三级栏目一
&nbsp;│&nbsp; └─三级栏目二
&nbsp; └─二级栏目二
一级栏目二
&nbsp; └─二级栏目三

```

NodeTree使用场景=&gt;后台管理系统的控制菜单 [![控制菜单](https://github.com/xiucaiwu/phptool/raw/master/screenshots/20180516133410.png)](https://github.com/xiucaiwu/phptool/blob/master/screenshots/20180516133410.png)

```
//引入类库
use PHPTool\NodeTree;

// NodeTree使用案例
public function ntdemo() {
	//原始数据, 从数据库读出
	$data = array(
		array(
			'id'=>1,
			'name'=>'book',
			'parent_id'=>0
		),
		array(
			'id'=>2,
			'name'=>'music',
			'parent_id'=>0
		),
		array(
			'id'=>3,
			'name'=>'book1',
			'parent_id'=>1
		),
		array(
			'id'=>4,
			'name'=>'book2',
			'parent_id'=>3
		)
	);
	$r = NodeTree::makeTree($data);
	echo json_encode($r);
}

```

// 输出

```
[{
	"id": 1,
	"name": "book",
	"parent_id": 0,
	"expanded": false,
	"children": [{
		"id": 3,
		"name": "book1",
		"parent_id": 1,
		"expanded": false,
		"children": [{
			"id": 4,
			"name": "book2",
			"parent_id": 3,
			"leaf": true
		}]
	}]
}, {
	"id": 2,
	"name": "music",
	"parent_id": 0,
	"leaf": true
}]

```

Curl使用场景

```
//引入类库
use PHPTool\Curl;

// Curl get使用案例
public function get() {
	echo Curl::get('www.baidu.com');
}

// Curl post使用案例
public function post() {
	$field = [
		'p'	=> 1,
		'time'	=> time(),
	];
	$userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36';
	$httpHeaders = [
		"Content-type: application/json;charset='utf-8'",
		"Accept: application/json",
		"Cache-Control: no-cache",
		"Pragma: no-cache",
	];

	echo Curl::post('http://www.ahlinux.com/', $field, $userAgent, $httpHeaders);
}

```

ColorEcho使用场景:命令行 [![控制菜单](https://github.com/xiucaiwu/phptool/raw/master/screenshots/20190110204946.png)](https://github.com/xiucaiwu/phptool/blob/master/screenshots/20190110204946.png)

```
//引入类库
use PHPTool\ColorEcho;

ColorEcho::info('Hello, world!');
ColorEcho::warn('Hello, world!');
ColorEcho::error('Hello, world!');
ColorEcho::e('Hello, world!', "purple", "yellow");
ColorEcho::e('Hello, world!', "blue", "light_gray");
ColorEcho::e('Hello, world!', "red", "black");
ColorEcho::e('Hello, world!', "cyan", "green");
ColorEcho::e('Hello, world!', "cyan");
ColorEcho::e('Hello, world!', null, "cyan");

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~124 days

Total

4

Last Release

2331d ago

PHP version history (2 changes)1.0PHP &gt;=5.4.0

1.1PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10164759?v=4)[xiucai.me](/maintainers/xiucaiwu)[@xiucaiwu](https://github.com/xiucaiwu)

---

Top Contributors

[![xiucaiwu](https://avatars.githubusercontent.com/u/10164759?v=4)](https://github.com/xiucaiwu "xiucaiwu (24 commits)")

---

Tags

composerphpphpPHPTool

### Embed Badge

![Health badge](/badges/xiucaiwu-tp5tool/health.svg)

```
[![Health](https://phpackages.com/badges/xiucaiwu-tp5tool/health.svg)](https://phpackages.com/packages/xiucaiwu-tp5tool)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
