Add "json" option
[shpub.git] / src / shpub / Validator.php
index f7f3605d103b999cfee3a314fdd4e48a0922958d..c7515953c57812efdd227647889e9e1fe5967da9 100644 (file)
@@ -16,11 +16,30 @@ class Validator
         }
 
         if (!isset($parts['host'])) {
-            Log::err('Invalid URL: No host in ' . $helpName);
-            return false;
+            if (count($parts) == 1 && isset($parts['path'])) {
+                //parse_url('example.org') puts 'example.org' in the path
+                // but this is common, so we fix it.
+                $url = 'http://' . $parts['path'];
+            } else {
+                Log::err('Invalid URL: No host in ' . $helpName);
+                return false;
+            }
         }
 
         return $url;
     }
+
+    public static function rsvp($answer)
+    {
+        $allowed = ['yes', 'no', 'maybe'];
+        if (false === array_search($answer, $allowed)) {
+            Log::err(
+                'Invalid RSVP answer given; allowed are: '
+                . implode(', ', $allowed)
+            );
+            return false;
+        }
+        return $answer;
+    }
 }
 ?>