The tree object (VersionControl_Git_Object_Tree)

An instance of the VersionControl_Git_Object_Tree represents tree object in Git. It has pointers to contents of the direcotry.

An instance of VersionControl_Git_Object_Tree can get via VersionControl_Git::getTree().

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$commits $git->getCommits();

$tree $git->getTree($commits[0]->getTree());

The instance doesn't have any contents at the first. If you want to get contents, you must call "fetch()" method.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$commits $git->getCommits();

$tree $git->getTree($commits[0]->getTree());
$tree->fetch();

The VersionControl_Git_Object_Commit implements the SeekableIterator interface. You can iterate and seek contents of tree.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$commits $git->getCommits();

$tree $git->getTree($commits[0]->getTree());
$tree->fetch();

foreach (
$tree as $content) {
   
var_dump($content);
}

/*
results:

object(VersionControl_Git_Object_Blob)#304 (3) {
}
object(VersionControl_Git_Object_Blob)#305 (3) {
}
object(VersionControl_Git_Object_Blob)#306 (3) {
}
object(VersionControl_Git_Object_Blob)#307 (3) {
}
object(VersionControl_Git_Object_Tree)#308 (4) {
}
object(VersionControl_Git_Object_Tree)#309 (4) {
}
object(VersionControl_Git_Object_Tree)#311 (4) {
}
object(VersionControl_Git_Object_Tree)#312 (4) {
}
object(VersionControl_Git_Object_Tree)#313 (4) {
}
object(VersionControl_Git_Object_Tree)#314 (4) {
}
object(VersionControl_Git_Object_Tree)#315 (4) {
}
object(VersionControl_Git_Object_Tree)#316 (4) {
}
object(VersionControl_Git_Object_Blob)#317 (3) {
}
object(VersionControl_Git_Object_Tree)#318 (4) {
}
*/
    Поддержать сайт на родительском проекте КГБ