Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2016 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9ee0c0dead47a973964023b3c2ce79ed to your computer and use it in GitHub Desktop.
Save anonymous/9ee0c0dead47a973964023b3c2ce79ed to your computer and use it in GitHub Desktop.
<?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