%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/vendor/gitonomy/gitlib/src/Gitonomy/Git/ |
Upload File : |
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git;
use Gitonomy\Git\Exception\InvalidArgumentException;
use Gitonomy\Git\Exception\UnexpectedValueException;
/**
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class Tree
{
protected $repository;
protected $hash;
protected $isInitialized = false;
protected $entries;
public function __construct(Repository $repository, $hash)
{
$this->repository = $repository;
$this->hash = $hash;
}
public function getHash()
{
return $this->hash;
}
protected function initialize()
{
if (true === $this->isInitialized) {
return;
}
$output = $this->repository->run('cat-file', ['-p', $this->hash]);
$parser = new Parser\TreeParser();
$parser->parse($output);
$this->entries = [];
foreach ($parser->entries as $entry) {
list($mode, $type, $hash, $name) = $entry;
if ($type == 'blob') {
$this->entries[$name] = [$mode, $this->repository->getBlob($hash)];
} elseif ($type == 'tree') {
$this->entries[$name] = [$mode, $this->repository->getTree($hash)];
} else {
$this->entries[$name] = [$mode, new CommitReference($hash)];
}
}
$this->isInitialized = true;
}
/**
* @return array An associative array name => $object
*/
public function getEntries()
{
$this->initialize();
return $this->entries;
}
public function getEntry($name)
{
$this->initialize();
if (!isset($this->entries[$name])) {
throw new InvalidArgumentException('No entry '.$name);
}
return $this->entries[$name][1];
}
public function resolvePath($path)
{
if ($path == '') {
return $this;
}
$path = preg_replace('#^/#', '', $path);
$segments = explode('/', $path);
$element = $this;
foreach ($segments as $segment) {
if ($element instanceof self) {
$element = $element->getEntry($segment);
} elseif ($element instanceof Blob) {
throw new InvalidArgumentException('Unresolvable path');
} else {
throw new UnexpectedValueException('Unknow type of element');
}
}
return $element;
}
}