move constructor to command base class
[shpub.git] / src / shpub / Validator.php
1 <?php
2 namespace shpub;
3
4 class Validator
5 {
6     public static function url($url, $helpName)
7     {
8         $parts = parse_url($url);
9         if (!isset($parts['scheme'])) {
10             $url = 'http://' . $url;
11         } else if ($parts['scheme'] != 'http' && $parts['scheme'] != 'https') {
12             Log::err(
13                 'Invalid URL scheme in ' . $helpName . ': ' . $parts['scheme']
14             );
15             return false;
16         }
17
18         if (!isset($parts['host'])) {
19             if (count($parts) == 1 && isset($parts['path'])) {
20                 //parse_url('example.org') puts 'example.org' in the path
21                 // but this is common, so we fix it.
22                 $url = 'http://' . $parts['path'];
23             } else {
24                 Log::err('Invalid URL: No host in ' . $helpName);
25                 return false;
26             }
27         }
28
29         return $url;
30     }
31 }
32 ?>