当前位置: 首页>>代码示例>>PHP>>正文


PHP Headers::set方法代码示例

本文整理汇总了PHP中Slim\Http\Headers::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Headers::set方法的具体用法?PHP Headers::set怎么用?PHP Headers::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Http\Headers的用法示例。


在下文中一共展示了Headers::set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: write

 /**
  * This function outputs the given $data as valid HAL+JSON to the client
  * and sets the HTTP Response Code to the given $statusCode.
  *
  * @param array|SlimBootstrap\DataObject $data       The data to output to
  *                                                   the client
  * @param int                            $statusCode The status code to set
  *                                                   in the reponse
  */
 public function write($data, $statusCode = 200)
 {
     $path = $this->_request->getPath();
     $hal = new hal\Hal($path);
     if (true === is_array($data)) {
         $pathData = explode('/', $path);
         unset($pathData[0]);
         $endpointName = end($pathData);
         $endpointUri = '/' . implode('/', $pathData) . '/';
         foreach ($data as $entry) {
             /** @var SlimBootstrap\DataObject $entry */
             $identifiers = $entry->getIdentifiers();
             $resourceName = $endpointUri . implode('/', array_values($identifiers));
             $resource = new hal\Hal($resourceName, $entry->getData() + $entry->getIdentifiers());
             $this->_addAdditionalLinks($resource, $entry->getLinks());
             $hal->addLink($endpointName, $resourceName);
             $hal->addResource($endpointName, $resource);
         }
     } else {
         $hal->setData($data->getData() + $data->getIdentifiers());
         $this->_addAdditionalLinks($hal, $data->getLinks());
     }
     $body = $this->_jsonEncode($hal);
     if (false === $body) {
         $this->_response->setStatus(500);
         $this->_response->setBody("Error encoding requested data.");
         return;
     }
     $this->_headers->set('Content-Type', 'application/hal+json; charset=UTF-8');
     $this->_response->setStatus($statusCode);
     $this->_response->setBody($hal->asJson());
 }
开发者ID:bigpoint,项目名称:slim-bootstrap,代码行数:41,代码来源:JsonHal.php

示例2: redirect

 /**
  * Redirect
  *
  * This method prepares this response to return an HTTP Redirect response
  * to the HTTP client.
  *
  * @param string $url    The redirect destination
  * @param int    $status The redirect HTTP status code
  */
 public function redirect($url, $status = 302)
 {
     if (isset(\Slim\Slim::getInstance()->globalConfig['url'])) {
         $url = \Slim\Slim::getInstance()->globalConfig['url'] . $url;
     }
     $this->setStatus($status);
     $this->headers->set('Location', $url);
 }
开发者ID:aslijiasheng,项目名称:jacksonslim,代码行数:17,代码来源:Response.php

示例3: testSetArrayValue

 public function testSetArrayValue()
 {
     $h = new Headers();
     $h->set('Allow', ['GET', 'POST']);
     $prop = new ReflectionProperty($h, 'data');
     $prop->setAccessible(true);
     $this->assertTrue(is_array($prop->getValue($h)['allow']));
     $this->assertEquals(['GET', 'POST'], $prop->getValue($h)['allow']['value']);
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:9,代码来源:HeadersTest.php

示例4: writeToStream

 /**
  * @param DataObject $entry
  * @param int $statusCode   - default 200, is only set at first method call
  */
 public function writeToStream(SlimBootstrap\DataObject $entry, $statusCode = 200)
 {
     if (true === $this->_firstCall) {
         $this->_headers->set('Content-Type', 'text/csv; charset=UTF-8');
         $this->_response->setStatus($statusCode);
         echo $this->_determineHeadline(array($entry));
         $this->_firstCall = false;
     }
     echo $this->_buildCsvLineFromDataSet($entry->getData(), $this->_multidimensionalFields, $this->_lastFieldName, $this->_encloseAll) . $this->_linebreak;
     $this->_flush();
 }
开发者ID:bigpoint,项目名称:slim-bootstrap,代码行数:15,代码来源:Csv.php

示例5: setUp

 /**
  * Run before each test.
  */
 public function setUp()
 {
     $uri = Uri::createFromString('https://example.com:443/foo/bar');
     $headers = new Headers();
     $headers->set('REMOTE_ADDR', '127.0.0.1');
     $cookies = [];
     $env = Environment::mock();
     $serverParams = $env->all();
     $body = new Body(fopen('php://temp', 'r+'));
     $this->request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new Response();
 }
开发者ID:davidepastore,项目名称:slim-restrict-route,代码行数:15,代码来源:RestrictRouteTest.php

示例6: setUpXmlPost

 /**
  * Setup for the XML POST requests.
  *
  * @param string $xml The XML to use to mock the body of the request.
  */
 public function setUpXmlPost($xml)
 {
     $uri = Uri::createFromString('https://example.com:443/foo');
     $headers = new Headers();
     $headers->set('Content-Type', 'application/xml;charset=utf8');
     $cookies = [];
     $env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'POST']);
     $serverParams = $env->all();
     $body = new RequestBody();
     $body->write($xml);
     $this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new Response();
 }
开发者ID:DavidePastore,项目名称:Slim-Validation,代码行数:18,代码来源:ValidationTest.php

示例7: write

 /**
  * This function outputs the given $data as valid JSON to the client
  * and sets the HTTP Response Code to the given $statusCode.
  *
  * @param array|SlimBootstrap\DataObject $data       The data to output to
  *                                                   the client
  * @param int                            $statusCode The status code to set
  *                                                   in the response
  */
 public function write($data, $statusCode = 200)
 {
     $result = array();
     if (true === is_array($data)) {
         foreach ($data as $entry) {
             /** @var SlimBootstrap\DataObject $entry */
             $identifiers = array_values($entry->getIdentifiers());
             $this->_buildStructure($entry, $identifiers, 0, $result);
         }
     } else {
         $identifiers = array_values($data->getIdentifiers());
         $this->_buildStructure($data, $identifiers, 0, $result);
     }
     $body = $this->_jsonEncode($result);
     if (false === $body) {
         $this->_response->setStatus(500);
         $this->_response->setBody("Error encoding requested data.");
         return;
     }
     $this->_headers->set('Content-Type', 'application/json; charset=UTF-8');
     $this->_response->setStatus($statusCode);
     $this->_response->setBody($body);
 }
开发者ID:bigpoint,项目名称:slim-bootstrap,代码行数:32,代码来源:Json.php

示例8: redirect

 /**
  * Redirect
  *
  * This method prepares this response to return an HTTP Redirect response
  * to the HTTP client.
  *
  * @param string $url    The redirect destination
  * @param int    $status The redirect HTTP status code
  */
 public function redirect($url, $status = 302)
 {
     $this->setStatus($status);
     $this->headers->set('Location', $url);
 }
开发者ID:florentsuc,项目名称:jobskee-open-source-job-board,代码行数:14,代码来源:Response.php

示例9: testGetParsedBodyXmlWithTextXMLMediaType

 public function testGetParsedBodyXmlWithTextXMLMediaType()
 {
     $method = 'GET';
     $uri = new Uri('https', 'example.com', 443, '/foo/bar', 'abc=123', '', '');
     $headers = new Headers();
     $headers->set('Content-Type', 'text/xml');
     $cookies = [];
     $serverParams = [];
     $body = new RequestBody();
     $body->write('<person><name>Josh</name></person>');
     $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     $this->assertEquals('Josh', $request->getParsedBody()->name);
 }
开发者ID:kschaefers,项目名称:RaumsucheRestBackend,代码行数:13,代码来源:RequestTest.php


注:本文中的Slim\Http\Headers::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。