aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/src/PHPGit/Command/CatCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/kzykhys/git/src/PHPGit/Command/CatCommand.php')
-rw-r--r--library/kzykhys/git/src/PHPGit/Command/CatCommand.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/CatCommand.php b/library/kzykhys/git/src/PHPGit/Command/CatCommand.php
new file mode 100644
index 000000000..0c4fc1f41
--- /dev/null
+++ b/library/kzykhys/git/src/PHPGit/Command/CatCommand.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace PHPGit\Command;
+
+use PHPGit\Command;
+use PHPGit\Exception\GitException;
+
+/**
+ * Provide content or type and size information for repository objects - `git cat-file`
+ *
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+class CatCommand extends Command
+{
+
+ /**
+ * Returns the contents of blob object
+ *
+ * ``` php
+ * $git = new PHPGit\Git();
+ * $git->setRepository('/path/to/repo');
+ * $contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
+ * ```
+ *
+ * @param string $object The name of the blob object to show
+ *
+ * @throws GitException
+ * @return string
+ */
+ public function blob($object)
+ {
+ $process = $this->git->getProcessBuilder()
+ ->add('cat-file')
+ ->add('blob')
+ ->add($object)
+ ->getProcess();
+
+ return $this->git->run($process);
+ }
+
+ /**
+ * Returns the object type identified by **$object**
+ *
+ * ``` php
+ * $git = new PHPGit\Git();
+ * $git->setRepository('/path/to/repo');
+ * $type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
+ * ```
+ *
+ * @param string $object The name of the object to show
+ *
+ * @throws GitException
+ * @return string
+ */
+ public function type($object)
+ {
+ $process = $this->git->getProcessBuilder()
+ ->add('cat-file')
+ ->add('-t')
+ ->add($object)
+ ->getProcess();
+
+ return trim($this->git->run($process));
+ }
+
+ /**
+ * Returns the object size identified by **$object**
+ *
+ * ``` php
+ * $git = new PHPGit\Git();
+ * $git->setRepository('/path/to/repo');
+ * $type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
+ * ```
+ *
+ * @param string $object The name of the object to show
+ *
+ * @throws GitException
+ * @return string
+ */
+ public function size($object)
+ {
+ $process = $this->git->getProcessBuilder()
+ ->add('cat-file')
+ ->add('-s')
+ ->add($object)
+ ->getProcess();
+
+ return trim($this->git->run($process));
+ }
+
+} \ No newline at end of file