diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php index 2549e5cc..8c38dc21 100644 --- a/PHPCI/Command/InstallCommand.php +++ b/PHPCI/Command/InstallCommand.php @@ -43,6 +43,11 @@ class InstallCommand extends Command $dbUser = $this->ask('Enter your MySQL username: '); $dbPass = $this->ask('Enter your MySQL password: ', true); $ciUrl = $this->ask('Your PHPCI URL (without trailing slash): '); + // verify url format and re-ask if wrong + while(! $this->controlFormat($ciUrl,array(FILTER_VALIDATE_URL,"/[^\/]$/i"),$status)) { + print $status; + $ciUrl = $this->ask('Your PHPCI URL (without trailing slash): '); + } $ghId = $this->ask('(Optional) Github Application ID: ', true); $ghSecret = $this->ask('(Optional) Github Application Secret: ', true); @@ -52,6 +57,7 @@ class InstallCommand extends Command shell_exec($cmd); + $str = "controlFormat($adminEmail,FILTER_VALIDATE_EMAIL,$status)) { + print $status; + $adminEmail = $this->ask('Enter your email address (leave blank if updating): '); + } + } $adminPass = $this->ask('Enter your desired admin password: '); $adminName = $this->ask('Enter your name: '); @@ -125,4 +138,39 @@ b8\Database::setReadServers(array('{$dbHost}')); return $rtn; } + protected function controlFormat($valueToInspect,$filter,&$statusMessage) + { + $filters = !(is_array($filter))? array($filter) : $filter; + $statusMessage = ''; + $status = true; + $options = array(); + + foreach ($filters as $filter) { + if (! is_int($filter)) { + $regexp = $filter; + $filter = FILTER_VALIDATE_REGEXP; + $options = array( + 'options' => array( + 'regexp' => $regexp, + ) + ); + } + if (! filter_var($valueToInspect,$filter,$options)) { + $status = false; + switch ($filter) + { + case FILTER_VALIDATE_URL : + $statusMessage = 'Incorrect url format.' . PHP_EOL; + break; + case FILTER_VALIDATE_EMAIL : + $statusMessage = 'Incorrect e-mail format.' . PHP_EOL; + break; + case FILTER_VALIDATE_REGEXP : + $statusMessage = 'Incorrect format.' . PHP_EOL; + break; + } + } + } + return $status; + } }