コード例 #1
0
ファイル: StatusSpec.php プロジェクト: gianarb/gstatus
 function it_should_be_use_constant(Headers $headers)
 {
     $headers->clearHeaders()->shouldBeCalledTimes(1);
     $headers->addHeaderLine("Content-Type", "application/json")->shouldBeCalledTimes(1);
     $headers->addHeaderLine("Authorization", "token token")->shouldBeCalledTimes(1);
     $this->setHeaders($headers);
     $this->setStatusFor("aaa", ["state" => \Gstatus\Request\Status::FAILURE]);
     $this->prepareRequest("token");
     $this->getContent()->shouldBe('{"state":"failure"}');
 }
コード例 #2
0
ファイル: RenderListener.php プロジェクト: xemlock/Zf1Module
 /**
  * @param \Zend_Controller_Response_Abstract $response
  * @return \Zend\Http\Headers
  */
 protected function getHeadersFromResponse(\Zend_Controller_Response_Abstract $response)
 {
     $headers = new HttpHeaders();
     foreach ($response->getRawHeaders() as $header) {
         $headers->addHeaderLine($header);
     }
     foreach ($response->getHeaders() as $header) {
         $headers->addHeaderLine($header['name'], $header['value']);
     }
     return $headers;
 }
コード例 #3
0
 public function testClearHeaderAndHeaderNotExists()
 {
     $response = $this->response = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\Response', ['getHeaders', 'send']);
     $this->headers->addHeaderLine('Header-name: header-value');
     $header = \Zend\Http\Header\GenericHeader::fromString('Header-name: header-value');
     $this->headers->expects($this->once())->method('has')->with('Header-name')->will($this->returnValue(false));
     $this->headers->expects($this->never())->method('get')->with('Header-name')->will($this->returnValue($header));
     $this->headers->expects($this->never())->method('removeHeader')->with($header);
     $response->expects($this->once())->method('getHeaders')->will($this->returnValue($this->headers));
     $response->clearHeader('Header-name');
 }
コード例 #4
0
 /**
  * Prepare cache-busting headers for GET requests
  *
  * Invoked from the onFinish() method for GET requests to disable client-side HTTP caching.
  *
  * @param Headers $headers
  */
 protected function disableHttpCache(Headers $headers)
 {
     $headers->addHeader(new GenericHeader('Expires', '0'));
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'no-store, no-cache, must-revalidate'));
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'post-check=0, pre-check=0'));
     $headers->addHeaderLine('Pragma', 'no-cache');
 }
