PHP code example of thinktomorrow / vine

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

    

thinktomorrow / vine example snippets


// Create a node and attach a child node ot it
$node = new Node('foobar');
$node->addChildren(new Node('fooberry'));

// flat dataset as pulled from database
$dataset = [
    ['id' => 1, 'parent_id' => 0, 'label' => 'foobar'],
    ['id' => 2, 'parent_id' => 1, 'label' => 'baz'],
    ['id' => 3, 'parent_id' => 2, 'label' => 'bazbaz'],
];

$collection = NodeCollection::fromArray($dataset);

 // Using a custom source
 $collection = NodeCollection::fromSource(
     new ArraySource($dataset)
 );
 
 
 interface Source
 {
    // array of all entries.
     public function nodeEntries(): array;

     // property to identify the key (default is 'id')
     public function nodeKeyIdentifier(): string;

     // property to identify the parent key (default is 'parent_id')
     public function nodeParentKeyIdentifier(): string;
 }