Add "json" option
[shpub.git] / src / shpub / Command / AbstractProps.php
index 822fc77bba72636aa7fa52fd18fceff8ed815c0b..c9ea8bb1a5c323876da182ebe2c1f455afdd2ff7 100644 (file)
@@ -104,11 +104,27 @@ class Command_AbstractProps
                 'default'     => [],
             )
         );
+        static::addOptJson($cmd);
+    }
+
+    protected static function addOptJson(\Console_CommandLine_Command $cmd)
+    {
+        $cmd->addOption(
+            'json',
+            array(
+                'long_name'   => '--json',
+                'description' => 'Send request data as JSON',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
     }
 
     protected function handleGenericOptions(
         \Console_CommandLine_Result $cmdRes, Request $req
     ) {
+        $this->handleOptJson($cmdRes, $req);
+
         if ($cmdRes->options['published'] !== null) {
             $req->req->addPostParameter(
                 'published', $cmdRes->options['published']
@@ -146,7 +162,7 @@ class Command_AbstractProps
             $postParams = [];
             foreach ($cmdRes->options['x'] as $xproperty) {
                 list($propkey, $propval) = explode('=', $xproperty, 2);
-                if (!isset($postParams[$propkey] )) {
+                if (!isset($postParams[$propkey])) {
                     $postParams[$propkey] = [];
                 }
                 $postParams[$propkey][] = $propval;
@@ -157,6 +173,12 @@ class Command_AbstractProps
         }
     }
 
+    protected function handleOptJson(
+        \Console_CommandLine_Result $cmdRes, Request $req
+    ) {
+        $req->setSendAsJson($cmdRes->options['json']);
+    }
+
     protected function handleFiles(
         \Console_CommandLine_Result $cmdRes, Request $req
     ) {