. */ namespace danog\MadelineProto; /** * Some tools. */ class Tools { /** * posmod(numeric,numeric) : numeric * Works just like the % (modulus) operator, only returns always a postive number. */ public static function posmod($a, $b) { $resto = $a % $b; if ($resto < 0) { $resto += abs($b); } return $resto; } public static function fread_all($handle) { $pos = ftell($handle); fseek($handle, 0); $content = fread($handle, fstat($handle)['size']); fseek($handle, $pos); return $content; } public static function fopen_and_write($filename, $mode, $data) { $handle = fopen($filename, $mode); fwrite($handle, $data); rewind($handle); return $handle; } public static function string2bin($string) { $res = null; foreach (explode('\\', $string) as $s) { if ($s != null && strlen($s) == 3) { $res .= hex2bin(substr($s, 1)); } } return $res; } // taken from mochikit: range( [start,] stop[, step] ) public static function range($start, $stop = null, $step = 1) { if ($stop === null) { $stop = $start; $start = 0; } if ($stop <= $start && $step < 0) { $arr = range($stop, $start, -$step); array_pop($arr); return array_reverse($arr, false); } if ($step > 1 && $step > ($stop - $start)) { $arr = [$start]; } else { $arr = range($start, $stop, $step); array_pop($arr); } return $arr; } }