aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/src/PHPGit/Command.php
diff options
context:
space:
mode:
authorWave <wave72@users.noreply.github.com>2016-07-22 10:55:02 +0200
committerGitHub <noreply@github.com>2016-07-22 10:55:02 +0200
commit744ad84714fe0f7a3d90250a4ff02dc4327b9061 (patch)
tree595fb74ec9ea0bc7130d18bd7993d719a222d343 /library/kzykhys/git/src/PHPGit/Command.php
parentc38c79d71c8ef70ef649f83e322f1984b75ee2dd (diff)
parent7d897a3f03bd57ed556433eb84a41963ba44e02e (diff)
downloadvolse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.gz
volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.bz2
volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.zip
Merge pull request #6 from redmatrix/dev
Dev
Diffstat (limited to 'library/kzykhys/git/src/PHPGit/Command.php')
-rw-r--r--library/kzykhys/git/src/PHPGit/Command.php123
1 files changed, 123 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command.php b/library/kzykhys/git/src/PHPGit/Command.php
new file mode 100644
index 000000000..9238a5454
--- /dev/null
+++ b/library/kzykhys/git/src/PHPGit/Command.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace PHPGit;
+
+use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\Process\ProcessBuilder;
+
+/**
+ * Base class for git commands
+ *
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+abstract class Command
+{
+
+ /**
+ * @var Git
+ */
+ protected $git;
+
+ /**
+ * @param Git $git
+ */
+ public function __construct(Git $git)
+ {
+ $this->git = $git;
+ }
+
+ /**
+ * Returns the combination of the default and the passed options
+ *
+ * @param array $options An array of options
+ *
+ * @return array
+ */
+ public function resolve(array $options = array())
+ {
+ $resolver = new OptionsResolver();
+ $this->setDefaultOptions($resolver);
+
+ return $resolver->resolve($options);
+ }
+
+ /**
+ * Sets the default options
+ *
+ * @param OptionsResolverInterface $resolver The resolver for the options
+ *
+ * @codeCoverageIgnore
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ }
+
+ /**
+ * Split string by new line or null(\0)
+ *
+ * @param string $input The string to split
+ * @param bool $useNull True to split by new line, otherwise null
+ *
+ * @return array
+ */
+ protected function split($input, $useNull = false)
+ {
+ if ($useNull) {
+ $pattern = '/\0/';
+ } else {
+ $pattern = '/\r?\n/';
+ }
+
+ return preg_split($pattern, rtrim($input), -1, PREG_SPLIT_NO_EMPTY);
+ }
+
+ /**
+ * Adds boolean options to command arguments
+ *
+ * @param ProcessBuilder $builder A ProcessBuilder object
+ * @param array $options An array of options
+ * @param array $optionNames The names of options to add
+ */
+ protected function addFlags(ProcessBuilder $builder, array $options = array(), array $optionNames = null)
+ {
+ if ($optionNames) {
+ foreach ($optionNames as $name) {
+ if (isset($options[$name]) && is_bool($options[$name]) && $options[$name]) {
+ $builder->add('--' . $name);
+ }
+ }
+ } else {
+ foreach ($options as $name => $option) {
+ if ($option) {
+ $builder->add('--' . $name);
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds options with values to command arguments
+ *
+ * @param ProcessBuilder $builder A ProcessBuilder object
+ * @param array $options An array of options
+ * @param array $optionNames The names of options to add
+ */
+ protected function addValues(ProcessBuilder $builder, array $options = array(), array $optionNames = null)
+ {
+ if ($optionNames) {
+ foreach ($optionNames as $name) {
+ if (isset($options[$name]) && $options[$name]) {
+ $builder->add('--' . $name . '=' . $options[$name]);
+ }
+ }
+ } else {
+ foreach ($options as $name => $option) {
+ if ($option) {
+ $builder->add('--' . $name . '=' . $option);
+ }
+ }
+ }
+ }
+
+} \ No newline at end of file