Exemplo n.º 1
0
Arquivo: Gcs.php Projeto: hhgr/hhgolf
 /**
  * Should validate the Driver settings using the \mithra62\Validate object
  * @param \mithra62\Validate $validate
  * @param array $settings
  * @param array $drivers
  * @return \mithra62\Validate
  */
 public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array())
 {
     $validate->rule('required', 'gcs_access_key')->message('{field} is required');
     $validate->rule('required', 'gcs_secret_key')->message('{field} is required');
     $validate->rule('required', 'gcs_bucket')->message('{field} is required');
     $validate->rule('gcs_connect', 'gcs_access_key', $settings)->message('Can\'t connect to {field}');
     if (!empty($settings['gcs_bucket'])) {
         $validate->rule('gcs_bucket_exists', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to exist...');
         $validate->rule('gcs_bucket_readable', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to be readable...');
         $validate->rule('gcs_bucket_writable', 'gcs_bucket', $settings)->message('Your bucket doesn\'t appear to be writable...');
     }
     return $validate;
 }
Exemplo n.º 2
0
 /**
  * Validates the given driver's data
  * @param \mithra62\Validate $validate
  * @param string $driver The name of the driver
  * @param array $data The data the driver is validating
  * @param array $locations The existing locations we may want to validate against
  * @return array
  */
 public function validateDriver(\mithra62\Validate $validate, $driver, array $data, array $locations = array())
 {
     $storage_drivers = $this->getAvailableStorageOptions();
     $validate->rule('required', 'storage_location_name')->message('{field} is required');
     //pass to the engine to validate what it needs
     if (isset($storage_drivers[$driver]) && $storage_drivers[$driver]['obj'] instanceof Storage\StorageInterface) {
         $validate = $storage_drivers[$driver]['obj']->setExistingStorageLocations($locations)->validateSettings($validate, $data);
     }
     //now we ahve to make sure we always have at least 1 location active
     if (count($locations) <= 1 && $data['storage_location_status'] != '1') {
         $validate->rule('false', 'storage_location_status')->message('{field} is required unless you have more than 1 Storage Location');
     }
     //now we ahve to make sure we always have at least 1 database location active
     if (count($locations) <= 1 && $data['storage_location_file_use'] != '1') {
         $validate->rule('false', 'storage_location_file_use')->message('{field} is required unless you have more than 1 Storage Location');
     }
     //now we ahve to make sure we always have at least 1 file location active
     if (count($locations) <= 1 && $data['storage_location_db_use'] != '1') {
         $validate->rule('false', 'storage_location_db_use')->message('{field} is required unless you have more than 1 Storage Location');
     }
     $errors = array();
     if (!$validate->val($data)) {
         $errors = $validate->getErrorMessages();
     }
     return $errors;
 }
Exemplo n.º 3
0
Arquivo: Rcf.php Projeto: hhgr/hhgolf
 /**
  * Should validate the Driver settings using the \mithra62\Validate object
  * @param \mithra62\Validate $validate
  * @param array $settings
  * @param array $drivers
  * @return \mithra62\Validate
  */
 public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array())
 {
     $validate->rule('required', 'rcf_username')->message('{field} is required');
     $validate->rule('required', 'rcf_api')->message('{field} is required');
     $validate->rule('required', 'rcf_container')->message('{field} is required');
     $validate->rule('required', 'rcf_location')->message('{field} is required');
     if (!empty($settings['rcf_username']) && !empty($settings['rcf_api']) && !empty($settings['rcf_container']) && !empty($settings['rcf_location'])) {
         if ($settings['storage_location_status'] != '1') {
             return $validate;
             //don't validate connection if disabling
         }
         $validate->rule('rcf_connect', 'rcf_username', $settings)->message('Can\'t connect to this account');
         if (!empty($settings['rcf_container'])) {
             $validate->rule('rcf_container_exists', 'rcf_container', $settings)->message('Your container doesn\'t appear to exist...');
             $validate->rule('rcf_container_readable', 'rcf_container', $settings)->message('Your container doesn\'t appear to be readable...');
             $validate->rule('rcf_container_writable', 'rcf_container', $settings)->message('Your container doesn\'t appear to be writable...');
         }
     }
     return $validate;
 }
Exemplo n.º 4
0
Arquivo: Ftp.php Projeto: hhgr/hhgolf
 /**
  * Should validate the Driver settings using the \mithra62\Validate object
  * @param \mithra62\Validate $validate
  * @param array $settings
  * @param array $drivers
  * @return \mithra62\Validate
  */
 public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array())
 {
     $validate->rule('required', 'ftp_hostname')->message('{field} is required');
     $validate->rule('required', 'ftp_username')->message('{field} is required');
     $validate->rule('required', 'ftp_password')->message('{field} is required');
     $validate->rule('required', 'ftp_port')->message('{field} is required');
     $validate->rule('numeric', 'ftp_port')->message('{field} must be a number');
     $validate->rule('required', 'ftp_timeout')->message('{field} is required');
     $validate->rule('numeric', 'ftp_timeout')->message('{field} must be a number');
     $validate->rule('required', 'ftp_store_location')->message('{field} is required');
     if (!empty($settings['ftp_hostname']) && !empty($settings['ftp_username']) && !empty($settings['ftp_password']) && !empty($settings['ftp_port'])) {
         if ($settings['storage_location_status'] != '1') {
             return $validate;
             //don't validate connection if disabling
         }
         $validate->rule('ftp_connect', 'ftp_hostname', $settings)->message('Can\'t connect to entered {field}');
         if (!empty($settings['ftp_store_location'])) {
             $settings['ftp_store_location'] = $settings['ftp_store_location'];
             $validate->rule('ftp_writable', 'ftp_store_location', $settings)->message('{field} has to be writable by the FTP user');
         }
     }
     return $validate;
 }
