diff --git a/module/Application/src/Application/ProjectUrlValidator.php b/module/Application/src/Application/ProjectUrlValidator.php new file mode 100644 index 0000000..4c76a5a --- /dev/null +++ b/module/Application/src/Application/ProjectUrlValidator.php @@ -0,0 +1,58 @@ +errors['invalid-url'] = "Invalid URL"; + } + + if (strpos($value, '/..') !== false) { + $this->errors['hax0r'] = "URL contains invalid characters"; + } + + if (!in_array(parse_url($value, PHP_URL_HOST), ['github.com', 'bitbucket.org', 'www.github.com', 'www.bitbucket.org'])) { + $this->errors['invalid-host'] = "Invalid Git host. Only github.com and bitbucket.org are supported."; + } + + if ($this->errors) { + return false; + } + + return true; + } + + /** + * Returns an array of messages that explain why the most recent isValid() + * call returned false. The array keys are validation failure message identifiers, + * and the array values are the corresponding human-readable message strings. + * + * If isValid() was never called or if the most recent isValid() call + * returned true, then this method returns an empty array. + * + * @return array + */ + public function getMessages() + { + return $this->errors; + } +}