function test_normalizing_files_array_when_multiple_files() { $files = array('userfile' => array('name' => array('test.pdf', 'test.doc'), 'tmp_name' => array('tmp85937457', 'tmp45937457'), 'size' => array('1024', '2048'), 'type' => array('application/pdf', 'application/ms-word'), 'error' => array(0, 0))); $expected = array('userfile' => array(array('name' => 'test.pdf', 'tmp_name' => 'tmp85937457', 'size' => '1024', 'type' => 'application/pdf', 'error' => 0), array('name' => 'test.doc', 'tmp_name' => 'tmp45937457', 'size' => '2048', 'type' => 'application/ms-word', 'error' => 0))); $g = new k_adapter_SafeGlobalsAccess(new k_charset_Latin1CharsetStrategy(), true); $normalized = $g->normalizeFiles($files); $this->assertEqual($expected, $normalized); }
/** * @param string * @param string * @param k_IdentityLoader * @param k_LanguageLoader * @param k_TranslatorLoader * @param k_adapter_GlobalsAccess * @param k_adapter_CookieAccess * @param k_adapter_SessionAccess */ function __construct($href_base = null, $request_uri = null, k_IdentityLoader $identity_loader = null, k_LanguageLoader $language_loader = null, k_TranslatorLoader $translator_loader = null, k_adapter_GlobalsAccess $superglobals = null, k_adapter_CookieAccess $cookie_access = null, k_adapter_SessionAccess $session_access = null, k_adapter_UploadedFileAccess $file_access = null) { if (preg_match('~/$~', $href_base)) { throw new Exception("href_base may _not_ have trailing slash"); } if (preg_match('~^\\w+://\\w+\\.~', $href_base)) { throw new Exception("href_base may _not_ include hostname"); } if (!$superglobals) { $superglobals = new k_adapter_SafeGlobalsAccess(new k_charset_Utf8CharsetStrategy()); } if (!$file_access) { $file_access = new k_adapter_DefaultUploadedFileAccess(); } $this->query = $superglobals->query(); $this->body = $superglobals->body(); $this->rawHttpRequestBody = $superglobals->rawHttpRequestBody(); $this->server = $superglobals->server(); $this->files = array(); foreach ($superglobals->files() as $key => $file_info) { if (array_key_exists('name', $file_info)) { $this->files[$key] = new k_adapter_UploadedFile($file_info, $key, $file_access); } else { $this->files[$key] = array(); foreach ($file_info as $file_info_struct) { $this->files[$key][] = new k_adapter_UploadedFile($file_info_struct, $key, $file_access); } } } $this->headers = $this->lowerKeys($superglobals->headers()); $this->cookie_access = $cookie_access ? $cookie_access : new k_adapter_DefaultCookieAccess($this->server['SERVER_NAME'], $superglobals->cookie()); $this->session_access = $session_access ? $session_access : new k_adapter_DefaultSessionAccess($this->cookie_access); $this->identity_loader = $identity_loader ? $identity_loader : new k_DefaultIdentityLoader(); $this->language_loader = $language_loader; $this->translator_loader = $translator_loader; $this->href_base = $href_base === null ? preg_replace('~(.*)/.*~', '$1', $this->server['SCRIPT_NAME']) : $href_base; $this->request_uri = $request_uri === null ? $this->server['REQUEST_URI'] : $request_uri; $this->subspace = preg_replace('~^' . preg_quote($this->href_base, '~') . '~', '', preg_replace('~([?]{1}.*)$~', '', $this->request_uri)); $this->content_type_negotiator = new k_ContentTypeNegotiator($this->header('accept')); }