$val) { if (is_array($val)) { $ret = $ret & Utility::logicalAnd($val); } else { $ret = $ret & $val; } } return (bool)$ret; } /** * convinience function for automatic casting in form methods etc * * @param mixed $value * @param string $type * @return safe value for DB query, or NULL if type was not a valid one * maybe move to bootstrap? * 2008-12-12 ms */ public static function typeCast($value, $type) { switch ($type) { case 'int': $value = (int)$value; break; case 'float': $value = (float)$value; break; case 'double': $value = (double)$value; break; case 'array': $value = (array )$value; break; case 'bool': $value = (bool)$value; break; case 'string': $value = (string )$value; break; default: return null; } return $value; } /** * trim recursivly * * 2009-07-07 ms */ public static function trimDeep($value) { $value = is_array($value) ? array_map('self::trimDeep', $value) : trim($value); return $value; } /** * h() recursivly * * 2009-07-07 ms */ public static function specialcharsDeep($value) { $value = is_array($value) ? array_map('self::specialcharsDeep', $value) : htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); return $value; } /** * removes all except A-Z,a-z,0-9 and allowedChars (allowedChars array) recursivly * * 2009-07-07 ms */ public static function paranoidDeep($value) { $value = is_array($value) ? array_map('self::paranoidDeep', $value) : Sanatize::paranoid($value, $this->allowedChars); return $value; } /** * transfers/removes all < > from text (remove TRUE/FALSE) * * 2009-07-07 ms */ public static function htmlDeep($value) { $value = is_array($value) ? array_map('self::htmlDeep', $value) : Sanatize::html($value, $this->removeChars); return $value; } /** * main deep method * * 2009-07-07 ms */ public static function deep($function, $value) { $value = is_array($value) ? array_map('self::' . $function, $value) : $function($value); return $value; } /** * Flattens an array, or returns FALSE on fail. * 2011-07-02 ms */ public static function arrayFlatten($array) { if (!is_array($array)) { return false; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, self::arrayFlatten($value)); } else { $result[$key] = $value; } } return $result; } /** * Similar to array_shift but on the keys of the array * * @param array $keyValuePairs * @return string $key * like array_shift() only for keys and not values * 2011-01-22 ms */ public static function arrayShiftKeys(&$array) { foreach ($array as $key => $value) { unset($array[$key]); return $key; } } protected static $_counterStartTime; /** * returns microtime as float value * (to be subtracted right away) * * @return float * 2009-07-07 ms */ public static function microtime($precision = 8) { return round(microtime(true), $precision); } /** * @return void * 2009-07-07 ms */ public static function startClock() { self::$_counterStartTime = self::microtime(); } /** * @return float * 2009-07-07 ms */ public static function returnElapsedTime($precision = 8, $restartClock = false) { $startTime = self::$_counterStartTime; if ($restartClock) { self::startClock(); } return self::calcElapsedTime($startTime, self::microtime(), $precision); } /** * returns microtime as float value * (to be subtracted right away) * * @return float * 2009-07-07 ms */ public static function calcElapsedTime($start, $end, $precision = 8) { $elapsed = $end - $start; return round($elapsed, $precision); } }