コード例 #5
0
ファイル: IndexController.php プロジェクト: coolms/file
 /**
  * {@inheritDoc}
  *
  * @return Stream|Response
  */
 public function indexAction()
 {
     $response = $this->getResponse();
     $params = $this->params()->fromRoute();
     if ($params['path'] === '') {
         $response->setStatusCode(404);
         return $response;
     }
     $info = pathinfo($params['path']);
     if ($info['dirname'] === '.') {
         $info['dirname'] = '';
     }
     /* @var $folder \CmsFile\Mapping\FolderInterface */
     $folder = $this->getFolderService()->getMapper()->findOneByPath('/' . trim($info['dirname'], '/'));
     if (!$folder) {
         $response->setStatusCode(404);
         return $response;
     }
     $file = $folder->getFile($info['basename']);
     if (!$file) {
         $response->setStatusCode(404);
         return $response;
     }
     $response = new Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', $file->getType())->addHeaderLine('Content-Disposition', 'attachment; filename="' . $file->getTitle() . '"')->addHeaderLine('Content-Length', filesize($file));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #6
0
 public function get($id)
 {
     $headers = new Headers();
     $headers->addHeaderLine('Access-Control-Allow-Origin', '*');
     $json = new JsonModel(array('data' => $this->listadoCursos($id)));
     return $json;
 }
コード例 #7
0
 /**
  *
  */
 private function injectEsiHeader()
 {
     if (!$this->esiHeaderInjected) {
         $this->responseHeaders->addHeaderLine('Surrogate-Control', 'ESI/1.0');
         $this->esiHeaderInjected = true;
     }
 }
コード例 #8
0
 public static function nearby($countryCode, $postalCode)
 {
     $http = new Client();
     $http->setOptions(array('sslverifypeer' => false));
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/json');
     $http->setHeaders($headers);
     $http->setUri(self::$apiUrl . 'nearby/' . urlencode($countryCode) . '/' . urlencode($postalCode));
     $http->setMethod('GET');
     $response = $http->send();
     $json = Json::decode($response->getBody());
     return $json;
 }
コード例 #9
0
 public function testGet()
 {
     $expectedDate = '2015-01-01';
     $headers = new Headers();
     $headers->addHeaderLine(sprintf('Cookie: %s=%s', TimetableCookieListener::COOKIE_NAME, $expectedDate));
     $request = new Request();
     $request->setHeaders($headers);
     $response = new Response();
     $listener = new TimetableCookieListener($request, $response);
     $event = new TimetableManagerEvent();
     $listener->getTime($event);
     $this->assertTrue($event->hasPointInTime());
     $this->assertEquals($expectedDate, $event->getPointInTime()->format('Y-m-d'));
 }
コード例 #10
0
 public static function getCountries()
 {
     $http = new Client();
     $http->setOptions(array('sslverifypeer' => false));
     $headers = new Headers();
     $headers->addHeaderLine('X-Mashape-Key', MASHAPE_API_KEY);
     $http->setHeaders($headers);
     $http->setUri("https://restcountries-v1.p.mashape.com/all");
     $http->setMethod('GET');
     $response = $http->send();
     $json = Json::decode($response->getBody());
     $data = array();
     foreach ($json as $country) {
         $data[] = array("code" => strtolower($country->alpha2Code), "name" => $country->name);
     }
     return $data;
 }
コード例 #11
0
ファイル: ProxyTest.php プロジェクト: nieldm/zf2
 /**
  * Acts like a client sending the given Authenticate header value.
  *
  * @param  string $clientHeader Authenticate header value
  * @param  string $scheme       Which authentication scheme to use
  * @return array Containing the result, the response headers, and the status
  */
 public function _doAuth($clientHeader, $scheme)
 {
     // Set up stub request and response objects
     $response = new Response();
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Proxy-Authorization', $clientHeader);
     $headers->addHeaderLine('User-Agent', 'PHPUnit');
     $request = new Request();
     $request->setUri('http://localhost/');
     $request->setMethod('GET');
     $request->setHeaders($headers);
     // Select an Authentication scheme
     switch ($scheme) {
         case 'basic':
             $use = $this->_basicConfig;
             break;
         case 'digest':
             $use = $this->_digestConfig;
             break;
         case 'both':
         default:
             $use = $this->_bothConfig;
     }
     // Create the HTTP Auth adapter
     $a = new \Zend\Authentication\Adapter\Http($use);
     $a->setBasicResolver($this->_basicResolver);
     $a->setDigestResolver($this->_digestResolver);
     // Send the authentication request
     $a->setRequest($request);
     $a->setResponse($response);
     $result = $a->authenticate();
     $return = array('result' => $result, 'status' => $response->getStatusCode(), 'headers' => $response->getHeaders());
     return $return;
 }
コード例 #12
0
ファイル: ObjectTest.php プロジェクト: haoyanfei/zf2
 public function testUnsupportedScheme()
 {
     $response = new Response();
     $headers = new Headers();
     $request = new Request();
     $headers->addHeaderLine('Authorization', 'NotSupportedScheme <followed by a space character');
     $request->setHeaders($headers);
     $a = new Adapter\Http($this->_digestConfig);
     $a->setDigestResolver($this->_digestResolver)->setRequest($request)->setResponse($response);
     $result = $a->authenticate();
     $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_UNCATEGORIZED);
 }
コード例 #13
0
ファイル: ResponseTest.php プロジェクト: mt-olympus/hermes
 /**
  * @covers Hermes\Api\Response::__construct
  * @covers Hermes\Api\Response::getContent
  */
 public function testGetContent()
 {
     $http = new Client();
     $response = new ZendResponse();
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/json');
     $response->setHeaders($headers);
     $response->setContent(static::$sampleJson);
     $this->object = new Response($http, $response);
     $content = $this->object->getContent();
 }
