%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;
/**
* Representation of a Blob commit.
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class Blob
{
/**
* @var Repository
*/
protected $repository;
/**
* @var string
*/
protected $hash;
/**
* @var string
*/
protected $content;
/**
* @var string
*/
protected $mimetype;
/**
* @param Repository $repository Repository where the blob is located
* @param string $hash Hash of the blob
*/
public function __construct(Repository $repository, $hash)
{
$this->repository = $repository;
$this->hash = $hash;
}
/**
* @return string
*/
public function getHash()
{
return $this->hash;
}
/**
* @throws ProcessException Error occurred while getting content of blob
*
* @return string Content of the blob.
*/
public function getContent()
{
if (null === $this->content) {
$this->content = $this->repository->run('cat-file', ['-p', $this->hash]);
}
return $this->content;
}
/**
* Determine the mimetype of the blob.
*
* @return string A mimetype
*/
public function getMimetype()
{
if (null === $this->mimetype) {
$finfo = new \finfo(FILEINFO_MIME);
$this->mimetype = $finfo->buffer($this->getContent());
}
return $this->mimetype;
}
/**
* Determines if file is binary.
*
* @return bool
*/
public function isBinary()
{
return !$this->isText();
}
/**
* Determines if file is text.
*
* @return bool
*/
public function isText()
{
return (bool) preg_match('#^text/|^application/xml#', $this->getMimetype());
}
}