Securise a variable

@param mixed $data The variable to securise
@param string $type The type of datas
@param boolean $htmlentities If use htmlentities function
to a better security

@return mixed

@throws \Exception If an error with a type of data
770260
public static function secureData($data, string $type, bool $htmlentities)
    {
        $currentClass = get_called_class();
        
        if (is_array($data)) {
            foreach ($data as $key => $val) {
                unset($data[$key]);

                $key = $currentClass::secureData($key, gettype($key), true);
                $val = $currentClass::secureData($val, $type, $htmlentities);

                $data[$key] = $val;
            }

            return $data;
        }

        try {
            return $currentClass::secureKnownType($data, $type);
        } catch (Exception $ex) {
            if ($ex->getCode() !== self::ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED) {
                throw new Exception($ex->getMessage(), $ex->getCode());
            }
            //Else : Use securise like if it's a text type
        }

        return $currentClass::secureUnknownType($data, $type, $htmlentities);
    }
298457
public function htmlsd($type = ENT_COMPAT)
    {
        $this->string = htmlspecialchars_decode($this->string, $type);

        return $this;
    }
706428
public function sanitize($data, $type) {
        if (strtolower($type) == "create") $rules = $this->repository->getSanitationRulesForCreate();

        if (strtolower($type) == "update") $rules = $this->repository->getSanitationRulesForUpdate();

        $sanitizedData = $this->repository->getSanitize($data, $rules);

        return $sanitizedData;
    }
270523
public function decryptByPublicKey_data($data, $publickey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($publickey != "") {
			$RSACrypt->pubkey = $publickey;
		}
		$decrypt_res = "";
		$datas = explode('@', $data);
		foreach ($datas as $value) {
			$decrypt_res = $decrypt_res . $RSACrypt->decryptByPublicKey($value);
		}
		return $decrypt_res;
	}
1211771
public function delete_attribute( $type, $data ) {
		$type = $data['type'];
		unset( $data['type'] );
		return $this->post( 'attribute/' . $type, json_encode( $data ) );
	}
948283
public function data(String $type, String $element)
    {
        $this->settings['attr']['data-'.$type] = $element;

        return $this;
    }
255712
public static function encode($data, String $type = 'unescapedUnicode') : String
    {
        return json_encode($data, Helper::toConstant($type, 'JSON_'));
    }
652395
public function get($key, $default = null, $htmlEntities = false)
    {
        if (!isset($_GET[$key])) {
            return $default;
        }

        return is_null($_GET[$key]) ? $default
            : $this->_escape($_GET[$key], $htmlEntities);
    }
1049238
public function writeString($data, $type = null)
    {
        if (!isset($type)) {
            $type = $this->_guessType($data);
        }
        return $this->_encodeValue($data, $this->_parseTypeString($type));
    }
267131
protected function crypt($data, $type = 'encrypt')
    {
        $melisConfig = $this->getServiceLocator()->get('MelisCoreConfig');
        $datas = $melisConfig->getItemPerPlatform('meliscore/datas');

        $hashMethod = $datas['accounts']['hash_method'];
        $salt = $datas['accounts']['salt'];

        if ($type == 'encrypt') {
            return base64_encode($data);
        }

        if ($type == 'decrypt') {
            return base64_decode($data);
        }

        return;
    }
919232
public function convert($type, $data)
    {
        foreach ($data as $k => $v) {
            if (is_array($v)) {
                $data[$k] = $this->convert($type, $v);
            }
        }

        switch (strtolower($type)) {
        case 'array':
            return (array) $data;
            break;
        case 'object':
            return (object) $data;
            break;
        default:
            throw new \Exception('Invalid conversion type given!');
        }
    }
1062472
protected function isOfCorrectType($data, $type, $exceptions)
    {
        if (is_object($data)) {
            if ($this->isCorrectObject($data, $type)) {
                return true;
            }
        } elseif ($this->isCorrectPrimitive($data, $type)) {
            return true;
        }

        $this->throwException($data, 'is not of type ' . $type, $exceptions);
        return false;

    }
322329
public function generateTokenSignature($data, PrivateKey $privateKey)
    {
        if (!$privateKey instanceof VirgilPrivateKey) {
            throw new VirgilCryptoException("instance of VirgilPrivateKey expected");
        }

        return $this->virgilCrypto->generateSignature($data, $privateKey);
    }
140893
protected function htmlEntityEncode($item)
    {
        if (is_array($item)) {
            array_walk_recursive($item, function (&$value) {
                $value = htmlentities($value);
            });
        } else {
            $item = htmlentities($item);
        }

        return $item;
    }
1229836
private function _setSecureArray($var) {
        if (is_array($var)) {
            foreach ($var as $key => $value) {
                $var['' . $key . ''] = $this->_setSecureArray($value);
            }
        }
        else {
            $var = htmlentities($var);
        }

        return $var;
    }
817269
public function visitArray($data, array $type, Context $context)
    {
        $this->dataStack->push($data);

        $isHash = isset($type['params'][1]);

        if (null === $this->root) {
            $this->root = $isHash ? new \ArrayObject() : array();
            $rs = &$this->root;
        } else {
            $rs = $isHash ? new \ArrayObject() : array();
        }

        $isList = isset($type['params'][0]) && !isset($type['params'][1]);

        foreach ($data as $k => $v) {
            $v = $this->navigator->accept($v, $this->getElementType($type), $context);

            if (null === $v && true !== $context->shouldSerializeNull()) {
                continue;
            }

            if ($isList) {
                $rs[] = $v;
            } else {
                $rs[$k] = $v;
            }
        }

        $this->dataStack->pop();

        return $rs;
    }
900844
public function fromPg($data, $type, Session $session)
    {
        $data = trim($data);

        if ($data === '') {
            return null;
        }

        return preg_split('/\./', $data);
    }