-
-
Save anonymous/9ee0c0dead47a973964023b3c2ce79ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DataValidation Class | |
* | |
* @author James Byrne <jamesbwebdev@gmail.com> | |
*/ | |
namespace Jay\System\Database; | |
class DataValidation | |
{ | |
private $filters = [ | |
'email' => FILTER_SANITIZE_EMAIL, | |
'string' => FILTER_SANITIZE_STRING, | |
'url' => FILTER_SANITIZE_URL | |
]; | |
public function sanitize($data, $type, $null = true) | |
{ | |
$data = isset($this->filters[$type]) ? filter_var($data, $this->filters[$type]) : $data; | |
if (is_null($data) && $null) { | |
return null; | |
} | |
if (is_null($data)) { | |
throw new \Exception("cannot be null"); | |
} | |
return $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment