PHP code example of mrsuh / tree-printer

1. Go to this page and download the library: Download mrsuh/tree-printer 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/ */

    

mrsuh / tree-printer example snippets


composer 



rsuh\Tree\NodeInterface;
use Mrsuh\Tree\Printer;

class Node implements NodeInterface
{
    private string $name;
    private array  $children;

    public function __construct(string $name, array $children = [])
    {
        $this->name     = $name;
        $this->children = $children;
    }

    public function getChildren(): array
    {
        return $this->children;
    }

    public function __toString(): string
    {
        return $this->name;
    }
}

$tree = new Node('/etc', [
    new Node('adduser.conf'),
    new Node('apt', [
        new Node('apt.conf.d', [
            new Node('01autoremove'),
            new Node('70debconf')
        ]),
        new Node('auth.conf.d'),
        new Node('preferences.d'),
        new Node('trusted.gpg.d', [
            new Node('debian-archive-bullseye-automatic.gpg'),
            new Node('debian-archive-bullseye-security-automatic.gpg'),
            new Node('debian-archive-bullseye-stable.gpg'),
        ]),
    ]),
    new Node('bash.bashrc'),
    new Node('cron.d', [
        new Node('e2scrub_all'),
    ]),
    new Node('cron.daily', [
        new Node('apt-compat'),
        new Node('dpkg'),
    ])
]);

$printer = new Printer();
$printer->print($ast);