コード例 #14
0
 public function testUpdateCanBeAccessed()
 {
     $data = array('firstName' => 'Jim', 'lastName' => 'Smith', 'middleInitial' => null, 'address1' => '123 Main St', 'address2' => 'Ste 400', 'city' => 'Pleasantville', 'state' => 'OK', 'zip' => '12345', 'zip4' => '6789', 'email' => '*****@*****.**', 'phoneNumber' => '8885551212', 'id' => 1);
     $contact = new Contact();
     $contact->exchangeArray($data);
     $entityManager = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->once())->method('merge')->with($this->anything())->will($this->returnValue($contact));
     $entityManager->expects($this->once())->method('flush');
     $entityManager->expects($this->once())->method('find')->with('AddressBook\\Model\\Contact', 1)->will($this->returnValue($contact));
     $this->controller->setObjectManager($entityManager);
     $this->routeMatch->setParam('id', '1');
     $this->request->setMethod('put');
     $this->request->setContent(json_encode($data));
     $headers = new Headers();
     $headers->addHeaderLine('Content-type', 'application/json');
     $this->request->setHeaders($headers);
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('{"data":1}', $result->serialize());
 }
コード例 #15
0
ファイル: Api.php プロジェクト: carnage/mailchimp
 /**
  * Call an api method
  *
  * @param $method
  * @param $params
  * @return mixed
  * @throws \Exception
  */
 public function call($method, $params)
 {
     $params['apikey'] = $this->getApiKey();
     $params = json_encode($params);
     $client = $this->getClient();
     $uri = $this->getBaseUri() . $method . '.json';
     $headers = new Headers();
     $headers->addHeaderLine('Accept-Encoding', 'identity');
     $headers->addHeaderLine('Content-Type', 'application/json');
     $headers->addHeaderLine('Accept', '*/*');
     $request = new Request();
     $request->setHeaders($headers);
     $request->setUri($uri);
     $request->setMethod('POST');
     $request->setContent($params);
     $response = $client->dispatch($request);
     if ($response->isSuccess()) {
         return json_decode($response->getContent(), true);
     } else {
         /*@TODO throw a more useful exception*/
         throw new \Exception('Request Failed');
     }
 }
コード例 #16
0
 /**
  * Send header to download the given file
  *
  * @param int $fileID            
  * @return \Zend\Http\Response\Stream
  */
 protected function downloadFile($fileID)
 {
     $file = $this->getFileTable()->getFile($fileID);
     $this->getFileTable()->incrementDownloadCount($file);
     $fileUrl = $this->getOptions()->getDownloadFolderPath() . "/" . $file->url;
     if (!file_exists($fileUrl)) {
         throw new \Exception("File doesn't exists");
     }
     $response = new Stream();
     $response->setStream(fopen($fileUrl, 'r'));
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Disposition', 'attachment; filename="' . $file->name . '"')->addHeaderLine('Cache-Control', 'must-revalidate')->addHeaderLine('Pragma', 'public')->addHeaderLine('Content-Length', filesize($fileUrl));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #17
0
 public function mysessionAction()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Access-Control-Allow-Origin', '*');
     $values = \Zend\Json\Json::decode($this->getRequest()->getContent());
     $content = array();
     foreach ($values as $key) {
         $content[] = $key;
     }
     $secciones = $content[0];
     $todas = explode(',', $secciones);
     $unico = array_unique($todas);
     $contentjson = array();
     foreach ($unico as $valores) {
         $posters_id = $this->getSessioniDao()->tuttiPerId($valores)->getPosterlab();
         $data_inizio = $this->getSessioniDao()->tuttiPerId($valores)->getInizio();
         $datas_i = $data_inizio;
         $date_i = new DateTime($datas_i);
         $fechas_i = $date_i->format('d-m-Y H:i');
         $data_fine = $this->getSessioniDao()->tuttiPerId($valores)->getFine();
         $datas_f = $data_fine;
         $date_f = new DateTime($datas_f);
         $fechas_f = $date_f->format('d-m-Y H:i');
         $nomeposter = $this->getPosterlabsDao()->tuttiPerId($posters_id)->getTitolo();
         $interventi = $this->getInterattivoDao()->tuttiReport($posters_id, $valores)->toArray();
         $dati = array();
         foreach ($interventi as $key) {
             $datas = $key['data'];
             $date = new DateTime($datas);
             $fechas = $date->format('d-m-Y H:i');
             //print_r($fecha);
             $dati[] = array('id' => $key['id'], 'nick' => $key['nome'], 'messaggio' => $key['messaggio'], 'tipo' => $key['tipo'], 'data' => $fechas, 'nomeposterlab' => $nomeposter);
         }
         //print_r($dati);die;
         $contentjson[] = array('titolo' => $nomeposter, 'livello' => 'base', 'data' => $fechas_i, 'data_estesa' => $data_fine, 'ora' => $fechas_f, 'id' => $valores, 'interattivo' => $dati);
     }
     $jsons = new JsonModel($contentjson);
     return $jsons;
 }
