improve "x" option, add syndication option
authorChristian Weiske <cweiske@cweiske.de>
Mon, 12 Sep 2016 13:14:07 +0000 (15:14 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 12 Sep 2016 13:14:07 +0000 (15:14 +0200)
src/shpub/Command/Note.php
src/shpub/Request.php

index 6fb7ceca34d0def575b79756ee9a7e3e1f369d4d..cc3a5c178aba0e3081d3331321d3f167238baaf4 100644 (file)
@@ -48,6 +48,17 @@ class Command_Note
                 'default'     => null,
             )
         );
                 'default'     => null,
             )
         );
+        $cmd->addOption(
+            'syndication',
+            array(
+                'short_name'  => '-s',
+                'long_name'   => '--syndication',
+                'description' => 'Syndication URL(s)',
+                'help_name'   => 'URL',
+                'action'      => 'StoreArray',
+                'default'     => [],
+            )
+        );
         $cmd->addOption(
             'x',
             array(
         $cmd->addOption(
             'x',
             array(
@@ -80,10 +91,15 @@ class Command_Note
             );
         }
         if (count($command->options['categories'])) {
             );
         }
         if (count($command->options['categories'])) {
-            $req->req->addPostParameter(
+            $req->addPostParameter(
                 'category', $command->options['categories']
             );
         }
                 'category', $command->options['categories']
             );
         }
+        if (count($command->options['syndication'])) {
+            $req->addPostParameter(
+                'syndication', $command->options['syndication']
+            );
+        }
 
         $files = $command->options['files'];
         $fileList = $urlList = [
 
         $files = $command->options['files'];
         $fileList = $urlList = [
@@ -127,7 +143,7 @@ class Command_Note
                 $n = 0;
                 foreach ($urls as $url) {
                     $req->req->addPostParameter(
                 $n = 0;
                 foreach ($urls as $url) {
                     $req->req->addPostParameter(
-                        $type . '[' . $n++ . ']', reset($urls)
+                        $type . '[' . $n++ . ']', $url
                     );
                 }
             }
                     );
                 }
             }
@@ -144,9 +160,16 @@ class Command_Note
         }
 
         if (count($command->options['x'])) {
         }
 
         if (count($command->options['x'])) {
+            $postParams = [];
             foreach ($command->options['x'] as $xproperty) {
                 list($propkey, $propval) = explode('=', $xproperty, 2);
             foreach ($command->options['x'] as $xproperty) {
                 list($propkey, $propval) = explode('=', $xproperty, 2);
-                $req->req->addPostParameter($propkey, $propval);
+                if (!isset($postParams[$propkey] )) {
+                    $postParams[$propkey] = [];
+                }
+                $postParams[$propkey][] = $propval;
+            }
+            foreach ($postParams as $propkey => $propvals) {
+                $req->addPostParameter($propkey, $propvals);
             }
         }
 
             }
         }
 
index edca12aae84749c8d71b57cd462bbd251d797b2b..0924ddae1cf54ba725636b4294e336b2db895dc7 100644 (file)
@@ -53,6 +53,21 @@ class Request
         return $this->req->addUpload($fieldName, $filename);
     }
 
         return $this->req->addUpload($fieldName, $filename);
     }
 
+    /**
+     * Add one or multiple POST parameters.
+     * Automatically adds them as array or as string.
+     *
+     * @param string       $key    Parameter name
+     * @param string|array $values One or multiple values
+     */
+    public function addPostParameter($key, $values)
+    {
+        if (count($values) == 1) {
+            $values = reset($values);
+        }
+        $this->req->addPostParameter($key, $values);
+    }
+
     protected function printCurl()
     {
         $command = 'curl';
     protected function printCurl()
     {
         $command = 'curl';