Exemplo n.º 5
0
 /**
  * Should validate the Driver settings using the \mithra62\Validate object
  * @param \mithra62\Validate $validate
  * @param array $settings
  * @param array $drivers
  * @return \mithra62\Validate
  */
 public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array())
 {
     $locations = $this->getExistingStorageLocations();
     $ignore = array();
     foreach ($locations as $location_id => $location) {
         if ($this->short_name == $location['storage_location_driver']) {
             if (empty($settings['location_id'])) {
                 //same driver so ensure no duplicate locations
                 $ignore[] = $location['backup_store_location'];
             }
         }
     }
     if ($ignore) {
         $validate->rule('notIn', 'backup_store_location', $ignore)->message('{field} is already setup with another Storage Location');
     }
     $validate->rule('required', 'backup_store_location')->message('{field} is required');
     $validate->rule('dir', 'backup_store_location')->message('{field} has to be a directory');
     $validate->rule('writable', 'backup_store_location')->message('{field} has to be writable');
     $validate->rule('readable', 'backup_store_location')->message('{field} has to be readable');
     return $validate;
 }
Exemplo n.º 6
0
 /**
  * Should validate the Driver settings using the \mithra62\Validate object
  * @param \mithra62\Validate $validate
  * @param array $settings
  * @param array $drivers
  * @return \mithra62\Validate
  */
 public function validateSettings(\mithra62\Validate $validate, array $settings, array $drivers = array())
 {
     $validate->rule('required', 'email_storage_attach_threshold')->message('{field} is required');
     $validate->rule('numeric', 'email_storage_attach_threshold')->message('{field} must be a number');
     $validate->rule('required', 'email_storage_emails')->message('{field} is required');
     if (!empty($settings['email_storage_emails'])) {
         $emails = explode("\n", trim($settings['email_storage_emails']));
         if ($emails != '') {
             if (!is_array($emails)) {
                 $emails = explode("\n", $emails);
             }
             foreach ($emails as $email) {
                 if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL)) {
                     $validate->rule('false', 'email_storage_emails')->message('"' . trim($email) . '" isn\'t a valid email');
                     //break;
                 }
             }
         }
     }
     return $validate;
 }