hxari/tree 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hxari/tree

最新稳定版本:v1.0.3

Composer 安装命令:

composer require hxari/tree

包简介

Create a Tree structure using an Array.

关键字:

README 文档

README

Tree Avatar

Abouts

Create a Tree structure using an Array or Object. You want to create a tree structure like in the Command Line Interface? Sans!... Tree is the solution!.. It's really very simple and without the hassle!

In addition to using PHP, Tree has also been made for the JavaScript version, but now it only supports HTML display, for the next version maybe I will add a feature so that the JavaScript version of Tree can run on the Command Line Interface along with NodeJS.

Install

Install with Composer

composer require hxari/tree

Install with Wget

wget https://raw.githubusercontent.com/hxAri/Tree/main/src/PHPTree/Tree.php

Install with Git

git clone https://github.com/hxAri/Tree

Or you can also download it directly from Github if you don't want to bother.

Usage

Very simple usage.

use Tree\Tree;

// If you use Composer.
require "vendor/autoload.php";

// If you use Git/ Download.
require "Tree/Tree.php";

// If you use Wget.
require "Tree.php";

// Suppose you have an array.
$array = [
    'users' => [
        [
            'id' => 2288,
            'profile' => [
                'fname' => "Xyz",
                'uname' => "xyz"
            ]
        ],
        [
            'id' => 2289,
            'profile' => [
                'fname' => "Xxx",
                'uname' => "xxx"
            ]
        ]
    ],
    'malware' => [
        'trojan' => "Horse"
    ]
];

// Creating a tree structure.
echo Tree::create( $array );

This will display.

├── users
│   ├── Array
│   │   ├── id
│   │   │   └── 2288
│   │   └── profile
│   │       ├── fname
│   │       │   └── Xyz
│   │       └── uname
│   │           └── xyz
│   └── Array
│       ├── id
│       │   └── 2289
│       └── profile
│           ├── fname
│           │   └── Xxx
│           └── uname
│               └── xxx
└── malware
    └── trojan
        └── Horse

Methods

Explanation for method.

The ::create method has three parameters which are:

Tree::create( Array $data, Int $start = 0, Int $flags = 0 )

Parameter $data is an array data that will be used to create a tree structure.

The $start parameter is used to identify how many spaces will be used for the start.

Meanwhile, the $flags parameter is used to identify whether to use a line or a dot to create the structure.

The ::setKeyHandler method has one parameter with Callable type. This is quite useful when you want to color the key values ​​of your array elements.

// Method.
Tree::setKeyHandler( Callable $handler );

// Method Use.
Tree::setKeyHandler( fn( Mixed $key ) => "\e[1;32m{$key}" );

// Or
Tree::setKeyHandler( function( Mixed $key ) {
    // Something....
});

For ::setValHandler method also has the same function.

Constants

Class Constants Type Value
Tree\Tree SPACE public String
Tree\Tree NONE public String
Tree\Tree STRAIGHT_LINE public String
Tree\Tree MIDDLE_LINE public String
Tree\Tree LAST_LINE public String
Tree\Tree LINE public Int
Tree\Tree DOUBLE_POINT public String
Tree\Tree POINT public Int

License

All source code under GNU General Public License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2022-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固