コード例 #18
0
ファイル: IndexController.php プロジェクト: gotcms/gotcms
 /**
  * Download files as gzip
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadContentAction()
 {
     $what = $this->params()->fromPost('what');
     if (empty($what) or !is_array($what)) {
         return $this->redirect()->toRoute('module/backup');
     }
     $model = new Model\Content($this->getServiceLocator());
     $content = $model->export($what);
     $filename = 'content-backup-' . date('Y-m-d-H-i-s') . '.xml';
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/download')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }
コード例 #19
0
ファイル: ViewController.php プロジェクト: gotcms/gotcms
 /**
  * Send a file to the browser
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadAction()
 {
     $viewId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($viewId)) {
         $view = View\Model::fromId($viewId);
         if (empty($view)) {
             $this->flashMessenger()->addErrorMessage('This view can not be download');
             return $this->redirect()->toRoute('development/view/edit', array('id' => $viewId));
         }
         $content = $view->getContent();
         $filename = $view->getIdentifier() . '.phtml';
     } else {
         $views = new View\Collection();
         $children = $views->getViews();
         $zip = new ZipArchive();
         $tmpFilename = tempnam(sys_get_temp_dir(), 'zip');
         $res = $zip->open($tmpFilename, ZipArchive::CREATE);
         if ($res === true) {
             foreach ($children as $child) {
                 $zip->addFromString($child->getIdentifier() . '.phtml', $child->getContent());
             }
             $zip->close();
             $content = file_get_contents($tmpFilename);
             $filename = 'views.zip';
             unlink($tmpFilename);
         }
     }
     if (empty($content) or empty($filename)) {
         $this->flashMessenger()->addErrorMessage('Can not save views');
         return $this->redirect()->toRoute('development/view');
     }
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }
コード例 #20
0
ファイル: HeadersTest.php プロジェクト: JojoBombardo/zf2
 public function testHeadersAddHeaderLineThrowsExceptionOnMissingFieldValue()
 {
     $this->setExpectedException('Zend\\Http\\Exception\\InvalidArgumentException', 'without a field');
     $headers = new Headers();
     $headers->addHeaderLine('Foo');
 }
コード例 #21
0
 /**
  * AJAX.
  * Retorna automaticamente as headers necessarias para json, com conteudo.
  * SEMPRE QUE USAR UM AJAX, UTILIZE ESTE METODO PARA RETORNO.
  * 
  * @param mixed $result
  * @return Response
  */
 protected function getJsonView($result)
 {
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/json');
     return $this->getResponse()->setHeaders($headers)->setContent(Json::encode($result));
 }
コード例 #22
0
 /**
  * Prepare cache-busting headers for GET requests
  *
  * Invoked from the onFinish() method for GET requests to disable client-side HTTP caching.
  *
  * @param \Zend\Http\Headers $headers
  */
 protected function disableHttpCache($headers)
 {
     $headers->addHeader(new GenericHeader('Expires', '0'));
     // $headers->addHeaderLine('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'no-store, no-cache, must-revalidate'));
     $headers->addHeader(new GenericMultiHeader('Cache-Control', 'post-check=0, pre-check=0'));
     $headers->addHeaderLine('Pragma', 'no-cache');
 }
