定制 pbergman/tree-helper 二次开发

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

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

pbergman/tree-helper

最新稳定版本:1.0.2

Composer 安装命令:

composer require pbergman/tree-helper

包简介

A symfony console helper to print a tree

README 文档

README

this is a small library for symfony console to print a tree in a fluent and flexible way.

The output is similar as the linux tree command, an can be used to debug/output relational data.

Usage:

$tree = new TreeHelper($output); $tree ->newNode('first') ->addValue('fist value') ->addValue('second value') ->newNode('fist sub') ->addValue('fist sub value') ->addValue('second sub value') ->newNode('fist sub sub') ->addValue('fist sub sub value') ->addValue('second sub sub value') ->end() ->end() ->newNode('second') ->addValue('second value') ->addValue('second second value') ->end(); $tree->printTree(); 

or

$tree = new TreeHelper($output); $tree->addArray([ 'first' => [ 0 => 'fist value', 1 => 'second value', 'fist sub' => [ 0 => 'fist sub value', 1 => 'second sub value', 'fist sub sub' => [ 'fist sub sub value', 'second sub sub value', ], ], ], 'second' => [ 'second value', 'second second value', ] ]); 

that will output:

. │ └── first ├── fist value ├── second value ├── fist sub │ ├── fist sub value │ ├── second sub value │ └── fist sub sub │ ├── fist sub sub value │ └── second sub sub value └── second ├── second value └── second second value 

for other example see the the tests.

Methods

newNode($name)

Create an new node and bind it to the parent

addNode($nodeobject:self)

Append node to tree

end()

Will return the parent object (if set else null)

getRoot()

Will return the root node

printTree($outputobject:OutputInterface)

Print the tree to output

findNode($name)

Search a node by title

toArray()

Returns a array representation of the data

getTitle()

Returns the title of the node

setTitle($title)

Sets the title of the node

addValue($value)

Add a value to the node, this can be a valid scalar or a object with method __toString

addArray($array)

Add a nested array to node

setValues($array)

Add a flat array to node, this be set as the values of the node

setParent($parentobject:self)

Set the parent of the node, will trow a RuntimeException is the the node all ready is linked to the given node, so we don`t get infinite loops.

getNodes()

Get all the (child) nodes defined in the node, all the nodes are only saved in the root so to get all nodes you probably have to do this $t->getRoot()->getNodes(); else it will return the nodes where the parent is set as node where from you calling the method.

setMaxDepth($depth)

Set the max depth of the node values, this can be done globally (on root) or on a specific node.

getMaxDepth()

Return the max depth that is set

setFormats()

Set the form that is used for example:

$tree->setFormats([ TreeHelper::LINE_PREFIX_EMPTY => ' ', TreeHelper::LINE_PREFIX => '│ ', TreeHelper::TEXT_PREFIX => '├ ', TreeHelper::TEXT_PREFIX_END => '└ ', ]); 

no it will use a 2 space indent instead of 4, see tests

setFormat($id, $format)

Overwrite a specific format

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固