/** * Returns singleton. * * @return Cleaner_Engine Singleton */ public static function getInstance() { if (self::$_instance === null) { self::$_instance = new Cleaner_Engine(); } return self::$_instance; }
/** * Sanitize value to 'Numeric'. * * @param mixed $value Value to sanitizes. * * @return mixed Sanitized value. */ public function sanitizeNumeric($value) { $instance = Cleaner_Engine::getInstance(); $floatSanitizer = $instance->getSanitizer('float'); return (string) $floatSanitizer->sanitize($value); }
/** * Creates a new Instance (Singleton) of Cleaner. * * @return void */ protected function __construct() { $this->_configuration = Cleaner_Engine::_getInstance(); $this->_cages = array(self::INPUT_SCOPE_GET => Cleaner_Cage::getInstance($_GET, self::INPUT_SCOPE_GET), self::INPUT_SCOPE_POST => Cleaner_Cage::getInstance($_POST, self::INPUT_SCOPE_POST), self::INPUT_SCOPE_REQUEST => Cleaner_Cage::getInstance($_REQUEST, self::INPUT_SCOPE_REQUEST), self::INPUT_SCOPE_COOKIE => Cleaner_Cage::getInstance($_COOKIE, self::INPUT_SCOPE_COOKIE), self::INPUT_SCOPE_FILES => Cleaner_Cage::getInstance($_FILES, self::INPUT_SCOPE_FILES), self::INPUT_SCOPE_SESSION => Cleaner_Cage::getInstance($_SESSION, self::INPUT_SCOPE_SESSION), self::INPUT_SCOPE_ENV => Cleaner_Cage::getInstance($_ENV, self::INPUT_SCOPE_ENV), self::INPUT_SCOPE_SERVER => Cleaner_Cage::getInstance($_SERVER, self::INPUT_SCOPE_SERVER)); if (isset($GLOBALS['HTTP_SERVER_VARS'])) { $GLOBALS['HTTP_SERVER_VARS'] = null; } if (isset($GLOBALS['HTTP_GET_VARS'])) { $GLOBALS['HTTP_GET_VARS'] = null; } if (isset($GLOBALS['HTTP_POST_VARS'])) { $GLOBALS['HTTP_POST_VARS'] = null; } if (isset($GLOBALS['HTTP_COOKIE_VARS'])) { $GLOBALS['HTTP_COOKIE_VARS'] = null; } if (isset($GLOBALS['HTTP_ENV_VARS'])) { $GLOBALS['HTTP_ENV_VARS'] = null; } if (isset($GLOBALS['HTTP_SESSION_VARS'])) { $GLOBALS['HTTP_SESSION_VARS'] = null; } if (isset($GLOBALS['HTTP_REQUEST_VARS'])) { $GLOBALS['HTTP_REQUEST_VARS'] = null; } if (isset($GLOBALS['HTTP_FILES_VARS'])) { $GLOBALS['HTTP_FILES_VARS'] = null; } }
/** * Validates an item in the wrapped scope for a certain type and if * invalid sanitizes the value of the parameter/item. * * @param string $type Type of parameter/item to validate and/or sanitize. * @param string $name Name of parameter / Name of item in scope. * @param boolean $empty Must parameter/item be not null or empty. * @param mixed $default Return value, if parameter/item and/or sanitizesparameter/item is null/empty/notset/... * @param boolean $sanitize Wheather sanitize value of parameter/item, when value is invalid. * * @return Cleaner_Parameter Instance, representing selected parameter/item in Scope. */ public function getParameter($type, $name, $empty = false, $default = null, $sanitize = true) { $messages = Cleaner_Engine::getMessages(); if (!isset($this->_scope[$name]) || Cleaner_Util::isBlank($this->_scope[$name])) { if (!$empty) { $messages->add('INVALID_REQUIRED'); } return new Cleaner_Parameter(null, null, $default, $empty, false, true, $messages, $type, $name, $this->_key); } $engine = Cleaner_Engine::getInstance(); $value = $this->_scope[$name]; if ($engine->validate($type, $value, $messages)) { return new Cleaner_Parameter(null, $value, $default, true, false, false, $messages, $type, $name, $this->_key); } if (!$sanitize) { return new Cleaner_Parameter(null, $value, $default, false, false, false, $messages, $type, $name, $this->_key); } $clean = $engine->sanitze($type, $value, $messages); if (is_null($clean)) { if (!$empty) { $messages->add('SANITIZE_DEFAULT'); } return new Cleaner_Parameter(null, null, $default, $empty, true, true, $messages, $type, $name, $this->_key); } return new Cleaner_Parameter($clean, $value, $default, false, true, false, $messages, $type, $name, $this->_key); }