public static function init() { $uri = explode('?', $_SERVER['REQUEST_URI']); $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false; static::$params = ['user_agent' => $_SERVER['HTTP_USER_AGENT'], 'status' => $_SERVER['REDIRECT_STATUS'], 'host' => $_SERVER['SERVER_NAME'], 'port' => $_SERVER['SERVER_PORT'], 'ip_address' => $_SERVER['REMOTE_ADDR'], 'method' => strtolower($_SERVER['REQUEST_METHOD']), 'query_string' => $_SERVER['QUERY_STRING'], 'uri' => $uri[0], 'ajax' => $ajax, 'accept' => $_SERVER['HTTP_ACCEPT'], 'accept_encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], 'accept_language' => $_SERVER['HTTP_ACCEPT_LANGUAGE']]; if (isset($_POST['_method'])) { static::$params['method'] = strtolower($_POST['_method']); unset($_POST['_method']); } foreach ($_GET as $key => $value) { static::$inputs[$key] = $value; } foreach ($_POST as $key => $value) { static::$inputs[$key] = $value; } foreach ($_FILES as $input_name => $file_properties) { if (is_array($file_properties['name'])) { // Closure $filter = function ($path) use($input_name) { // get the type as: name, tmp_name, size, error, type (mime-type) $type = substr($path, 0, strpos($path, '.')); // get the value of path in $_FILES array from $path :P $pathWitoutType = substr($path, strpos($path, '.') + 1); if ($type === 'tmp_name') { $file = new File(get_array_value($_FILES, $input_name . '.tmp_name.' . $pathWitoutType), static::$file_error_codes[get_array_value($_FILES, $input_name . '.error.' . $pathWitoutType)], get_array_value($_FILES, $input_name . '.name.' . $pathWitoutType)); $file->setArrayPath($input_name . '.' . $pathWitoutType); return $file; } return null; }; static::$files = array_merge(static::$files, array_paths($_FILES[$input_name], [], null, $filter)); } else { $file = new File($file_properties['tmp_name'], static::$file_error_codes[$file_properties['error']], $file_properties['name']); $file->setArrayPath($input_name); static::$files = array_merge(static::$files, [$file]); } } unset($_FILES); unset($_GET); unset($_POST); unset($_SERVER); }
function array_paths(array $array, array $path = array(), $to_key = null, Closure $filter = null) { $result = array(); foreach ($array as $key => $val) { if ($key !== $to_key) { $currentPath = array_merge($path, array($key)); } else { $currentPath = $path; } if (is_array($val) && $currentPath !== $path) { $result = array_merge($result, array_paths($val, $currentPath, $to_key, $filter)); } else { $new_full_path = join('.', $currentPath); if ($filter !== null) { if ($filter($new_full_path) !== null) { $result[] = $filter($new_full_path); } } else { $result[] = $new_full_path; } } } return $result; }