@ 2014-10-04T00:44:02Z <?php
class __Utils
{
public static function setHeader(string $header, $variable, $replace = false, $httpresponse = null)
{
if($httpresponse !== null) {
header("$header: $variable", $replace, $httpresponse);
} else {
header("$header: $variable", $replace);
}
}
public static function setHeaders(array $headers)
{
foreach($headers as $header => $variables){
if(is_array($variables)) {
$replace = (isset($variables[1]) && self::isBoolean($variables[1])) ? $variables[1] : true;
if( isset($variables[2]) && self::isInteger($variables[2]) ) {
self::setHeader($header, $variables[0], $replace, $variables[2]);
} else {
self::setHeader($header, $variables[0], $replace);
}
} else {
self::setHeader($header, $variables);
}
}
}
public static function spaces($count, $htmlentities = true)
{
$spaces = str_repeat(' ', (int) $count);
return ($htmlentities) ? $spaces : str_replace(' ', '', $spaces);
}
public static function tabs($count, $tabsize = 6)
{
return self::spaces(((int) $tabsize * (int) $count));
}
public static function lineBreaks($count, $heightpx = 16) {
return str_repeat('<br style="height: ' . $heightpx . 'px;" />', (int) $count);
}
public static function isArray($variable)
{
return (is_array($variable));
}
public static function isBoolean($variable)
{
return (is_bool($variable));
}
public static function isString($variable)
{
return (is_string($variable));
}
public static function isNull($variable)
{
return (is_null($variable));
}
public static function isCallable($variable)
{
return (is_callable($variable));
}
public static function isObject($variable)
{
return (is_object($variable));
}
public static function isDouble($variable)
{
return (is_double($variable));
}
public static function isFloat($variable)
{
return (is_float($variable));
}
public static function isInteger($variable)
{
return (is_int($variable));
}
public static function isLong($variable)
{
return (is_long($variable));
}
public static function isResource($variable)
{
return (is_resource($variable));
}
public static function getVarType($variable)
{
$typecases = array(
"array" => self::isArray($variable),
"boolean" => self::isBoolean($variable),
"string" => self::isString($variable),
"null" => self::isNull($variable),
"callable" => self::isCallable($variable),
"object" => self::isObject($variable),
"double" => self::isDouble($variable),
"integer" => self::isInteger($variable),
"float" => self::isFloat($variable),
"long" => self::isLong($variable),
"resource" => self::isResource($variable)
);
foreach($typecases as $type => $bool){
if($bool) return $type;
}
}
public static function nocacheHaders()
{
if (!headers_sent()) {
self::setHeaders(array(
"Expires" => "Wed, 11 Jan 1984 05:00:00 GMT",
"Last-Modified" => gmdate( 'D, d M Y H:i:s' ) . " GMT",
"Cache-Control" => "no-cache, must-revalidate, max-age=0",
"Pragma" => "no-cache",
));
}
}
public static function stripSpace(string $string)
{
return str_replace(' ', '', preg_replace('/\s+/', '', $string));
}
public static function sanitize(string $string)
{
$sanitized = $string;
$sanitized = strip_tags($sanitized);
$sanitized = htmlspecialchars($sanitized, ENT_QUOTES, 'utf-8');
$sanitized = htmlentities($sanitized, ENT_HTML5, 'utf-8');
return $sanitized;
}
public static function dumpVar($variable, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1)
{
$return = '';
$wrapper = ($dopre === null) ? 'none' : ((self::isBoolean($dopre)) ? (($dopre) ? 'pre' : 'div' ) : $dopre );
$class = ($styles) ? 'styled' : 'nostyles';
$settings = array(
'wrappers' => array(
'none' => '%s',
'pre' => '<pre class="vardump ' . $class . '">%s</pre>',
'div' => '<div class="vardump ' . $class . '">%s</div>'
),
'sprintf' => array(
'vartype' => '<span class="vartype">%s</span>',
'specialvartype' => '<span class="specialvartype">%s</span>',
'parentheses' => '<span class="parentheses">(</span><span class="parcont">%s</span><span class="parentheses">)</span>',
'string' => '<span class="misc">"%s"</span>',
'raw' => '<span class="misc">%s</span>',
'arrkey' => '<span class="misc">' . self::tabs($tabamt) . '[%s]</span>',
'arrsep' => '<span class="arrsep">=></span>'
),
);
switch(self::getVarType($variable)) {
case "boolean":
$return .= sprintf($settings['sprintf']['vartype'], 'bool') . sprintf($settings['sprintf']['parentheses'], (string) $variable ? 'true' : 'false');
break;
case "integer":
$return .= sprintf($settings['sprintf']['vartype'], 'int') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "double":
$return .= sprintf($settings['sprintf']['vartype'], 'double') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "float":
$return .= sprintf($settings['sprintf']['vartype'], 'float') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "string":
$return .= sprintf($settings['sprintf']['vartype'], 'string') . sprintf($settings['sprintf']['parentheses'], (string) strlen($variable)) . " " . sprintf($settings['sprintf']['string'], $variable);
break;
case "null":
$return .= sprintf($settings['sprintf']['specialvartype'], 'NULL');
break;
case "array":
$brackets = array('{');
foreach($variable as $key => $value) {
$brackets[] = sprintf($settings['sprintf']['arrkey'], $key) . " " . $settings['sprintf']['arrsep'] . " " . self::dumpVar($value, true, null, $styles, $tabamt + 1) . ',';
}
$brackets[] = ($tabamt < 2) ? '}' : self::tabs(($tabamt - 1)) . '}';
$brackets = ($dopre) ? implode("\n", $brackets) : implode('<br />', $brackets);
$return .= sprintf($settings['sprintf']['vartype'], 'array') . sprintf($settings['sprintf']['parentheses'], (string) count($variable)) . " " . $brackets;
break;
case "object":
$reflclass = new ReflectionClass($variable);
$constants = $reflclass->getConstants();
$variables = $reflclass->getProperties();
$methods = $reflclass->getMethods();
$brackets = array('{');
foreach($constants as $name => $value) {
$brackets[] = self::tabs($tabamt) . sprintf($settings['sprintf']['raw'], 'CONST ' . $name) . ' ' . self::dumpVar($value, true, null, $styles);
}
foreach($variables as $var) {
}
$return .= sprintf($settings['sprintf']['vartype'], 'object') . sprintf($settings['sprintf']['parentheses'], get_class($variable));
break;
default:
$return .= sprintf($settings['sprintf']['specialvartype'], 'UNKNOWN TYPE') . ' ' . sprintf($settings['sprintf']['raw'], var_export($variable, true));
break;
}
if($dopre) $return = str_ireplace(' ', ' ', $return);
$returnwrapper = (array_key_exists($wrapper, $settings['wrappers'])) ? $settings['wrappers'][$wrapper] : $settings['wrappers']['none'];
$return = sprintf($returnwrapper, $return);
if($doreturn) return $return;
echo $return;
}
public static function dumpVars($variables, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1)
{
$return = array();
foreach($variables as $var) {
$return[] = self::dumpVar($var, true, $dopre, $styles, $tabamt);
}
$return = implode(self::lineBreaks(1), $return);
if($doreturn) return $return;
echo $return;
}
public static function outputData(string $filename, string $content = null, $mimetype = "auto")
{
$mimetype =
(is_file($filename)) ?
finfo_file(finfo_open(FILEINFO_MIME, pathinfo($content, PATHINFO_DIRNAME), $content)) :
($mimetype == "auto") ? "application/force-download" :
$mimetype;
if(!headers_sent()) {
$output = is_null($content) ? file_get_contents($file) : $content;
self::setHeaders(array(
"Pragma" => "public",
"Expires" => "0",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Cache-Control" => array("private", FALSE),
"Content-Disposition" => "attatchment; filename=" . basename(str_replace('"', '', $filename)) . '";',
"Content-Type" => $mimetype,
"Content-Transer-Encoding" => "binary",
"Content-Length" => strlen($output),
));
ob_clean();
flush();
echo $output;
exit();
}
}
public static function forceDownload($file, $content = null)
{
self::outputData($file, $content, "application/force-download");
}
public static function uniqueId($prefix = null, $format = '{35}') // Ex: {8}-{4}-{4}-{4}-{12} will return something like XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
{
$uniqueid = $prefix;
$alpha = range('a', 'z', 1);
$alphacase = range('A', 'Z', 1);
$num = range('1', '999', 1);
$rand1 = array_rand($alpha, 5);
$rand2 = array_rand($alphacase, 5);
$rand3 = array_rand($num, 5);
$rand = array_merge($rand1, $rand2, $rand3);
$datetime = new DateTime('now', new DateTimeZone('America/New_York'));
$timestamp = $datetime->format('c');
$uniqueid .= implode('', $rand) . "_" . $timestamp . "_" . uniqid();
$origuniqueid = $uniqueid;
foreach(hash_algos() as $algo) {
$uniqueid = hash($algo, $uniqueid . "_" . $timestamp . "_" . uniqid());
}
$uniqueid = md5($uniqueid);
$chararrays = array();
$finaluniqueid = '';
$amount = 10;
for($time = $amount; $time > 0; $time--) {
$chararrays[$time] = str_split($uniqueid);
shuffle($chararrays[$time]);
$finaluniqueid .= implode('', array_slice($chararrays[$time], rand(0, (count($chararrays[$time]) - 1)), rand(0, (count($chararrays[$time]) - 1))));
}
$finaluniqueid = str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid);
$formateduniqueid = $format;
$substart = 0;
preg_match_all('([0-9]+)', $format, $ints);
foreach($ints[0] as $int) {
if($newi > strlen($formateduniqueid) ) $newi = strlen($formateduniqueid);
$substr = substr($finaluniqueid, $substart, ((int) $int));
$formateduniqueid = preg_replace('/\{' . $int . '\}/', $substr, $formateduniqueid, 1);
$substart = $substart + ((int) $int);
}
return $formateduniqueid;
}
public static function getRelativePath($from, $to)
{
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
$from = str_replace('\\', '/', $from);
$to = str_replace('\\', '/', $to);
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach($from as $depth => $dir) {
if($dir === $to[$depth]) {
array_shift($relPath);
} else {
$remaining = count($from) - $depth;
if($remaining > 1) {
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './' . $relPath[0];
}
}
}
return implode('/', $relPath);
}
public static function arrayList(array $array, $withkeys = false, $keysep = ': ') {
if($withkeys) {
foreach($array as $k => $v) {
$array[$k] = $k . $keysep . $v;
}
}
switch(count($array)) {
case 1:
return implode('', $array);
break;
case 2:
return implode(' and ', $array);
break;
case 3:
$arrv = array_values($array);
$array[array_search($arrv[(count($arrv) - 1)], $array)] = 'and ' . $array[array_search($arrv[(count($arrv) - 1)], $array)];
$output = implode(', ', $array);
if(strtoupper(Locale::getRegion(Locale::getDefault())) === 'GB') $output = str_replace(', and', ' and ', $output);
return $output;
}
}
public static function pluckArrays($key, $value, $arrays) {
$return = array();
foreach($arrays as $array) {
if($array[$key] === $value) {
$return[] = $array;
}
}
return $return;
}
public static function addQuotes($string, $quote = '"') {
return $quote . $string . $quote;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.012 0.006 18.30 8.3.5 0.015 0.007 21.93 8.3.4 0.014 0.007 18.98 8.3.3 0.013 0.003 19.04 8.3.2 0.004 0.004 20.54 8.3.1 0.004 0.004 20.59 8.3.0 0.005 0.003 19.66 8.2.18 0.013 0.007 16.75 8.2.17 0.006 0.009 22.96 8.2.16 0.007 0.007 20.59 8.2.15 0.005 0.003 24.18 8.2.14 0.005 0.003 24.66 8.2.13 0.008 0.000 26.16 8.2.12 0.004 0.004 22.23 8.2.11 0.008 0.003 20.93 8.2.10 0.008 0.004 17.63 8.2.9 0.004 0.004 19.34 8.2.8 0.009 0.000 17.97 8.2.7 0.000 0.009 17.49 8.2.6 0.008 0.000 17.93 8.2.5 0.005 0.003 18.10 8.2.4 0.000 0.008 18.34 8.2.3 0.006 0.003 19.41 8.2.2 0.004 0.004 17.87 8.2.1 0.004 0.004 18.14 8.2.0 0.000 0.008 17.69 8.1.28 0.009 0.006 25.92 8.1.27 0.000 0.009 22.35 8.1.26 0.008 0.000 26.35 8.1.25 0.008 0.000 28.09 8.1.24 0.008 0.004 22.29 8.1.23 0.004 0.008 19.30 8.1.22 0.005 0.003 17.74 8.1.21 0.006 0.003 18.77 8.1.20 0.006 0.003 17.35 8.1.19 0.004 0.004 17.35 8.1.18 0.006 0.003 18.10 8.1.17 0.003 0.006 18.57 8.1.16 0.007 0.000 22.10 8.1.15 0.008 0.000 18.93 8.1.14 0.003 0.006 17.61 8.1.13 0.008 0.000 18.00 8.1.12 0.004 0.004 17.57 8.1.11 0.006 0.003 17.56 8.1.10 0.005 0.003 17.48 8.1.9 0.004 0.004 17.54 8.1.8 0.003 0.005 17.50 8.1.7 0.000 0.008 17.50 8.1.6 0.000 0.008 17.68 8.1.5 0.000 0.008 17.52 8.1.4 0.000 0.009 17.52 8.1.3 0.000 0.008 17.69 8.1.2 0.004 0.004 17.75 8.1.1 0.005 0.003 17.57 8.1.0 0.008 0.000 17.43 8.0.30 0.005 0.003 18.77 8.0.29 0.000 0.008 16.88 8.0.28 0.004 0.004 18.43 8.0.27 0.004 0.004 17.35 8.0.26 0.007 0.000 17.41 8.0.25 0.000 0.007 17.00 8.0.24 0.003 0.003 16.98 8.0.23 0.000 0.008 17.11 8.0.22 0.004 0.004 16.96 8.0.21 0.000 0.008 16.95 8.0.20 0.000 0.007 17.12 8.0.19 0.005 0.003 17.16 8.0.18 0.006 0.003 17.05 8.0.17 0.003 0.006 17.04 8.0.16 0.003 0.005 17.03 8.0.15 0.004 0.004 16.94 8.0.14 0.008 0.000 16.89 8.0.13 0.006 0.000 13.43 8.0.12 0.004 0.004 17.02 8.0.11 0.006 0.003 16.89 8.0.10 0.004 0.004 17.00 8.0.9 0.004 0.004 17.05 8.0.8 0.003 0.012 16.98 8.0.7 0.000 0.008 16.94 8.0.6 0.005 0.003 17.02 8.0.5 0.004 0.004 17.15 8.0.3 0.006 0.013 17.17 8.0.2 0.013 0.012 17.40 8.0.1 0.008 0.000 17.05 8.0.0 0.008 0.011 16.82 7.4.33 0.002 0.005 15.00 7.4.32 0.007 0.000 16.65 7.4.30 0.005 0.003 16.73 7.4.29 0.004 0.004 16.74 7.4.28 0.007 0.003 16.55 7.4.27 0.000 0.009 16.64 7.4.26 0.004 0.004 16.71 7.4.25 0.000 0.008 16.63 7.4.24 0.005 0.002 16.58 7.4.23 0.004 0.004 16.45 7.4.22 0.006 0.013 16.61 7.4.21 0.007 0.010 16.72 7.4.20 0.000 0.008 16.80 7.4.16 0.009 0.009 16.42 7.4.15 0.016 0.003 17.40 7.4.14 0.013 0.007 17.86 7.4.13 0.007 0.010 16.58 7.4.12 0.008 0.010 16.82 7.4.11 0.010 0.007 16.48 7.4.10 0.008 0.015 16.67 7.4.9 0.006 0.011 16.64 7.4.8 0.012 0.006 16.63 7.4.7 0.006 0.010 16.73 7.4.6 0.007 0.014 16.56 7.4.5 0.009 0.000 16.72 7.4.4 0.009 0.008 16.49 7.4.3 0.007 0.010 16.54 7.4.0 0.015 0.000 14.86 7.3.33 0.003 0.003 13.40 7.3.32 0.004 0.004 13.39 7.3.31 0.003 0.003 16.25 7.3.30 0.003 0.004 16.27 7.3.29 0.000 0.014 16.28 7.3.28 0.006 0.008 16.36 7.3.27 0.011 0.008 17.40 7.3.26 0.010 0.010 16.45 7.3.25 0.009 0.012 16.43 7.3.24 0.003 0.014 16.36 7.3.23 0.011 0.007 16.61 7.3.21 0.011 0.007 16.45 7.3.20 0.010 0.009 19.39 7.3.19 0.011 0.011 16.53 7.3.18 0.006 0.010 16.53 7.3.17 0.006 0.014 16.52 7.3.16 0.013 0.004 16.68 7.3.1 0.006 0.010 16.73 7.3.0 0.008 0.010 16.44 7.2.33 0.006 0.012 16.63 7.2.32 0.006 0.012 16.38 7.2.31 0.011 0.007 16.50 7.2.30 0.015 0.003 16.79 7.2.29 0.010 0.010 16.65 7.2.13 0.006 0.012 16.77 7.2.12 0.004 0.016 16.79 7.2.11 0.011 0.003 16.83 7.2.10 0.007 0.004 16.78 7.2.9 0.006 0.006 16.52 7.2.8 0.004 0.012 16.54 7.2.7 0.014 0.000 16.93 7.2.6 0.010 0.006 16.65 7.2.5 0.003 0.009 16.67 7.2.4 0.010 0.003 16.85 7.2.3 0.000 0.012 16.66 7.2.2 0.006 0.009 16.66 7.2.1 0.007 0.011 16.63 7.2.0 0.003 0.009 17.87 7.1.25 0.004 0.011 15.36 7.1.10 0.006 0.006 17.73 7.1.7 0.004 0.004 16.96 7.1.6 0.012 0.012 19.32 7.1.5 0.013 0.013 16.94 7.1.0 0.003 0.077 22.36 7.0.20 0.002 0.005 16.49 7.0.14 0.007 0.067 21.93 7.0.10 0.023 0.080 20.25 7.0.9 0.003 0.090 20.07 7.0.8 0.010 0.073 20.10 7.0.7 0.037 0.077 20.34 7.0.6 0.033 0.087 20.27 7.0.5 0.033 0.073 20.50 7.0.4 0.007 0.083 20.13 7.0.3 0.010 0.060 20.18 7.0.2 0.013 0.060 20.11 7.0.1 0.010 0.067 20.15 7.0.0 0.007 0.090 20.01 5.6.28 0.007 0.073 21.22 5.6.25 0.000 0.087 20.85 5.6.24 0.023 0.060 20.63 5.6.23 0.010 0.087 20.63 5.6.22 0.010 0.077 20.74 5.6.21 0.007 0.087 20.59 5.6.20 0.023 0.063 21.30 5.6.19 0.003 0.043 21.08 5.6.18 0.003 0.057 21.15 5.6.17 0.007 0.083 21.08 5.6.16 0.007 0.053 21.19 5.6.15 0.013 0.073 21.29 5.6.14 0.010 0.077 21.25 5.6.13 0.010 0.080 21.21 5.6.12 0.013 0.053 21.12 5.6.11 0.007 0.053 21.09 5.6.10 0.010 0.047 21.05 5.6.9 0.010 0.043 21.13 5.6.8 0.003 0.040 20.58 5.6.7 0.010 0.033 20.52 5.6.6 0.003 0.040 20.60 5.6.5 0.010 0.033 20.59 5.6.4 0.000 0.053 20.52 5.6.3 0.003 0.067 20.60 5.6.2 0.003 0.037 20.55 5.6.1 0.017 0.073 20.55 5.6.0 0.013 0.043 20.48 5.5.38 0.007 0.087 20.58 5.5.37 0.007 0.050 20.49 5.5.36 0.007 0.083 20.46 5.5.35 0.007 0.050 20.50 5.5.34 0.007 0.050 20.76 5.5.33 0.010 0.077 21.02 5.5.32 0.030 0.067 21.04 5.5.31 0.007 0.080 21.01 5.5.30 0.007 0.050 21.00 5.5.29 0.013 0.040 20.88 5.5.28 0.007 0.053 20.88 5.5.27 0.003 0.053 20.93 5.5.26 0.000 0.047 21.03 5.5.25 0.013 0.037 20.84 5.5.24 0.003 0.067 20.31 5.5.23 0.000 0.043 20.34 5.5.22 0.003 0.040 20.25 5.5.21 0.007 0.037 20.43 5.5.20 0.007 0.043 20.37 5.5.19 0.000 0.043 20.28 5.5.18 0.003 0.063 20.28 5.5.16 0.020 0.067 20.30 5.5.15 0.007 0.057 20.30 5.5.14 0.017 0.050 20.38 5.5.13 0.003 0.060 20.28 5.5.12 0.003 0.037 20.38 5.5.11 0.010 0.037 20.39 5.5.10 0.007 0.037 20.20 5.5.9 0.010 0.037 20.10 5.5.8 0.003 0.050 20.19 5.5.7 0.010 0.037 20.21 5.5.6 0.003 0.037 20.21 5.5.5 0.007 0.037 20.13 5.5.4 0.010 0.030 20.22 5.5.3 0.007 0.040 20.12 5.5.2 0.013 0.027 20.25 5.5.1 0.000 0.043 20.09 5.5.0 0.010 0.030 20.17 5.4.45 0.013 0.070 19.23 5.4.44 0.007 0.077 19.56 5.4.43 0.007 0.040 19.41 5.4.42 0.010 0.037 19.24 5.4.41 0.013 0.037 19.10 5.4.40 0.007 0.037 19.11 5.4.39 0.000 0.047 19.11 5.4.38 0.007 0.040 18.93 5.4.37 0.007 0.037 19.23 5.4.36 0.000 0.043 19.09 5.4.35 0.007 0.057 19.09 5.4.34 0.007 0.073 19.09 5.4.32 0.007 0.033 19.05 5.4.31 0.007 0.043 19.01 5.4.30 0.000 0.040 19.13 5.4.29 0.000 0.083 19.23 5.4.28 0.007 0.053 19.14 5.4.27 0.000 0.043 19.09 5.4.26 0.007 0.047 19.00 5.4.25 0.000 0.040 19.23 5.4.24 0.000 0.040 19.27 5.4.23 0.000 0.040 18.91 5.4.22 0.000 0.040 18.90 5.4.21 0.000 0.037 19.14 5.4.20 0.003 0.067 19.20 5.4.19 0.003 0.037 19.30 5.4.18 0.003 0.040 19.08 5.4.17 0.003 0.040 19.09 5.4.16 0.003 0.043 19.21 5.4.15 0.010 0.037 19.21 5.4.14 0.000 0.040 16.45 5.4.13 0.000 0.067 16.50 5.4.12 0.013 0.033 16.48 5.4.11 0.017 0.023 16.59 5.4.10 0.007 0.050 16.42 5.4.9 0.003 0.030 16.42 5.4.8 0.007 0.040 16.37 5.4.7 0.007 0.033 16.37 5.4.6 0.007 0.030 16.52 5.4.5 0.000 0.040 16.40 5.4.4 0.000 0.033 16.50 5.4.3 0.000 0.040 16.54 5.4.2 0.000 0.040 16.53 5.4.1 0.000 0.040 16.43 5.4.0 0.000 0.040 15.88
preferences:dark mode live preview
43.51 ms | 401 KiB | 5 Q