コード例 #23
0
 /**
  * Prepare the request before it been send to Zend Server
  */
 public function prepareRequest()
 {
     $date = gmdate('D, d M Y H:i:s ') . 'GMT';
     $webApiUri = self::API_URI . $this->action;
     $signatureData = $this->uri->getHost() . ':';
     $signatureData .= $this->uri->getPort() . ':';
     $signatureData .= $webApiUri . ':';
     $signatureData .= self::USER_AGENT . ':';
     $signatureData .= $date;
     $signature = hash_hmac('sha256', $signatureData, $this->apiKey->getKey());
     $headers = new Headers();
     $headers->addHeaderLine('Host', $this->uri->getHost() . ':' . $this->uri->getPort());
     $headers->addHeaderLine('Date', $date);
     $headers->addHeaderLine('Accept', 'application/vnd.zend.serverapi+' . $this->outputType . ';version=' . $this->apiVersion);
     $headers->addHeaderLine('X-Zend-Signature', $this->apiKey->getName() . '; ' . $signature);
     $headers->addHeaderLine('Accept-Encoding: identity');
     if ($this->isPost()) {
         if (count($this->getFiles())) {
             $headers->addHeaderLine('Content-Type', 'multipart/form-data');
         } else {
             $headers->addHeaderLine('Content-Type', 'application/x-www-form-urlencoded');
         }
         $this->setPostParameter();
     } else {
         $this->setGetParameter();
     }
     $this->setHeaders($headers);
 }
コード例 #24
0
ファイル: Image.php プロジェクト: gridguyz/zork
 /**
  * Render image
  *
  * @param string|\Zend\Stdlib\ResponseInterface $to path / response
  * @param int $type
  * @param int $quality [optional] used if type is png / jpeg
  * @param int $filters [optional] used if type is png
  * @return \Zork\Image\Image
  */
 public function render($to, $type = null, $quality = null, $filters = null)
 {
     if (null === $type) {
         $type = $this->getType();
     }
     if ($to instanceof ResponseInterface) {
         $resp = $to;
         $to = null;
         if ($resp instanceof HttpResponse) {
             $headers = new HttpHeaders();
             $headers->addHeaderLine('Content-Type', static::typeToMimeType($type));
             $resp->setHeaders($headers);
         }
         ob_start();
     } else {
         $resp = false;
     }
     switch ($type) {
         case self::TYPE_GIF:
             imagegif($this->resource, $to);
             break;
         case self::TYPE_JPEG:
             imagejpeg($this->resource, $to, is_null($quality) ? self::DEFAULT_JPEG_QUALITY : min($quality, self::MAX_JPEG_QUALITY));
             break;
         case self::TYPE_PNG:
             imagepng($this->resource, $to, is_null($quality) ? self::DEFAULT_PNG_QUALITY : min($quality, self::MAX_PNG_QUALITY), is_null($filters) ? self::DEFAULT_PNG_FILTERS : $filters);
             break;
         default:
             throw new Exception\OperationException('Type not supported');
     }
     if ($resp instanceof ResponseInterface) {
         $resp->setContent(ob_get_clean());
     }
     return $this;
 }
コード例 #25
0
 /**
  * Send a file to the browser
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadAction()
 {
     $translator = new Translator();
     $values = $translator->getValues();
     $zip = new ZipArchive();
     $tmpFilename = tempnam(sys_get_temp_dir(), 'zip');
     $res = $zip->open($tmpFilename, ZipArchive::CREATE);
     if ($res === true) {
         $locales = array();
         foreach ($values as $value) {
             if (!isset($locales[$value['locale']])) {
                 $locales[$value['locale']] = array();
             }
             $locales[$value['locale']][] = sprintf('"%s","%s"', str_replace('"', '"""', $value['source']), str_replace('"', '"""', $value['destination']));
         }
         foreach ($locales as $locale => $content) {
             $zip->addFromString($locale . '.csv', implode(PHP_EOL, $content));
         }
         $zip->close();
         $content = file_get_contents($tmpFilename);
         $filename = 'translations.zip';
         unlink($tmpFilename);
     }
     if (empty($content) or empty($filename)) {
         $this->flashMessenger()->addErrorMessage('Can not save translations');
         return $this->redirect()->toRoute('content/translation');
     }
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }