date.chapril.org-framadate/app/classes/Framadate/Services/InputService.php
2014-12-17 13:17:08 +01:00

28 lines
648 B
PHP

<?php
namespace Framadate\Services;
/**
* This class helps to clean all inputs from the users or external services.
*/
class InputService {
function __construct() {}
/**
* This method filter an array calling "filter_var" on each items.
* Only items validated are added at their own indexes, the others are not returned.
*/
function filterArray($arr, $type, $options) {
$newArr = [];
foreach($arr as $id=>$item) {
$item = filter_var($item, $type, $options);
if ($item !== false) {
$newArr[$id] = $item;
}
}
return $newArr;
}
}