aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-01 22:29:51 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-01 22:29:51 -0400
commitc2d15e6c3bd8a29bae89d184a999ddac15fcb807 (patch)
tree96cbbfa98f131d830fbfd154f82e37383bb37bd8 /library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php
parentb1ae4d776c7c093c7f3ff6905e1a5302fbd5e3f6 (diff)
downloadvolse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.tar.gz
volse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.tar.bz2
volse-hubzilla-c2d15e6c3bd8a29bae89d184a999ddac15fcb807.zip
New plugin repo is cloned to /store/pluginrepos/REPONAME for analysis
Diffstat (limited to 'library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php')
-rw-r--r--library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php132
1 files changed, 132 insertions, 0 deletions
diff --git a/library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php b/library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php
new file mode 100644
index 000000000..cb8bb625f
--- /dev/null
+++ b/library/kzykhys/git/src/PHPGit/Command/ConfigCommand.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace PHPGit\Command;
+
+use PHPGit\Command;
+use PHPGit\Exception\GitException;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+/**
+ * Get and set repository or global options - `git config`
+ *
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+class ConfigCommand extends Command
+{
+
+ /**
+ * Returns all variables set in config file
+ *
+ *
+ * ##### Options
+ *
+ * - **global** (_boolean_) Read or write configuration options for the current user
+ * - **system** (_boolean_) Read or write configuration options for all users on the current machine
+ *
+ * @param array $options [optional] An array of options {@see ConfigCommand::setDefaultOptions}
+ *
+ * @throws GitException
+ * @return array
+ */
+ public function __invoke(array $options = array())
+ {
+ $options = $this->resolve($options);
+ $builder = $this->git->getProcessBuilder()
+ ->add('config')
+ ->add('--list')
+ ->add('--null');
+
+ $this->addFlags($builder, $options, array('global', 'system'));
+
+ $config = array();
+ $output = $this->git->run($builder->getProcess());
+ $lines = $this->split($output, true);
+
+ foreach ($lines as $line) {
+ list($name, $value) = explode("\n", $line, 2);
+
+ if (isset($config[$name])) {
+ $config[$name] .= "\n" . $value;
+ } else {
+ $config[$name] = $value;
+ }
+ }
+
+ return $config;
+ }
+
+ /**
+ * Set an option
+ *
+ * ##### Options
+ *
+ * - **global** (_boolean_) Read or write configuration options for the current user
+ * - **system** (_boolean_) Read or write configuration options for all users on the current machine
+ *
+ * @param string $name The name of the option
+ * @param string $value The value to set
+ * @param array $options [optional] An array of options {@see ConfigCommand::setDefaultOptions}
+ *
+ * @throws GitException
+ * @return bool
+ */
+ public function set($name, $value, array $options = array())
+ {
+ $options = $this->resolve($options);
+ $builder = $this->git->getProcessBuilder()
+ ->add('config');
+
+ $this->addFlags($builder, $options, array('global', 'system'));
+
+ $builder->add($name)->add($value);
+ $process = $builder->getProcess();
+ $this->git->run($process);
+
+ return true;
+ }
+
+ /**
+ * Adds a new line to the option without altering any existing values
+ *
+ * ##### Options
+ *
+ * - **global** (_boolean_) Read or write configuration options for the current user
+ * - **system** (_boolean_) Read or write configuration options for all users on the current machine
+ *
+ * @param string $name The name of the option
+ * @param string $value The value to add
+ * @param array $options [optional] An array of options {@see ConfigCommand::setDefaultOptions}
+ *
+ * @throws GitException
+ * @return bool
+ */
+ public function add($name, $value, array $options = array())
+ {
+ $options = $this->resolve($options);
+ $builder = $this->git->getProcessBuilder()
+ ->add('config');
+
+ $this->addFlags($builder, $options, array('global', 'system'));
+
+ $builder->add('--add')->add($name)->add($value);
+ $process = $builder->getProcess();
+ $this->git->run($process);
+
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * - **global** (_boolean_) Read or write configuration options for the current user
+ * - **system** (_boolean_) Read or write configuration options for all users on the current machine
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ $resolver->setDefaults(array(
+ 'global' => false,
+ 'system' => false,
+ ));
+ }
+
+} \ No newline at end of file