Пример #1
0
 protected function execute($method = 'GET', $url, $parameters = array(), $files = array())
 {
     foreach ($this->headers as $header => $val) {
         $this->client->setServerParameter("HTTP_{$header}", $val);
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     if (is_array($parameters) || $parameters instanceof \ArrayAccess) {
         $parameters = $this->scalarizeArray($parameters);
         if (array_key_exists('Content-Type', $this->headers) && $this->headers['Content-Type'] === 'application/json' && $method != 'GET') {
             $parameters = json_encode($parameters);
         }
     }
     if (is_array($parameters) || $method == 'GET') {
         if ($method == 'GET' && !empty($parameters)) {
             $url .= '?' . http_build_query($parameters);
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url}?" . http_build_query($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, array(), $files, array(), $parameters);
     }
     $this->response = $this->client->getResponse()->getContent();
     $this->debugSection("Response", $this->response);
 }
Пример #2
0
 protected function execute($method = 'GET', $url, $parameters = array(), $files = array())
 {
     foreach ($this->headers as $header => $val) {
         $header = str_replace('-', '_', strtoupper($header));
         $this->client->setServerParameter("HTTP_{$header}", $val);
         # Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_
         if ($this->is_functional and $header == 'CONTENT_TYPE') {
             $this->client->setServerParameter($header, $val);
         }
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     $parameters = $this->encodeApplicationJson($method, $parameters);
     if (is_array($parameters) || $method == 'GET') {
         if (!empty($parameters) && $method == 'GET') {
             $url .= '?' . http_build_query($parameters);
         }
         if ($method == 'GET') {
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, array(), $files, array(), $parameters);
     }
     $this->response = $this->client->getInternalResponse()->getContent();
     $this->debugSection("Response", $this->response);
     if (count($this->client->getInternalRequest()->getCookies())) {
         $this->debugSection('Cookies', json_encode($this->client->getInternalRequest()->getCookies()));
     }
     $this->debugSection("Headers", json_encode($this->client->getInternalResponse()->getHeaders()));
     $this->debugSection("Status", json_encode($this->client->getInternalResponse()->getStatus()));
 }