<?php
namespace WpInstaller\Parameter;
class Validator
{
public static function validate_cpanel_user($user, $allOptions)
{
$user_info = posix_getpwnam($user);
if (!$user_info) {
throw new \Exception("Given user: {$user} does not exist on this system.");
}
}
public static function validate_install_path($path, $allOptions)
{
$username = $allOptions['cpanel_user'];
// Make sure the given path exists within the user's homedirectory
$user_info = posix_getpwnam($username);
if (!$user_info) {
throw new \Exception("{$username} is not a valid user.");
}
$homedir = $user_info['dir'];
if (empty($homedir)) {
throw new \Exception("Failed to determine home directory for user: {$username}");
}
if(strpos($path, $homedir) !== 0) {
throw new \Exception('Install path is not in the user\'s home directory');
}
}
public static function validate_site_url($url, $allOptions)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new \Exception("{$url} is not a valid URL");
}
}
public static function validate_wp_admin_email($email, $allOptions)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \Exception("{$email} is not a valid email address");
}
}
}